Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

Sync workflow: open a pull request instead of pushing main, which is now protected

LNPANDY1a16b2ea8fab
diff --git a/.github/workflows/sync-upstream.yml b/.github/workflows/sync-upstream.yml
index e2070c97..2caaac7b 100644
--- a/.github/workflows/sync-upstream.yml
+++ b/.github/workflows/sync-upstream.yml
@@ -13,6 +13,7 @@ on:
permissions:
contents: write
issues: write
+ pull-requests: write
jobs:
sync:
@@ -35,15 +36,32 @@ jobs:
python3 scripts/sync_upstream.py --old "${LAST:-$NEW}" --new "$NEW" 2>&1 | tee sync.log
exit ${PIPESTATUS[0]}
- - name: Commit and push
+ - name: Commit to a sync branch and open a pull request
if: success() && steps.sync.outcome == 'success'
+ env:
+ GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+ # main is protected (a pull request is required, force pushes and deletions are
+ # blocked, and the rules apply to everyone including the owner and this bot), so the
+ # sync result goes to a branch and a PR instead of straight to main. The PR runs the
+ # full test suite, then a person merges it.
run: |
git config user.name "sync-bot"
git config user.email "[email protected]"
+ NEW=$(git rev-parse upstream/main)
+ SHORT=$(git rev-parse --short upstream/main)
git rev-parse upstream/main > .upstream-ref
git add -A
- git diff --cached --quiet || git commit -m "Sync upstream $(git rev-parse --short upstream/main)"
- git push
+ if git diff --cached --quiet; then echo "nothing to sync"; exit 0; fi
+ git checkout -b "sync/upstream-$SHORT"
+ git commit -m "Sync upstream $SHORT"
+ git push -u origin "sync/upstream-$SHORT"
+ gh pr create -R "${{ github.repository }}" --base main --head "sync/upstream-$SHORT" \
+ --title "Sync upstream $SHORT" \
+ --body "The scheduled upstream sync, verified by scripts/sync_upstream.py (patchers, Python 3.9 parse, bash -n, the archive reader test, a macOS host build). Merging brings seedds/nxnative to \`$NEW\`.
+
+ \`\`\`
+ $(tail -12 sync.log)
+ \`\`\`" || echo "PR creation failed; the branch is pushed"
- name: Open an issue when the sync fails
if: failure()