get commits from upstream #101
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: 'get commits from upstream' | |
on: | |
schedule: | |
- cron: '0 0 * * 1' # run every monday | |
workflow_dispatch: | |
jobs: | |
sync_latest_from_upstream: | |
runs-on: ubuntu-latest | |
name: Sync latest commits from upstream repo | |
steps: | |
# REQUIRED step | |
# Step 1: run a standard checkout action, provided by github | |
- name: Checkout target repo | |
uses: actions/checkout@v2 | |
with: | |
# optional: set the branch to checkout, | |
# sync action checks out your 'target_sync_branch' anyway | |
ref: master | |
- name: Sync latest commits | |
id: sync | |
run: | | |
# make file runnable, might not be necessary | |
chmod +x "${GITHUB_WORKSPACE}/.github/fetch_from_upstream.sh" | |
# run script | |
"${GITHUB_WORKSPACE}/.github/fetch_from_upstream.sh" | |
shell: bash | |
# Step 3: Display a sample message based on the sync output var 'has_new_commits' | |
- name: New commits found | |
if: steps.sync.outputs.has_new_commits == 'true' | |
run: echo "New commits were found to sync." | |
- name: New commits not found | |
if: steps.sync.outputs.has_new_commits == 'false' | |
run: echo "New commits were not found" | |
- name: Create Pull Request if new commits are present | |
if: steps.sync.outputs.has_new_commits == 'true' | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const { repo, owner } = context.repo; | |
const d = new Date() | |
const datestring = d.getFullYear() + "-" + ("0"+(d.getMonth()+1)).slice(-2) + "-" + ("0" + d.getDate()).slice(-2) | |
const result = await github.rest.pulls.create({ | |
title: [ | |
'[UPSTREAM CHANGES] latest changes as of ', | |
d | |
].join('\n'), | |
owner, | |
repo, | |
head: [ | |
'upstream-changes', | |
datestring | |
].join('-'), | |
base: 'master', | |
body: [ | |
'This PR is auto-generated by', | |
'[actions/github-script](https://github.com/actions/github-script).' | |
].join('\n') | |
}); |