Skip to content

Commit 6ddd6d2

Browse files
committed
Fix: Let release-sync satisfy the main guard without a PAT
A pull request opened with GITHUB_TOKEN triggers no workflows, so the required only-release-into-main check never reported and the release PR could never merge. release-sync now sets that status on the release commit it generated. Same change as python-multiplatform.
1 parent f5ec437 commit 6ddd6d2

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

‎.github/workflows/release-sync.yml‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
permissions:
1111
contents: write
1212
pull-requests: write
13+
statuses: write
1314

1415
concurrency:
1516
group: release-sync
@@ -33,9 +34,8 @@ jobs:
3334
3435
- name: Open or update PR release -> main
3536
env:
36-
# PRs created with GITHUB_TOKEN do not trigger other workflows, so the
37-
# main-source-guard check would never run on this PR. Set the optional
38-
# secret RELEASE_PR_TOKEN (PAT or app token) to make it run.
37+
# Needs "Allow GitHub Actions to create and approve pull requests" in the
38+
# repository's Actions settings. RELEASE_PR_TOKEN is optional.
3939
GH_TOKEN: ${{ secrets.RELEASE_PR_TOKEN || github.token }}
4040
run: |
4141
set -eu
@@ -51,3 +51,17 @@ jobs:
5151
else
5252
gh pr create --head release --base main --title "$title" --body "$body"
5353
fi
54+
55+
# A PR opened with GITHUB_TOKEN triggers no workflows, so main-source-guard
56+
# never runs on it. Report the guard's verdict for the release commit here:
57+
# this job just generated it from develop, which is exactly what the guard
58+
# requires. A status set with GITHUB_TOKEN satisfies a required check.
59+
- name: Mark release as passing the main source guard
60+
env:
61+
GH_TOKEN: ${{ github.token }}
62+
run: |
63+
set -eu
64+
if ! git rev-parse -q --verify refs/heads/release >/dev/null; then exit 0; fi
65+
gh api "repos/${GITHUB_REPOSITORY}/statuses/$(git rev-parse release)" \
66+
-f state=success -f context=only-release-into-main \
67+
-f description="generated from develop ${GITHUB_SHA::7} by release-sync"

‎tools/release/README.md‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ ignored and overwritten.
1212
whose tree is the develop tree minus the files below. This happens even when nothing
1313
is dropped. It is a no-op only if `release` already has that tree and that parent.
1414
The push uses `--force-with-lease` pinned to the remote sha the run observed.
15-
2. The workflow opens (or updates) a pull request `release` -> `main`. PRs created with
16-
the default `GITHUB_TOKEN` do not trigger other workflows, so `main-source-guard`
17-
would not run on them. To make it run, add a repository secret `RELEASE_PR_TOKEN`
18-
(a PAT or GitHub App token with pull-request write access); the workflow uses it
19-
when present and falls back to `github.token` otherwise.
15+
2. The workflow opens (or updates) a pull request `release` -> `main` with the default
16+
`GITHUB_TOKEN`. This needs the repository setting *Actions -> General -> Allow GitHub
17+
Actions to create and approve pull requests*. A PR opened with `GITHUB_TOKEN`
18+
triggers no workflows, so `main-source-guard` would never run on it; the workflow
19+
therefore sets the `only-release-into-main` commit status on the release commit
20+
itself, which satisfies the required check. No PAT is needed; an optional
21+
`RELEASE_PR_TOKEN` secret is used for the PR step when present.
2022
3. Merging that PR is the only way to change `main`. `main-source-guard.yml` fails
2123
any PR into `main` whose head is not `release`.
2224
4. On push to `main`, `pages.yml` deploys `docs/guide/` to GitHub Pages.

0 commit comments

Comments
 (0)