Skip to content

Commit 2b6cf99

Browse files
committed
ci: gate main behind a stable ci-ok context and run real CI on release commits before pushing to protected main
1 parent 275d05c commit 2b6cf99

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
pull_request:
55
push:
66
branches: [main]
7+
workflow_dispatch:
78

89
permissions:
910
contents: read
@@ -53,3 +54,13 @@ jobs:
5354
run: go test .
5455
env:
5556
ROXY_API_KEY: ${{ secrets.ROXY_API_KEY }}
57+
58+
# Single stable context for branch protection: matrix legs rename as Go versions rotate, this name never does.
59+
ci-ok:
60+
if: always()
61+
needs: [checks, test]
62+
runs-on: ubuntu-latest
63+
steps:
64+
- run: |
65+
test "${{ needs.checks.result }}" = "success"
66+
test "${{ needs.test.result }}" = "success"

.github/workflows/release.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ on:
1414

1515
permissions:
1616
contents: write
17+
actions: write
1718

1819
jobs:
1920
release:
@@ -67,14 +68,29 @@ jobs:
6768
6869
- name: Commit, tag, push
6970
if: steps.diff.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'
71+
env:
72+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
7073
run: |
7174
git config user.name "github-actions[bot]"
7275
git config user.email "github-actions[bot]@users.noreply.github.com"
7376
V=${{ steps.bump.outputs.version }}
7477
git add specs/openapi.json roxyapi.gen.go roxy.gen.go version.go README.md AGENTS.md docs/llms-full.txt
7578
git commit -m "release: v$V"
7679
git tag "v$V"
80+
# Protected main requires the ci-ok context green on every pushed SHA, and a direct push can never carry one. So park the commit on a temp branch, run the real CI there via workflow_dispatch (GITHUB_TOKEN pushes trigger no workflows on their own), and push to main only after it reports green.
81+
SHA=$(git rev-parse HEAD)
82+
git push --force origin "HEAD:refs/heads/release-checks"
83+
gh workflow run ci.yml --ref release-checks
84+
RUN_ID=""
85+
for _ in $(seq 1 24); do
86+
sleep 5
87+
RUN_ID=$(gh run list --workflow=ci.yml --branch=release-checks --limit 5 --json databaseId,headSha --jq "[.[] | select(.headSha == \"$SHA\")][0].databaseId // empty")
88+
[ -n "$RUN_ID" ] && break
89+
done
90+
[ -n "$RUN_ID" ] || { echo "dispatched CI run never appeared for $SHA"; exit 1; }
91+
gh run watch "$RUN_ID" --exit-status
7792
git push --follow-tags
93+
git push origin --delete release-checks || true
7894
7995
- name: Index new version on pkg.go.dev
8096
if: steps.diff.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'

0 commit comments

Comments
 (0)