Repository navigation
feat(sync-main-to-edge): open a PR when direct push can't fast-forward #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ on: | |
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| plan: | ||
|
|
@@ -127,9 +128,14 @@ jobs: | |
| persist-credentials: false | ||
| fetch-depth: 0 | ||
|
|
||
| # The aormsby action fast-forwards upstream -> target. It fails when the | ||
| # branches have diverged or when branch protection rejects the push. | ||
| # continue-on-error lets us fall back to opening a PR in that case instead | ||
| # of failing the whole job. | ||
| - name: Sync upstream changes | ||
| if: steps.check.outputs.exists == 'true' | ||
| id: sync | ||
| continue-on-error: true | ||
| uses: aormsby/Fork-Sync-With-Upstream-action@83d78e8c4bf524e79b091cf257deba4dee9e60df # v3.4.3 | ||
| with: | ||
| target_sync_branch: ${{ matrix.target }} | ||
|
|
@@ -138,10 +144,35 @@ jobs: | |
| upstream_sync_repo: ${{ github.repository }} | ||
| test_mode: ${{ inputs.test_mode }} | ||
|
|
||
| # When the direct push could not happen (diverged history or branch | ||
| # protection), open a PR upstream -> target instead. Idempotent: skips if | ||
| # a PR is already open for the same head/base, and tolerates "no diff". | ||
| - name: Open PR if direct sync could not push | ||
| if: steps.check.outputs.exists == 'true' && steps.sync.outcome == 'failure' | ||
| env: | ||
| UPSTREAM: ${{ matrix.upstream }} | ||
| TARGET: ${{ matrix.target }} | ||
| REPO: ${{ github.repository }} | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| set -euo pipefail | ||
| existing=$(gh pr list --repo "$REPO" --base "$TARGET" --head "$UPSTREAM" \ | ||
| --state open --json number -q '.[0].number' || true) | ||
| if [ -n "$existing" ]; then | ||
| echo "PR #$existing already open for $UPSTREAM -> $TARGET; nothing to do." | ||
| exit 0 | ||
| fi | ||
| gh pr create --repo "$REPO" --base "$TARGET" --head "$UPSTREAM" \ | ||
| --title "sync: $UPSTREAM -> $TARGET" \ | ||
| --body "Automated sync could not fast-forward \`$TARGET\` from \`$UPSTREAM\` (diverged history or branch protection). Merging via PR instead." \ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The body should have a link back to this workflow captured the same way other nsheaps ones do. |
||
| || echo "No PR created (possibly no diff between $UPSTREAM and $TARGET)." | ||
|
|
||
| - name: Report | ||
| if: steps.check.outputs.exists == 'true' | ||
| run: | | ||
| if [ "${{ steps.sync.outputs.has_new_commits }}" = "true" ]; then | ||
| if [ "${{ steps.sync.outcome }}" = "failure" ]; then | ||
| echo "Direct sync could not push ${{ matrix.upstream }} -> ${{ matrix.target }}; opened/ensured a PR instead." | ||
| elif [ "${{ steps.sync.outputs.has_new_commits }}" = "true" ]; then | ||
| echo "Synced new commits from ${{ matrix.upstream }} into ${{ matrix.target }}." | ||
| else | ||
| echo "${{ matrix.target }} already up-to-date with ${{ matrix.upstream }}." | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a re-usable action that's commonly used in the nsheaps org that you should reuse here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/nsheaps/.github/blob/main/.github/workflows/sync-repo-settings.yaml#L62-L122
Something like this maybe should be put in it's own re-usable action