|
| 1 | +name: Release ruleset probe |
| 2 | + |
| 3 | +# Read the bump's ruleset barrier with the release App installation token. |
| 4 | +# Keep the mint step identical to release.yml, including its permission set. |
| 5 | +on: |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +permissions: |
| 9 | + contents: read |
| 10 | + |
| 11 | +jobs: |
| 12 | + authz: |
| 13 | + name: authz |
| 14 | + # Preflight pins executable workflow lines after removing comment-only lines. |
| 15 | + # authz uses pf-gcp-pr; the App-token probe uses pf-gcp-post. |
| 16 | + runs-on: ["self-hosted", "pf-gcp-pr"] |
| 17 | + permissions: {} |
| 18 | + # No timeout-minutes: the owner's no-time-limits rule (check-no-time-limits refuses new ones). |
| 19 | + steps: |
| 20 | + - name: Only our own pull requests and our own events run CI |
| 21 | + env: |
| 22 | + EVENT: ${{ github.event_name }} |
| 23 | + REPO: ${{ github.repository }} |
| 24 | + HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }} |
| 25 | + HEAD_IS_FORK: ${{ github.event.pull_request.head.repo.fork }} |
| 26 | + ASSOCIATION: ${{ github.event.pull_request.author_association }} |
| 27 | + PR_AUTHOR: ${{ github.event.pull_request.user.login }} |
| 28 | + WR_HEAD_REPO: ${{ github.event.workflow_run.head_repository.full_name }} |
| 29 | + WR_ACTOR: ${{ github.event.workflow_run.triggering_actor.login }} |
| 30 | + GH_TOKEN: ${{ github.token }} # read-only use: one permission lookup for workflow_run |
| 31 | + # Bot logins whose same-repository pull requests count as ours: dependabot[bot] (CI-DEPBOT A) |
| 32 | + # and the org's own GitHub App bot logins by name (space-separated), nothing else. |
| 33 | + ALLOWED_BOTS: "dependabot[bot] pineforge-app[bot]" |
| 34 | + run: | |
| 35 | + set -eu |
| 36 | + fail() { echo "::error title=authz::$1"; echo "authz: REFUSED: $1" >> "$GITHUB_STEP_SUMMARY"; exit 1; } |
| 37 | + case "$EVENT" in |
| 38 | + push|workflow_dispatch|schedule|merge_group|release|workflow_call|repository_dispatch) |
| 39 | + # Only someone with write access to this repository (or our App's token) can cause these |
| 40 | + # events; none of them runs pull-request code. |
| 41 | + ;; |
| 42 | + workflow_run) |
| 43 | + # LB-437: bind identity to the triggering run and its re-runner. |
| 44 | + # These two App bots are fixed canon policy; ALLOWED_BOTS is PR-only. |
| 45 | + [ -n "${WR_HEAD_REPO:-}" ] || fail "workflow_run head repository is missing" |
| 46 | + [ -n "${WR_ACTOR:-}" ] || fail "workflow_run triggering actor is missing" |
| 47 | + [ "$WR_HEAD_REPO" = "$REPO" ] || fail "workflow_run head repository does not match this repository" |
| 48 | + case "$WR_ACTOR" in |
| 49 | + "pineforge-app[bot]"|"pineforge-ci-dispatcher[bot]") ;; |
| 50 | + *"[bot]") fail "workflow_run bot is not on the canon allowlist" ;; |
| 51 | + *) |
| 52 | + perm=$(gh api "repos/$REPO/collaborators/$WR_ACTOR/permission" --jq .permission 2>/dev/null) || fail "workflow_run permission lookup failed" |
| 53 | + case "$perm" in admin|maintain|write) ;; *) fail "workflow_run triggering actor does not have write permission" ;; esac ;; |
| 54 | + esac ;; |
| 55 | + pull_request) |
| 56 | + [ "$HEAD_REPO" = "$REPO" ] || fail "pull request from another repository (${HEAD_REPO:-unknown})" |
| 57 | + [ "$HEAD_IS_FORK" = "false" ] || fail "pull request from a fork" |
| 58 | + case "$ASSOCIATION" in |
| 59 | + OWNER|MEMBER|COLLABORATOR) ;; |
| 60 | + *) |
| 61 | + case " $ALLOWED_BOTS " in |
| 62 | + *" $PR_AUTHOR "*) ;; |
| 63 | + *) |
| 64 | + # A member whose org membership is private shows as CONTRIBUTOR: ask GitHub for the |
| 65 | + # author's permission on this repository; anything but admin/maintain/write (or a |
| 66 | + # failed call) refuses. |
| 67 | + perm=$(gh api "repos/$REPO/collaborators/$PR_AUTHOR/permission" --jq .permission 2>/dev/null || echo none) |
| 68 | + case "$perm" in admin|maintain|write) ;; *) fail "author ${PR_AUTHOR:-unknown} (${ASSOCIATION:-NONE}) has permission '$perm', not write, and is not an allowlisted bot" ;; esac ;; |
| 69 | + esac ;; |
| 70 | + esac ;; |
| 71 | + *) fail "event $EVENT does not run CI (pull_request_target and other events are not allowed)" ;; |
| 72 | + esac |
| 73 | + echo "authz: allowed ($EVENT${PR_AUTHOR:+ by $PR_AUTHOR})" >> "$GITHUB_STEP_SUMMARY" |
| 74 | +
|
| 75 | + probe: |
| 76 | + needs: [authz] |
| 77 | + runs-on: ["self-hosted","pf-gcp-post"] |
| 78 | + steps: |
| 79 | + - name: Refuse a dispatch ref other than main |
| 80 | + env: |
| 81 | + REF: ${{ github.ref }} |
| 82 | + run: | |
| 83 | + set -euo pipefail |
| 84 | + fail() { echo "::error title=rulesets-probe::$1"; echo "rulesets-probe: REFUSED: $1" >> "$GITHUB_STEP_SUMMARY"; exit 1; } |
| 85 | + [ "$REF" = refs/heads/main ] || fail "release ruleset probe requires refs/heads/main" |
| 86 | +
|
| 87 | + - name: Mint org App token |
| 88 | + id: app |
| 89 | + uses: actions/create-github-app-token@v1 |
| 90 | + with: |
| 91 | + app-id: ${{ secrets.PINEFORGE_APP_ID }} |
| 92 | + private-key: ${{ secrets.PINEFORGE_APP_PRIVATE_KEY }} |
| 93 | + owner: ${{ github.repository_owner }} |
| 94 | + repositories: pineforge-engine |
| 95 | + |
| 96 | + - name: Checkout |
| 97 | + if: ${{ needs.authz.result == 'success' }} |
| 98 | + uses: actions/checkout@v4 |
| 99 | + with: |
| 100 | + persist-credentials: false |
| 101 | + |
| 102 | + - name: Probe release ruleset barrier |
| 103 | + if: ${{ needs.authz.result == 'success' }} |
| 104 | + env: |
| 105 | + GH_TOKEN: ${{ steps.app.outputs.token }} |
| 106 | + run: python3 scripts/ci_release_gate.py rulesets-probe --repo "${GITHUB_REPOSITORY}" |
0 commit comments