Skip to content

fix(ci): switch upstream-sync to PR mode + token preflight - #11

Merged
eduralph merged 2 commits into
mainfrom
fix/upstream-sync-pr-mode
May 17, 2026
Merged

fix(ci): switch upstream-sync to PR mode + token preflight#11
eduralph merged 2 commits into
mainfrom
fix/upstream-sync-pr-mode

Conversation

@eduralph

@eduralph eduralph commented May 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Replaces the broken `gh repo sync`-based upstream sync with a PR-mode workflow that handles both the PRFirst branch-protection ruleset (no bypass, all changes via PR) and the regular divergence the forks carry due to cherry-picked CI/CD work.
  • Adds a `FORK_SYNC_TOKEN` preflight check so the failure mode for a missing token is human-readable setup instructions instead of `gh` exit-code 4.

Why

`gh repo sync` calls GitHub's merge-upstream API, which is a fast-forward push under the covers. The fork ruleset rejects it, and it can't handle the divergent state the forks normally carry. Net effect: the nightly sync has been silently failing for at least 3 days (confirmed by `gh run list --workflow=upstream-sync.yml`), the forks drifted 100+ commits behind upstream, and the QuiltView E2E test in PR #10 needed a manual sync PR (eduralph/addons-source#16) to validate.

Behaviour

For each (repo, branch) matrix cell:

  1. Verify `secrets.FORK_SYNC_TOKEN` is set; fail with setup instructions if not.
  2. Clone the fork with the PAT, add upstream as a remote, fetch.
  3. If fork is already up-to-date: log + close any stale sync PR + exit 0.
  4. Otherwise: rebuild `sync/upstream--auto` from the fork's head, merge upstream into it, force-push.
  5. Open a new sync PR (or update the existing one by virtue of the force-push).
  6. On merge conflict: abort, list conflicting files, exit 1 so the run shows red and the user knows to do a manual sync.

Requirements

  • A fine-grained PAT in `secrets.FORK_SYNC_TOKEN` with Contents: write + Pull-requests: write on `eduralph/gramps` and `eduralph/addons-source`.

Test plan

  • Set `FORK_SYNC_TOKEN` secret (manual step on Ralphovi/gramps-testbed)
  • `gh workflow run upstream-sync.yml --ref fix/upstream-sync-pr-mode` and confirm: token-missing path tested by temporarily unsetting; happy path produces a sync PR (or exits 0 when fork is up-to-date)
  • Merge once green

🤖 Generated with Claude Code

eduralph and others added 2 commits May 17, 2026 13:13
The previous implementation used `gh repo sync`, which:
  * has no chance of working against the forks because the PRFirst
    branch ruleset (no bypass) blocks all direct pushes to master and
    maintenance/gramps60 — `gh repo sync` calls the merge-upstream API,
    which is just a fast-forward push under the covers and is rejected
    by branch protection.
  * could not handle divergence anyway; the forks regularly carry
    cherry-picked CI/CD work (see e.g. eduralph/addons-source#16) and
    `gh repo sync` refuses to operate on any branch that has commits
    upstream lacks.

The new workflow does what the manual sync PRs have been doing by hand:
clones the fork, fetches upstream, attempts a merge commit on a stable
`sync/upstream-<branch>-auto` branch, force-pushes that branch, and
opens (or updates by force-push) a PR against the protected branch.
Conflicts abort cleanly with a file list so the next run after a
manual sync re-attempts from the current head.

Also added an explicit FORK_SYNC_TOKEN preflight check so the failure
mode for a missing token is a single readable line of setup
instructions instead of `gh: To use GitHub CLI in a GitHub Actions
workflow, set the GH_TOKEN environment variable` exit-code 4 from
deep inside `gh repo sync`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
`git checkout <branch>` errors with "matched multiple remote tracking
branches" when both origin and upstream carry the branch and no local
branch exists yet. That happened on every non-default branch — for
gramps the default is master so maintenance/gramps60 failed; for
addons-source the default is maintenance/gramps60 so master failed.

Force the local branch creation from origin/<branch> explicitly.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@eduralph
eduralph merged commit 2caa5b1 into main May 17, 2026
6 of 10 checks passed
@eduralph
eduralph deleted the fix/upstream-sync-pr-mode branch May 17, 2026 11:39
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.

1 participant