|
| 1 | +# Sync gix-main branch with upstream/main. |
| 2 | +# |
| 3 | +# gix-main is a pristine mirror of GitoxideLabs/gitoxide's main branch. |
| 4 | +# It MUST stay fast-forward-only. If a fast-forward fails, something |
| 5 | +# has gone wrong and we want to know about it immediately rather than |
| 6 | +# papering over it with a merge commit. |
| 7 | +# |
| 8 | +# Branch protection for gix-main should forbid direct pushes from |
| 9 | +# anyone but this workflow. |
| 10 | +name: sync-gix-main |
| 11 | + |
| 12 | +on: |
| 13 | + schedule: |
| 14 | + # Every 6 hours. Upstream moves at a few commits per day, this is enough |
| 15 | + # cadence to have gix-main be fresh without burning Actions minutes. |
| 16 | + - cron: "17 */6 * * *" |
| 17 | + workflow_dispatch: {} |
| 18 | + |
| 19 | +permissions: |
| 20 | + contents: write |
| 21 | + |
| 22 | +jobs: |
| 23 | + sync: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - name: Checkout gix-main |
| 27 | + uses: actions/checkout@v4 |
| 28 | + with: |
| 29 | + ref: gix-main |
| 30 | + fetch-depth: 0 |
| 31 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 32 | + |
| 33 | + - name: Configure git identity |
| 34 | + run: | |
| 35 | + git config user.name "gix-main sync bot" |
| 36 | + git config user.email "ci@ethosengine.invalid" |
| 37 | +
|
| 38 | + - name: Add upstream remote |
| 39 | + run: | |
| 40 | + git remote add upstream https://github.com/GitoxideLabs/gitoxide.git |
| 41 | + git fetch upstream main --tags |
| 42 | +
|
| 43 | + - name: Fast-forward gix-main to upstream/main |
| 44 | + id: ff |
| 45 | + run: | |
| 46 | + set -eu |
| 47 | + before="$(git rev-parse HEAD)" |
| 48 | + target="$(git rev-parse upstream/main)" |
| 49 | + if [ "$before" = "$target" ]; then |
| 50 | + echo "Already up-to-date at $before." |
| 51 | + echo "changed=false" >> "$GITHUB_OUTPUT" |
| 52 | + exit 0 |
| 53 | + fi |
| 54 | + # Fast-forward only. If this fails, gix-main has diverged from |
| 55 | + # upstream/main — that should never happen and is worth a loud failure. |
| 56 | + git merge --ff-only upstream/main |
| 57 | + after="$(git rev-parse HEAD)" |
| 58 | + echo "Advanced gix-main: $before -> $after" |
| 59 | + echo "changed=true" >> "$GITHUB_OUTPUT" |
| 60 | +
|
| 61 | + - name: Push updated gix-main |
| 62 | + if: steps.ff.outputs.changed == 'true' |
| 63 | + run: git push origin gix-main |
| 64 | + |
| 65 | + - name: Push mirrored tags |
| 66 | + if: steps.ff.outputs.changed == 'true' |
| 67 | + run: git push origin --tags |
0 commit comments