From f61aadf18db029f54e1bca1f1186f3125a35b54a Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Thu, 3 Dec 2026 17:41:50 +0000 Subject: [PATCH] Replace PHPSTAN_BOT_TOKEN with scoped tokens Amp-Thread-ID: https://ampcode.com/threads/T-01a23cc3-0490-7181-9065-13f0ab41c8b5 --- .github/workflows/merge-maintained-branch.yml | 36 +++++++++++++------ .github/workflows/send-pr.yml | 9 +++-- .github/zizmor.yml | 8 ++--- 3 files changed, 36 insertions(+), 17 deletions(-) diff --git a/.github/workflows/merge-maintained-branch.yml b/.github/workflows/merge-maintained-branch.yml index c921eefe..96e7137b 100644 --- a/.github/workflows/merge-maintained-branch.yml +++ b/.github/workflows/merge-maintained-branch.yml @@ -7,6 +7,8 @@ on: branches: - "1.22.x" +# The merge is pushed with a phpstan-push App token from the push +# environment, not the workflow token; it stays authored by phpstan-bot. permissions: {} concurrency: @@ -16,23 +18,37 @@ concurrency: jobs: merge: name: Merge branch + if: github.repository_owner == 'phpstan' runs-on: ubuntu-latest - permissions: - contents: read # for actions/checkout to fetch the code; the merge is made with PHPSTAN_BOT_TOKEN + environment: + name: push + deployment: false steps: - name: Harden the runner (Audit all outbound calls) uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 with: egress-policy: audit + - name: "Mint a push token for phpstan/phpdoc-parser" + id: push-token + uses: actions/create-github-app-token@f418cff399f7aef4c2f0ad47e25ca7a6abbdd6fc # v3.4.0 + with: + client-id: ${{ vars.PUSH_APP_CLIENT_ID }} + private-key: ${{ secrets.PUSH_APP_PRIVATE_KEY }} + repositories: phpdoc-parser + permission-contents: write + # the merge may bring changes to .github/workflows + permission-workflows: write + - name: "Checkout" - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 # zizmor: ignore[artipacked] -- the persisted App token credentials push the merge below with: - persist-credentials: false + fetch-depth: 0 + ref: '1.23.x' + token: ${{ steps.push-token.outputs.token }} - name: "Merge branch" - uses: everlytic/branch-merge@c4a244dc23143f824ae6c022a10732566cb8e973 # 1.1.5 - with: - github_token: "${{ secrets.PHPSTAN_BOT_TOKEN }}" - source_ref: ${{ github.ref }} - target_branch: '1.23.x' - commit_message_template: 'Merge branch {source_ref} into {target_branch}' + run: | + git config --global user.name "phpstan-bot" + git config --global user.email "ondrej+phpstanbot@mirtes.cz" + git merge --strategy=ort "origin/${GITHUB_REF_NAME}" -m "Merge branch ${GITHUB_REF_NAME} into 1.23.x" + git push diff --git a/.github/workflows/send-pr.yml b/.github/workflows/send-pr.yml index 606451a3..e0ff0706 100644 --- a/.github/workflows/send-pr.yml +++ b/.github/workflows/send-pr.yml @@ -7,7 +7,7 @@ on: types: [published] # GITHUB_TOKEN needs no permissions: phpstan-src is checked out and the pull request -# is sent with PHPSTAN_BOT_TOKEN. +# is sent with PHPSTAN_BOT_PULL_REQUESTS_TOKEN from the bot-pr environment. permissions: {} concurrency: @@ -18,6 +18,9 @@ jobs: send-pr: name: "Send pull request" runs-on: "ubuntu-latest" + environment: + name: bot-pr + deployment: false steps: - name: Harden the runner (Audit all outbound calls) uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 @@ -36,7 +39,7 @@ jobs: persist-credentials: false repository: phpstan/phpstan-src path: phpstan-src - token: ${{ secrets.PHPSTAN_BOT_TOKEN }} + token: ${{ secrets.PHPSTAN_BOT_PULL_REQUESTS_TOKEN }} ref: 2.3.x - name: "Install dependencies" @@ -55,7 +58,7 @@ jobs: id: create-pr uses: peter-evans/create-pull-request@3ffccacd46053766916f087ce41d627c0b8cf2d1 # v8.1.3 with: - token: ${{ secrets.PHPSTAN_BOT_TOKEN }} + token: ${{ secrets.PHPSTAN_BOT_PULL_REQUESTS_TOKEN }} path: ./phpstan-src branch-suffix: random delete-branch: true diff --git a/.github/zizmor.yml b/.github/zizmor.yml index 741f670d..ff49ecdc 100644 --- a/.github/zizmor.yml +++ b/.github/zizmor.yml @@ -1,11 +1,11 @@ rules: secrets-outside-env: config: - # These are repository secrets used by the release workflows (create-tag, release, - # send-pr, merge-maintained-branch, release-toot, release-tweet). Moving them into - # dedicated environments has to be done in the repository settings first. + # Repository-level secrets used by release automation (create-tag, release, release-toot, + # release-tweet); they are not scoped to deployment environments. allow: - - PHPSTAN_BOT_TOKEN + - PHPSTAN_BOT_CONTENTS_TOKEN + - RELEASE_DISPATCH_TOKEN - MASTODON_ACCESS_TOKEN - TWITTER_CONSUMER_API_KEY - TWITTER_CONSUMER_API_SECRET