From f41d6ce5042b4155764d8aae1c6a5a953eff9470 Mon Sep 17 00:00:00 2001 From: Lukas Frey Date: Sat, 28 Nov 2026 19:11:09 +0100 Subject: [PATCH] ci: only admins run builds by hand, only maintainers promote --- .github/actions/require-role/action.yml | 20 +++++++++++++++++++ .../workflows/build-frankenphp-windows.yml | 1 + .github/workflows/build-pg-extension.yml | 1 + .github/workflows/build-php-exts-windows.yml | 1 + .github/workflows/build-php-linux.yml | 1 + .github/workflows/build-php-macos.yml | 1 + .github/workflows/build-service.yml | 1 + .github/workflows/mirror.yml | 1 + .github/workflows/promote.yml | 4 ++++ .github/workflows/release.yml | 1 + README.md | 5 +++-- 11 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 .github/actions/require-role/action.yml diff --git a/.github/actions/require-role/action.yml b/.github/actions/require-role/action.yml new file mode 100644 index 0000000..6a423f5 --- /dev/null +++ b/.github/actions/require-role/action.yml @@ -0,0 +1,20 @@ +# A run started by hand goes on only when whoever started (or re-ran) it has one of the given +# repository roles. Scheduled runs pass: nobody started them. +name: Require role +description: Fails a run started by hand unless whoever started it has one of the given roles +inputs: + roles: + description: Repository roles that may start the run, space-separated + default: admin +runs: + using: composite + steps: + - if: github.event_name == 'workflow_dispatch' + shell: bash + env: + GH_TOKEN: ${{ github.token }} + ACTOR: ${{ github.triggering_actor }} + ROLES: ${{ inputs.roles }} + run: | + role="$(gh api "repos/$GITHUB_REPOSITORY/collaborators/$ACTOR/permission" --jq .role_name)" + [[ " $ROLES " == *" $role "* ]] || { echo "::error::only $ROLES can run this, not $ACTOR ($role)"; exit 1; } diff --git a/.github/workflows/build-frankenphp-windows.yml b/.github/workflows/build-frankenphp-windows.yml index 0b76655..cb2fe83 100644 --- a/.github/workflows/build-frankenphp-windows.yml +++ b/.github/workflows/build-frankenphp-windows.yml @@ -46,6 +46,7 @@ jobs: ok: ${{ steps.done.outputs.ok }} steps: - uses: actions/checkout@v7 + - uses: ./.github/actions/require-role - id: config shell: bash run: | diff --git a/.github/workflows/build-pg-extension.yml b/.github/workflows/build-pg-extension.yml index 7f3788c..bbd5765 100644 --- a/.github/workflows/build-pg-extension.yml +++ b/.github/workflows/build-pg-extension.yml @@ -61,6 +61,7 @@ jobs: asset: ${{ steps.config.outputs.asset }} steps: - uses: actions/checkout@v7 + - uses: ./.github/actions/require-role - id: config shell: bash diff --git a/.github/workflows/build-php-exts-windows.yml b/.github/workflows/build-php-exts-windows.yml index c6e04b4..ca7ba04 100644 --- a/.github/workflows/build-php-exts-windows.yml +++ b/.github/workflows/build-php-exts-windows.yml @@ -53,6 +53,7 @@ jobs: GH_TOKEN: ${{ github.token }} steps: - uses: actions/checkout@v7 + - uses: ./.github/actions/require-role - id: config run: | echo "asset=php-exts-$MINOR-build$(jq -r .php.windows.extensions.build versions.json)-windows-x64.zip" >> "$GITHUB_OUTPUT" diff --git a/.github/workflows/build-php-linux.yml b/.github/workflows/build-php-linux.yml index ea5f961..293e745 100644 --- a/.github/workflows/build-php-linux.yml +++ b/.github/workflows/build-php-linux.yml @@ -68,6 +68,7 @@ jobs: GITHUB_TOKEN: ${{ github.token }} steps: - uses: actions/checkout@v7 + - uses: ./.github/actions/require-role - name: Read versions.json id: config diff --git a/.github/workflows/build-php-macos.yml b/.github/workflows/build-php-macos.yml index b941bb5..8918e3b 100644 --- a/.github/workflows/build-php-macos.yml +++ b/.github/workflows/build-php-macos.yml @@ -59,6 +59,7 @@ jobs: GITHUB_TOKEN: ${{ github.token }} steps: - uses: actions/checkout@v7 + - uses: ./.github/actions/require-role - name: Read versions.json id: config diff --git a/.github/workflows/build-service.yml b/.github/workflows/build-service.yml index 49a5a9f..d00fcd5 100644 --- a/.github/workflows/build-service.yml +++ b/.github/workflows/build-service.yml @@ -59,6 +59,7 @@ jobs: GITHUB_TOKEN: ${{ github.token }} steps: - uses: actions/checkout@v7 + - uses: ./.github/actions/require-role - id: config shell: bash diff --git a/.github/workflows/mirror.yml b/.github/workflows/mirror.yml index 9c34d00..32c5acb 100644 --- a/.github/workflows/mirror.yml +++ b/.github/workflows/mirror.yml @@ -61,6 +61,7 @@ jobs: GITHUB_TOKEN: ${{ github.token }} steps: - uses: actions/checkout@v7 + - uses: ./.github/actions/require-role - id: config run: | # PHP for Windows is configured next to PHP for macOS, not under packages. diff --git a/.github/workflows/promote.yml b/.github/workflows/promote.yml index edfac73..0b51b6d 100644 --- a/.github/workflows/promote.yml +++ b/.github/workflows/promote.yml @@ -1,6 +1,7 @@ # Records a channel decision in channels.json, commits it to main as whoever ran the workflow, and # rebuilds the manifests from that commit right away (manifest.yml), so it takes effect within # minutes. Run it from the Actions tab; the "Ready for testing" issue lists what is waiting. +# Only admins and maintainers can run it. # promote-beta approve for beta (then stable after the patch waiting time) # promote-stable approve for stable (never for pre-releases) # hold / unhold stop or restart every timer of a build (hold needs a reason) @@ -47,6 +48,9 @@ jobs: REASON: ${{ inputs.reason }} steps: - uses: actions/checkout@v7 + - uses: ./.github/actions/require-role + with: + roles: admin maintain - uses: actions/setup-go@v7 with: go-version-file: tools/flockrel/go.mod diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e5a7e4a..930da07 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -44,6 +44,7 @@ jobs: mirrors: ${{ steps.plan.outputs.mirrors }} steps: - uses: actions/checkout@v7 + - uses: ./.github/actions/require-role - uses: actions/setup-go@v7 with: go-version-file: tools/flockrel/go.mod diff --git a/README.md b/README.md index 2cab50a..3cc5645 100644 --- a/README.md +++ b/README.md @@ -169,7 +169,7 @@ mirrors and tests each one, and uploads it to a release tagged `-