Sync upstream oauth2 repo #55
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
# for reference: https://stackoverflow.com/questions/23793062/can-forks-be-synced-automatically-in-github | |
# .github/workflows/example.yml | |
name: Sync upstream oauth2 repo | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "0 9 * * 1" | |
# run once a week on monday morning | |
# if it fails | |
# send slack message (iw-engineering or integration-inovators) | |
permissions: | |
contents: write | |
jobs: | |
sync: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
ref: master | |
fetch-depth: 0 # https://stackoverflow.com/questions/71819174/shallow-update-not-allowed-with-github-actions/71819349#71819349 | |
- name: Set Github Config | |
run: | | |
git config --global user.name 'upstream-sync-bot' | |
git config --global user.email '[email protected]' | |
git config --global push.followTags true | |
- name: Merge upstream | |
id: merge-upstream | |
run: | | |
git remote add upstream https://github.com/golang/oauth2.git | |
git fetch --tags upstream | |
trap 'echo "$merge_result"' EXIT | |
merge_result=$(git merge --allow-unrelated-histories --no-edit upstream/master 2>&1) | |
if [ "$merge_result" == "Already up to date." ]; then | |
echo "already_updated=true" >> "$GITHUB_OUTPUT" | |
fi | |
- name: Push changes | |
id: push-changes | |
if: ${{ success() && steps.merge-upstream.outputs.already_updated != 'true' }} | |
run: git push origin master | |
- name: On Fail, Send Message About Merge to Slack | |
id: notify-slack | |
if: failure() | |
uses: archive/[email protected] | |
env: | |
ACTIONS_STEP_DEBUG: true | |
ACTIONS_RUNNER_DEBUG: true | |
with: | |
slack-bot-user-oauth-access-token: ${{ secrets.SLACK_BOT_TOKEN }} | |
slack-channel: ${{ secrets.SLACK_BOT_INTEGRATION_INNOVATORS_CHANNEL }} #USE CHANNEL ID, NOT CHANNEL NAME, SINCE ID IS USED IN NEW SLACK API's | |
slack-text: | | |
OAuth2 fork upstream sync failed. [action](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}) | |
- name: Send Slack Message Result | |
if: failure() | |
run: echo "${{ steps.notify-slack.outputs.slack-result }}" |