Skip to content

Commit 23c8caf

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 40e8200 commit 23c8caf

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

.github/workflows/ci.yml

Lines changed: 9 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
@@ -45,3 +46,11 @@ jobs:
4546

4647
- name: Test
4748
run: vendor/bin/pest --no-coverage
49+
50+
# Single stable context for branch protection: matrix legs rename as PHP versions rotate, this name never does.
51+
ci-ok:
52+
if: always()
53+
needs: [test]
54+
runs-on: ubuntu-latest
55+
steps:
56+
- run: test "${{ needs.test.result }}" = "success"

.github/workflows/release.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ jobs:
1717
runs-on: ubuntu-latest
1818
permissions:
1919
contents: write
20+
actions: write
2021
steps:
2122
- uses: actions/checkout@v7
2223
with:
@@ -78,14 +79,29 @@ jobs:
7879
7980
- name: Commit, tag, push
8081
if: steps.diff.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'
82+
env:
83+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8184
run: |
8285
git config user.name "github-actions[bot]"
8386
git config user.email "github-actions[bot]@users.noreply.github.com"
8487
VERSION="${{ steps.bump.outputs.version }}"
8588
git add composer.json package.json src/Version.php specs/openapi.json src/Roxy.php src/Generated tests/Generated README.md AGENTS.md
8689
git commit -m "release: v$VERSION"
8790
git tag "v$VERSION"
91+
# 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.
92+
SHA=$(git rev-parse HEAD)
93+
git push --force origin "HEAD:refs/heads/release-checks"
94+
gh workflow run ci.yml --ref release-checks
95+
RUN_ID=""
96+
for _ in $(seq 1 24); do
97+
sleep 5
98+
RUN_ID=$(gh run list --workflow=ci.yml --branch=release-checks --limit 5 --json databaseId,headSha --jq "[.[] | select(.headSha == \"$SHA\")][0].databaseId // empty")
99+
[ -n "$RUN_ID" ] && break
100+
done
101+
[ -n "$RUN_ID" ] || { echo "dispatched CI run never appeared for $SHA"; exit 1; }
102+
gh run watch "$RUN_ID" --exit-status
88103
git push --follow-tags
104+
git push origin --delete release-checks || true
89105
90106
- name: Create GitHub release
91107
if: steps.diff.outputs.changed == 'true' || github.event_name == 'workflow_dispatch'

0 commit comments

Comments
 (0)