Skip to content

Commit c65d6e0

Browse files
authored
Merge pull request #122 from thisisthepy/feat/drop-main-guard
Chore: main protection by settings only (option B)
2 parents e1dc7f5 + d8c405d commit c65d6e0

4 files changed

Lines changed: 14 additions & 54 deletions

File tree

‎.github/workflows/main-source-guard.yml‎

Lines changed: 0 additions & 24 deletions
This file was deleted.

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

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

1514
concurrency:
1615
group: release-sync
@@ -51,17 +50,3 @@ jobs:
5150
else
5251
gh pr create --head release --base main --title "$title" --body "$body"
5352
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 & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@ ignored and overwritten.
1414
The push uses `--force-with-lease` pinned to the remote sha the run observed.
1515
2. The workflow opens (or updates) a pull request `release` -> `main` with the default
1616
`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
17+
Actions to create and approve pull requests*. No PAT is needed; an optional
2118
`RELEASE_PR_TOKEN` secret is used for the PR step when present.
22-
3. Merging that PR is the only way to change `main`. `main-source-guard.yml` fails
23-
any PR into `main` whose head is not `release`.
19+
3. Merging that PR is the only way to change `main`. Branch protection (below) makes `main`
20+
PR-only and lets only administrators merge; the maintainer merges the `release` PR and
21+
checks that its head is `release` (maintainer decision 2026-10-03: no source-branch
22+
workflow, settings only).
2423
4. On push to `main`, `pages.yml` deploys `docs/guide/` to GitHub Pages.
2524

2625
## What is dropped on release
@@ -46,6 +45,5 @@ It refuses to run while `release` is checked out.
4645
tools/release/protect-main.sh # print what would be applied
4746
tools/release/protect-main.sh --apply # apply via gh api (needs admin)
4847

49-
This requires a pull request, blocks force-push and deletion. Classic protection cannot
50-
restrict a PR's source branch, so add the check `only-release-into-main` as required
51-
(the script does; the workflow must have run once first).
48+
This requires a pull request (no approving review needed), blocks direct push, force-push and
49+
deletion, leaves the branch unlocked, and restricts merging to administrators.

‎tools/release/protect-main.sh‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ done
1414
[ -n "$REPO" ] || REPO="{owner}/{repo}" # gh expands these placeholders from the current repo
1515

1616
BODY='{
17-
"required_status_checks": {"strict": true, "contexts": ["only-release-into-main"]},
18-
"enforce_admins": true,
17+
"required_status_checks": null,
18+
"enforce_admins": false,
1919
"required_pull_request_reviews": {"required_approving_review_count": 0},
20-
"restrictions": null,
20+
"restrictions": {"users": [], "teams": [], "apps": []},
2121
"allow_force_pushes": false,
22-
"allow_deletions": false
22+
"allow_deletions": false,
23+
"lock_branch": false
2324
}'
2425
CMD="gh api --method PUT repos/$REPO/branches/$BRANCH/protection --input -"
2526

@@ -29,6 +30,6 @@ if [ "$APPLY" -eq 1 ]; then
2930
else
3031
echo "[dry run] would run: $CMD"
3132
echo "$BODY"
32-
echo "Re-run with --apply to apply. The check 'only-release-into-main' comes from .github/workflows/main-source-guard.yml;"
33-
echo "it must have run once before GitHub accepts it as a required check."
33+
echo "Re-run with --apply to apply (needs admin). 'restrictions' with empty lists means only"
34+
echo "administrators may merge; it is accepted for organisation repositories only."
3435
fi

0 commit comments

Comments
 (0)