From fd5595b4c41b5b21737a55633276e1a417bcf410 Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Sat, 28 Nov 2026 13:03:57 +0000 Subject: [PATCH 1/2] Replace PHPSTAN_BOT_TOKEN with scoped tokens --- .github/workflows/merge-maintained-branch.yml | 16 ++++++++++++++-- .github/workflows/release.yml | 6 +++--- .github/workflows/send-pr.yml | 8 +++++--- .github/zizmor.yml | 3 ++- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/.github/workflows/merge-maintained-branch.yml b/.github/workflows/merge-maintained-branch.yml index c921eefe..66ad05ca 100644 --- a/.github/workflows/merge-maintained-branch.yml +++ b/.github/workflows/merge-maintained-branch.yml @@ -17,8 +17,11 @@ jobs: merge: name: Merge branch runs-on: ubuntu-latest + environment: + name: push + deployment: false permissions: - contents: read # for actions/checkout to fetch the code; the merge is made with PHPSTAN_BOT_TOKEN + contents: read # for actions/checkout to fetch the code; the merge is made with a phpstan-push App token steps: - name: Harden the runner (Audit all outbound calls) uses: step-security/harden-runner@1d88384fd173af6ecb012dfd0264a306b711241a # v2.22.4 @@ -29,10 +32,19 @@ jobs: uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 with: persist-credentials: false + - 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 + - name: "Merge branch" uses: everlytic/branch-merge@c4a244dc23143f824ae6c022a10732566cb8e973 # 1.1.5 with: - github_token: "${{ secrets.PHPSTAN_BOT_TOKEN }}" + github_token: ${{ steps.push-token.outputs.token }} source_ref: ${{ github.ref }} target_branch: '1.23.x' commit_message_template: 'Merge branch {source_ref} into {target_branch}' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b1e3e2d9..2cca0385 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -18,7 +18,7 @@ jobs: name: "Deploy" runs-on: "ubuntu-latest" permissions: - contents: read # for actions/checkout to fetch the code; the release is created with PHPSTAN_BOT_TOKEN + contents: read # for actions/checkout to fetch the code; the release is created as phpstan-bot with PHPSTAN_BOT_CONTENTS_TOKEN steps: - name: Harden the runner (Audit all outbound calls) @@ -35,12 +35,12 @@ jobs: id: changelog uses: metcalfc/changelog-generator@bb7a08e07e326061351dab6ce89c72f13797043c # v4.9.1 with: - myToken: ${{ secrets.PHPSTAN_BOT_TOKEN }} + myToken: ${{ github.token }} - name: "Create release" run: 'gh release create "$TAG" --verify-tag --title "$TAG" --notes "$CHANGELOG"' env: - GH_TOKEN: ${{ secrets.PHPSTAN_BOT_TOKEN }} + GH_TOKEN: ${{ secrets.PHPSTAN_BOT_CONTENTS_TOKEN }} GH_REPO: ${{ github.repository }} TAG: ${{ github.ref_name }} CHANGELOG: ${{ steps.changelog.outputs.changelog }} diff --git a/.github/workflows/send-pr.yml b/.github/workflows/send-pr.yml index 606451a3..119da389 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 as phpstan-bot 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,6 @@ jobs: persist-credentials: false repository: phpstan/phpstan-src path: phpstan-src - token: ${{ secrets.PHPSTAN_BOT_TOKEN }} ref: 2.3.x - name: "Install dependencies" @@ -55,7 +57,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..a9fb89d3 100644 --- a/.github/zizmor.yml +++ b/.github/zizmor.yml @@ -5,7 +5,8 @@ rules: # send-pr, merge-maintained-branch, release-toot, release-tweet). Moving them into # dedicated environments has to be done in the repository settings first. allow: - - PHPSTAN_BOT_TOKEN + - PHPSTAN_BOT_CONTENTS_TOKEN + - RELEASE_DISPATCH_TOKEN - MASTODON_ACCESS_TOKEN - TWITTER_CONSUMER_API_KEY - TWITTER_CONSUMER_API_SECRET From b6bcdc0989729b30d0f5971b270b50af17043e3b Mon Sep 17 00:00:00 2001 From: "ondrej@mirtes.cz" Date: Mon, 30 Nov 2026 10:05:17 +0000 Subject: [PATCH 2/2] Let merge-maintained-branch push workflow changes Amp-Thread-ID: https://ampcode.com/threads/T-01a22152-db15-752f-a0d3-582d55ae32cb --- .github/workflows/merge-maintained-branch.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/merge-maintained-branch.yml b/.github/workflows/merge-maintained-branch.yml index 66ad05ca..0eea6c2c 100644 --- a/.github/workflows/merge-maintained-branch.yml +++ b/.github/workflows/merge-maintained-branch.yml @@ -40,6 +40,8 @@ jobs: 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: "Merge branch" uses: everlytic/branch-merge@c4a244dc23143f824ae6c022a10732566cb8e973 # 1.1.5