Sync with H7 #936
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: Sync with H7 | |
on: | |
#push: | |
# branches: [gh-workflows] | |
# "Scheduled workflows run on the latest commit on the default or base branch." | |
schedule: | |
- cron: '8 0 * * *' | |
# "To trigger the workflow_dispatch event, your workflow must be in the default branch." | |
# To run this manually from the command-line: | |
# gh workflow run sync.yml --repo OpenDRR/h7-riskprofiler | |
workflow_dispatch: | |
jobs: | |
sync-with-h7: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Trigger OpenDRR/h7-framework sync.yml workflow | |
env: | |
GH_TOKEN: ${{ secrets.GH_PAT }} | |
run: | | |
set -x | |
gh workflow run sync.yml --repo OpenDRR/h7-framework --ref gh-workflows | |
sleep 10 | |
RUN_ID=$(gh run list --repo OpenDRR/h7-framework --limit 1 --json databaseId --template '{{range .}}{{tablerow .databaseId}}{{end}}') | |
gh run watch --repo OpenDRR/h7-framework "$RUN_ID" | |
- name: "Checkout our own repo: OpenDRR/h7-riskprofiler" | |
uses: actions/checkout@v4 | |
with: | |
ref: main | |
token: ${{ secrets.GH_PAT }} | |
fetch-depth: 0 | |
- name: Fetch and merge latest commits from upstream, and push to GitHub | |
run: | | |
set -euxo pipefail | |
git config checkout.defaultRemote origin | |
git config user.name github-actions | |
git config user.email github-actions@github.com | |
git remote add upstream ${{ secrets.UPSTREAM_GIT_REPO }} | |
git fetch upstream --tags | |
LAST_SYNC_UPSTREAM_REF=$(git tag -l --format='%(contents)' last-sync-upstream-ref | head -1) | |
if [[ -z $LAST_SYNC_UPSTREAM_REF ]]; then | |
echo 'ERROR: `last-sync-upstream-ref` tag not found. Please create it manually.' | tee -a "$GITHUB_STEP_SUMMARY" | |
exit 1 | |
fi | |
UPSTREAM_BRANCH=upstream/main | |
#UPSTREAM_BRANCH=upstream/fw-v2 | |
LATEST_UPSTREAM_REV=$(git rev-parse --verify $UPSTREAM_BRANCH) | |
if [[ "$LAST_SYNC_UPSTREAM_REF" == "$LATEST_UPSTREAM_REV" ]]; then | |
echo 'INFO: No change since last sync, skipping.' | tee -a "$GITHUB_STEP_SUMMARY" | |
exit 0 | |
fi | |
git cherry-pick "$LAST_SYNC_UPSTREAM_REF"..$UPSTREAM_BRANCH |& tee -a "$GITHUB_STEP_SUMMARY" | |
git tag -a -f -m "$LATEST_UPSTREAM_REV" last-sync-upstream-ref | |
git push origin --all | |
git push origin -f last-sync-upstream-ref | |
git push origin --tags |