-
Notifications
You must be signed in to change notification settings - Fork 1
admin: add GitHub App branch ruleset control plane #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d1b3102
admin: add protect-next ruleset spec
primeinc 5dde047
admin: add protect-main-release-only ruleset spec
primeinc cc06c87
admin: set github app as sole next ruleset bypass actor
primeinc 64082a5
admin: remove hardcoded app bypass actor from next ruleset spec
primeinc 140251e
admin: add main release branch guard
primeinc c9b060a
admin: add github app ruleset check and upsert workflow
primeinc 30d9c57
admin: add DoNotMergeYet pull request gate
primeinc e152ebe
ci: run gate checks for next branch
primeinc 727b8a4
ci: run web gate for next branch
primeinc d148f4e
admin: require DoNotMergeYet label gate on next
primeinc cdab840
admin: require DoNotMergeYet label gate on main
primeinc 49b0b60
admin: harden ruleset workflow lookups and dispatch guard
primeinc 9db6f0e
admin: add GitHub API next sync workflow
primeinc d866363
admin: require explicit approval gate for ruleset upsert
primeinc d4a8be7
admin: add repository code owners
primeinc db31fd8
admin: require code owner review on next ruleset
primeinc e080ac5
admin: require code owner review on main ruleset
primeinc 1d54bb2
admin: protection-stage rework — drop CODEOWNERS, native bypass, behi…
primeinc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
.github-stars/control-plane/rulesets/protect-main-release-only.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| { | ||
| "name": "protect-main-release-only", | ||
| "target": "branch", | ||
| "enforcement": "disabled", | ||
| "conditions": { | ||
| "ref_name": { | ||
| "include": [ | ||
| "refs/heads/main" | ||
| ], | ||
| "exclude": [] | ||
| } | ||
| }, | ||
| "rules": [ | ||
| { | ||
| "type": "pull_request", | ||
| "parameters": { | ||
| "allowed_merge_methods": [ | ||
| "squash", | ||
| "rebase" | ||
| ], | ||
| "dismiss_stale_reviews_on_push": true, | ||
| "require_code_owner_review": false, | ||
| "require_last_push_approval": false, | ||
| "required_approving_review_count": 0, | ||
| "required_review_thread_resolution": true | ||
| } | ||
| }, | ||
| { | ||
| "type": "required_status_checks", | ||
| "parameters": { | ||
| "strict_required_status_checks_policy": true, | ||
| "required_status_checks": [ | ||
| { | ||
| "context": "admin-branch-sync-guard" | ||
| }, | ||
| { | ||
| "context": "main-release-guard" | ||
| }, | ||
| { | ||
| "context": "do-not-merge-yet" | ||
| }, | ||
| { | ||
| "context": "gate" | ||
| }, | ||
| { | ||
| "context": "workflow-lint" | ||
| }, | ||
| { | ||
| "context": "build" | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| { | ||
| "type": "required_linear_history" | ||
| }, | ||
| { | ||
| "type": "non_fast_forward" | ||
| }, | ||
| { | ||
| "type": "deletion" | ||
| } | ||
| ], | ||
| "bypass_actors": [] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| { | ||
| "name": "protect-next", | ||
| "target": "branch", | ||
| "enforcement": "disabled", | ||
| "conditions": { | ||
| "ref_name": { | ||
| "include": [ | ||
| "refs/heads/next" | ||
| ], | ||
| "exclude": [] | ||
| } | ||
| }, | ||
| "rules": [ | ||
| { | ||
| "type": "pull_request", | ||
| "parameters": { | ||
| "allowed_merge_methods": [ | ||
| "squash", | ||
| "rebase" | ||
| ], | ||
| "dismiss_stale_reviews_on_push": true, | ||
| "require_code_owner_review": false, | ||
| "require_last_push_approval": false, | ||
| "required_approving_review_count": 0, | ||
| "required_review_thread_resolution": true | ||
| } | ||
| }, | ||
| { | ||
| "type": "required_status_checks", | ||
| "parameters": { | ||
| "strict_required_status_checks_policy": true, | ||
| "required_status_checks": [ | ||
| { | ||
| "context": "do-not-merge-yet" | ||
| }, | ||
| { | ||
| "context": "gate" | ||
| }, | ||
| { | ||
| "context": "workflow-lint" | ||
| }, | ||
| { | ||
| "context": "build" | ||
| } | ||
| ] | ||
| } | ||
| }, | ||
| { | ||
| "type": "required_linear_history" | ||
| }, | ||
| { | ||
| "type": "non_fast_forward" | ||
| }, | ||
| { | ||
| "type": "deletion" | ||
| } | ||
| ], | ||
| "bypass_actors": [] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,9 +4,11 @@ on: | |
| pull_request: | ||
| branches: | ||
| - main | ||
| - next | ||
| push: | ||
| branches: | ||
| - main | ||
| - next | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| name: DoNotMergeYet label gate | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: | ||
| - opened | ||
| - reopened | ||
| - synchronize | ||
| - edited | ||
| - labeled | ||
| - unlabeled | ||
| - ready_for_review | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| do-not-merge-yet: | ||
| name: do-not-merge-yet | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Fail when PR has DoNotMergeYet label | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| if jq -e '.pull_request.labels[]? | select(.name == "DoNotMergeYet")' "$GITHUB_EVENT_PATH" >/dev/null; then | ||
| echo "::error::This pull request has the DoNotMergeYet label. Remove the label before merging." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "No DoNotMergeYet label present." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| name: main-release-guard | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| types: | ||
| - opened | ||
| - reopened | ||
| - synchronize | ||
| - edited | ||
| - ready_for_review | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| main-release-guard: | ||
| name: main-release-guard | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Require repo-owned next as source branch for main | ||
| env: | ||
| BASE_REF: ${{ github.event.pull_request.base.ref }} | ||
| HEAD_REF: ${{ github.event.pull_request.head.ref }} | ||
| HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }} | ||
| BASE_REPO: ${{ github.repository }} | ||
| run: | | ||
| set -euo pipefail | ||
| echo "base=$BASE_REF" | ||
| echo "head=$HEAD_REF" | ||
| echo "head_repo=$HEAD_REPO" | ||
| echo "base_repo=$BASE_REPO" | ||
|
|
||
| if [ "$BASE_REF" = "main" ] && { [ "$HEAD_REF" != "next" ] || [ "$HEAD_REPO" != "$BASE_REPO" ]; }; then | ||
| echo "::error::PRs into main must come from the repo-owned next branch. Retarget feature/chore/fork PRs to next first." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "main release guard passed: repo-owned next is the source branch." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| name: admin-branch-sync-guard | ||
|
|
||
| # Per the protection-stage brief (rule #9): admin/control-plane | ||
| # branches must not silently drift behind `main`. This workflow runs | ||
| # on every PR that targets `main` from an `admin/*` head branch and | ||
| # fails the PR if the head branch is behind main. | ||
| # | ||
| # Mechanism: GitHub's | ||
| # `GET /repos/{owner}/{repo}/compare/{base}...{head}` returns | ||
| # `behind_by` — the number of commits in `base` that are not present | ||
| # in `head`. Anything > 0 means the admin PR is stale; the operator | ||
| # must rebase or use the GitHub UI's "Update branch" button (which | ||
| # calls `PUT /repos/{owner}/{repo}/pulls/{pull_number}/update-branch` | ||
| # with the documented `expected_head_sha` for the safe path) before | ||
| # the PR can merge. | ||
| # | ||
| # The 00f-sync-next-with-main.yml workflow uses the same | ||
| # update-branch API for the `next -> main` release PR flow; this | ||
| # workflow is the analogous read-only check for the admin/* PR | ||
| # class. | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| types: | ||
| - opened | ||
| - reopened | ||
| - synchronize | ||
| - ready_for_review | ||
| - edited | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: read | ||
|
|
||
| jobs: | ||
| admin-branch-sync-guard: | ||
| name: admin-branch-sync-guard | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Compare head to base (admin/* only) | ||
| # Pass-through for non-admin heads so this check name remains | ||
| # available as a required status check on every PR to main — | ||
| # required checks that never run leave the PR perpetually | ||
| # pending. | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| REPO: ${{ github.repository }} | ||
| BASE_REF: ${{ github.event.pull_request.base.ref }} | ||
| HEAD_REF: ${{ github.event.pull_request.head.ref }} | ||
| HEAD_SHA: ${{ github.event.pull_request.head.sha }} | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| echo "base=${BASE_REF}" | ||
| echo "head=${HEAD_REF}" | ||
| echo "head_sha=${HEAD_SHA}" | ||
|
|
||
| case "${HEAD_REF}" in | ||
| admin/*) | ||
| echo "Admin/* head detected. Running behind-base check." | ||
| ;; | ||
| *) | ||
| echo "Non-admin head (${HEAD_REF}); admin sync guard does not apply. Pass." | ||
| exit 0 | ||
| ;; | ||
| esac | ||
|
|
||
| # `compare/{base}...{head}` per | ||
| # https://docs.github.com/en/rest/commits/commits#compare-two-commits | ||
| # — `behind_by` counts commits in base that are not in head. | ||
| response=$(gh api \ | ||
| -H "Accept: application/vnd.github+json" \ | ||
| -H "X-GitHub-Api-Version: 2022-11-28" \ | ||
| "/repos/${REPO}/compare/${BASE_REF}...${HEAD_SHA}") | ||
|
|
||
| behind_by=$(jq -r '.behind_by' <<<"${response}") | ||
| ahead_by=$(jq -r '.ahead_by' <<<"${response}") | ||
| status=$(jq -r '.status' <<<"${response}") | ||
|
|
||
| echo "ahead_by=${ahead_by}" | ||
| echo "behind_by=${behind_by}" | ||
| echo "status=${status}" | ||
|
|
||
| if [ "${behind_by}" -gt 0 ]; then | ||
| echo "::error::admin/* PR head is ${behind_by} commit(s) behind ${BASE_REF}. Rebase or use the GitHub UI 'Update branch' button before this PR can merge. The update-branch API takes expected_head_sha=${HEAD_SHA} for the safe path." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "admin/* PR head is up to date with ${BASE_REF} (ahead_by=${ahead_by}, behind_by=0)." | ||
|
|
||
| - name: Sync guard summary | ||
| if: always() | ||
| run: | | ||
| { | ||
| echo "# admin-branch-sync-guard" | ||
| echo "" | ||
| echo "- Trigger: \`pull_request\` to \`main\` from \`admin/*\` head" | ||
| echo "- Mechanism: GitHub REST \`GET /repos/{owner}/{repo}/compare/{base}...{head}\`" | ||
| echo "- Block condition: \`behind_by > 0\`" | ||
| echo "- Unblock: rebase against \`${{ github.event.pull_request.base.ref }}\` or click \"Update branch\" in the PR UI (calls update-branch API with expected_head_sha)" | ||
| } >> "$GITHUB_STEP_SUMMARY" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
protect-nextruleset makesgate,workflow-lint, andbuildmandatory forrefs/heads/next, but those jobs are configured to run only for pull requests intomain(.github/workflows/00-ci.yml:4-6and.github/workflows/00b-web-ci.yml:8-10). Once this ruleset is upserted withenforcement=active, PRs targetingnextwill be blocked waiting for checks that never start, effectively preventing merges intonext.Useful? React with 👍 / 👎.