From a3740bcaa3121083fef7d7f0ecc790534dbde890 Mon Sep 17 00:00:00 2001 From: djl11 Date: Sun, 12 Jul 2026 21:11:51 +0100 Subject: [PATCH] ci: fast-forward staging to main after release merges Match the other Unify repos so merge commits on main do not leave staging permanently one tip behind. --- .github/workflows/sync-staging.yml | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/sync-staging.yml diff --git a/.github/workflows/sync-staging.yml b/.github/workflows/sync-staging.yml new file mode 100644 index 000000000..f65bfda85 --- /dev/null +++ b/.github/workflows/sync-staging.yml @@ -0,0 +1,48 @@ +# After a staging → main merge, GitHub's merge commit leaves main one commit +# ahead of staging even when the trees match. Fast-forward staging to main +# so the branches stay tip-aligned (same pattern as unify/orchestra/etc.). +name: Sync staging with main + +permissions: + contents: write + +on: + push: + branches: + - main + +jobs: + sync: + runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Fast-forward staging to main (only if staging has no unreleased work) + run: | + main_sha=$(git rev-parse origin/main) + staging_sha=$(git rev-parse origin/staging) + echo "main is at: $main_sha" + echo "staging is at: $staging_sha" + + if [ "$main_sha" = "$staging_sha" ]; then + echo "staging is already in sync with main" + exit 0 + fi + + # Check if staging is an ancestor of main, meaning main already + # contains everything on staging (e.g. staging was merged to main). + # If staging has commits that main doesn't, skip to avoid data loss. + if ! git merge-base --is-ancestor "$staging_sha" "$main_sha"; then + echo "::warning::Skipping sync — staging has commits not yet in main" + exit 0 + fi + + gh api repos/${{ github.repository }}/git/refs/heads/staging \ + -X PATCH \ + -f sha="$main_sha" \ + -F force=true + + echo "Fast-forwarded staging to $main_sha"