-
Notifications
You must be signed in to change notification settings - Fork 20
fix: sync-main-to-experimental action correct base branch #479
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 all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bd6fa79
fix: sync-main-to-experimental action corret base branch
pravusjif 4a745ed
fix
pravusjif 5ece7fe
fix
pravusjif a364e95
mini refactor based on PR feedback
pravusjif d80fdb7
tackled review feedback
pravusjif efb4ae6
added DRAFT flag for auto-pr + fixed P2 issues reported on feedback
pravusjif 2bdc865
Merge branch 'main' into fix/sync-main-to-experimental-action
pravusjif 43252aa
merging instructions in auto-pr description
pravusjif 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 |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| name: Merge sync PR into experimental | ||
|
|
||
| # The repo allows only squash merges, and squashing the sync PR would drop main's | ||
| # commits and freeze the merge base. This lands it as a real merge commit instead; | ||
| # GitHub closes the sync PR as merged once its commits are reachable from experimental. | ||
| on: | ||
| workflow_dispatch: | ||
|
|
||
| # Shared with sync-main-to-experimental.yml: see the note there. | ||
| concurrency: | ||
| group: chore-sync-branch | ||
| cancel-in-progress: false | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| merge: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Check out the code | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Configure git identity | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
|
|
||
| - name: Merge chore/sync into experimental | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| git fetch --no-tags --force --prune origin | ||
|
|
||
| if ! git rev-parse --verify --quiet refs/remotes/origin/chore/sync >/dev/null; then | ||
| echo "::error::chore/sync does not exist on the remote; there is no sync to land." | ||
| exit 1 | ||
| fi | ||
|
|
||
| if git merge-base --is-ancestor origin/chore/sync origin/experimental; then | ||
| echo "experimental already contains chore/sync; nothing to merge." | ||
| # It is fully merged, so a leftover branch is only a failed cleanup. | ||
| git push origin --delete chore/sync || true | ||
| exit 0 | ||
|
pravusjif marked this conversation as resolved.
|
||
| fi | ||
|
|
||
| PR_NUMBER="$(gh pr list --base experimental --head chore/sync --state open --json number --jq '.[0].number // empty')" | ||
|
|
||
| # The sync PR is opened as a draft so it cannot be squashed. Take it out of | ||
| # draft before the merge lands, so GitHub applies its normal | ||
| # merged-by-reachability handling to it. | ||
| if [ -n "$PR_NUMBER" ]; then | ||
| gh pr ready "$PR_NUMBER" \ | ||
| || echo "::warning::Could not mark PR #$PR_NUMBER ready; it may close as Closed rather than Merged." | ||
| fi | ||
|
|
||
| git checkout -B experimental origin/experimental | ||
| # --no-ff so the sync always shows up as one labelled merge commit, the way the | ||
| # PR button would have recorded it. | ||
| if ! git merge --no-ff -m "chore: sync main to experimental${PR_NUMBER:+ (#$PR_NUMBER)}" origin/chore/sync; then | ||
| git merge --abort || true | ||
| echo "::error::Merging chore/sync into experimental failed. Resolve it on chore/sync, push, and re-run this workflow." | ||
| exit 1 | ||
| fi | ||
|
|
||
| git push origin experimental | ||
|
|
||
| # A PR closed by a push is not covered by delete_branch_on_merge, so remove the | ||
| # now fully-merged branch here: the sync job treats an existing chore/sync as a | ||
| # sync still in flight. Deleting a head branch also closes its PR, so wait for | ||
| # GitHub to register the merge first — otherwise the PR reads Closed, not Merged. | ||
| STATE="" | ||
| if [ -n "$PR_NUMBER" ]; then | ||
| for _ in $(seq 1 10); do | ||
| STATE="$(gh pr view "$PR_NUMBER" --json state --jq .state)" | ||
| [ "$STATE" = "MERGED" ] && break | ||
| sleep 3 | ||
| done | ||
| if [ "$STATE" != "MERGED" ]; then | ||
| echo "::warning::PR #$PR_NUMBER still reads $STATE, so chore/sync is left in place rather than closing the PR unmerged. Re-run this workflow to clean it up." | ||
| exit 0 | ||
| fi | ||
| fi | ||
|
|
||
| # Non-fatal: experimental is already pushed, so a failed cleanup is not a | ||
| # failed sync. The no-op path above finishes the job on any later run. | ||
| git push origin --delete chore/sync \ | ||
| || echo "::warning::Could not delete chore/sync; re-run this workflow to clean it up." | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.