Skip to content

ci(sync-upstream): guard merge/push on existing remote branch - #14

Merged
dogmar merged 3 commits into
mainfrom
claude/peaceful-euler-eEY69
May 28, 2026
Merged

dogmar merged 3 commits into
mainfrom
claude/peaceful-euler-eEY69

Conversation

@dogmar

@dogmar dogmar commented May 28, 2026

Copy link
Copy Markdown
Collaborator

Summary

Two fixes to the Sync Upstream workflow (.github/workflows/sync-upstream.yml). Rebased on latest main.

1. Guard merge/push on an existing remote branch

Fixes the recurring non-fast-forward push failure:

! [rejected]  sync/v0.21.1-20260521 -> sync/v0.21.1-20260521 (non-fast-forward)
error: failed to push some refs ... tip of your current branch is behind its remote counterpart

Root cause: the sync branch name is derived from the upstream commit date, so every run computes the same name while upstream sits on one release. The only idempotency guard matched open PRs only — a branch pushed by a prior run that never landed a PR (or whose PR was closed) slipped through, got re-created from origin/main, and the plain (non-force) push was rejected as diverged, wedging the workflow every 2 hours.

Change: the check step now also detects an existing remote branch (git ls-remote --exit-code --heads) and exposes branch_exists. The Setup/Merge steps gain && branch_exists == 'false' so an existing branch is never re-created or re-pushed, while Create PR still runs to (re)open a PR against it — recovering orphaned branches instead of stranding them.

2. Keep fork-removed files deleted on sync

The fork removed .github/workflows/zizmor.yml and .github/CODEOWNERS, both of which still exist upstream and at the merge-base. An upstream edit to either surfaces as a modify/delete conflict (same shape as release.yml), which previously fell through to the manual-review path and aborted the merge.

Change: the conflict resolver now keeps release.yml, zizmor.yml, and CODEOWNERS deleted automatically, preserving the fork's removals.

Test plan

  • Trigger Sync Upstream when a sync/... branch exists with no open PR → merge/push skipped, PR opened against the existing branch (no non-fast-forward error).
  • Trigger with no sync branch and no PR → full merge + push + PR path runs.
  • Trigger with an open sync PR → everything skipped, as before.
  • Trigger a sync where upstream modified zizmor.yml or CODEOWNERS → both auto-resolved to deleted, merge completes.

Notes

claude added 2 commits May 28, 2026 23:29
The sync branch name is derived from the upstream commit date, so every
run computes the same name while upstream sits on one release. The only
idempotency guard checked for an *open* PR; a branch pushed by a prior
run that never landed a PR (or whose PR was closed) slipped through. The
job then re-created the branch from origin/main and force-free-pushed a
diverged history, which git rejects as non-fast-forward — wedging the
workflow on every 2-hour cron tick.

Detect the existing remote branch and skip the merge/push when present,
while still letting the Create PR step (re)open a PR against it. This
both fixes the non-fast-forward failure and recovers orphaned branches.
The fork removed .github/workflows/zizmor.yml and .github/CODEOWNERS,
both of which still exist upstream. An upstream edit to either surfaces
as a modify/delete conflict (same as release.yml), which previously fell
through to the manual-review path and aborted the merge. Resolve them
back to 'deleted' automatically so the fork's removals are preserved.
@dogmar
dogmar force-pushed the claude/peaceful-euler-eEY69 branch from c7e17b4 to 43d9ec3 Compare May 28, 2026 23:30
A closed (not merged) sync PR means the version was deliberately
rejected. The prior open-only check let it through, but gh pr create
refuses a second PR for a head that already has one, so the recovery
path still wedged. Match PRs in any state so a closed PR skips the sync.
@dogmar
dogmar marked this pull request as ready for review May 28, 2026 23:40
@dogmar
dogmar merged commit 4cd6a7e into main May 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants