Skip to content

Commit fecc199

Browse files
committed
Make workflows safer
1 parent 2379dc1 commit fecc199

File tree

5 files changed

+29
-15
lines changed

5 files changed

+29
-15
lines changed

.github/workflows/claude-fix-issue.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ jobs:
1919
name: "Fix #${{ inputs.issue-number }}"
2020
runs-on: blacksmith-4vcpu-ubuntu-2404
2121
timeout-minutes: 60
22+
permissions:
23+
contents: read
24+
issues: read
25+
pull-requests: write
2226

2327
steps:
2428
- name: "Checkout"
@@ -27,7 +31,6 @@ jobs:
2731
repository: phpstan/phpstan-src
2832
ref: "2.1.x"
2933
fetch-depth: 0
30-
token: ${{ secrets.PHPSTAN_BOT_TOKEN }}
3134

3235
- name: "Install PHP"
3336
uses: "shivammathur/setup-php@v2"
@@ -45,7 +48,7 @@ jobs:
4548
- name: "Fetch issue details"
4649
id: issue
4750
env:
48-
GH_TOKEN: ${{ secrets.PHPSTAN_BOT_TOKEN }}
51+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4952
ISSUE_NUMBER: ${{ inputs.issue-number }}
5053
run: |
5154
ISSUE_JSON=$(gh issue view "$ISSUE_NUMBER" \
@@ -158,7 +161,7 @@ jobs:
158161
- name: "Run Claude Code"
159162
env:
160163
CLAUDE_CODE_OAUTH_TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
161-
GH_TOKEN: ${{ secrets.PHPSTAN_BOT_TOKEN }}
164+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
162165
run: |
163166
git config user.name "phpstan-bot"
164167
git config user.email "ondrej+phpstanbot@mirtes.cz"
@@ -196,7 +199,6 @@ jobs:
196199
id: create-pr
197200
uses: peter-evans/create-pull-request@v6
198201
with:
199-
token: ${{ secrets.PHPSTAN_BOT_TOKEN }}
200202
branch-suffix: random
201203
delete-branch: true
202204
title: "Fix #${{ inputs.issue-number }}: ${{ steps.issue.outputs.title }}"

.github/workflows/claude-fix-pr-ci.yml

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,24 @@ jobs:
2626
ignoreActions: "Wait for CI checks,Fix CI failure,Automerge PRs"
2727
checkInterval: 13
2828
env:
29-
GITHUB_TOKEN: "${{ secrets.PHPSTAN_BOT_TOKEN }}"
29+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
3030

3131
fix-ci:
3232
name: "Fix CI failure"
3333
needs: wait-for-checks
3434
if: needs.wait-for-checks.outputs.status == 'failure'
3535
runs-on: blacksmith-4vcpu-ubuntu-2404
3636
timeout-minutes: 60
37+
permissions:
38+
contents: read
39+
actions: read
40+
pull-requests: write
3741

3842
steps:
3943
- name: "Check fix attempt count"
4044
id: check-attempts
4145
env:
42-
GH_TOKEN: ${{ secrets.PHPSTAN_BOT_TOKEN }}
46+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4347
PR_NUMBER: ${{ github.event.pull_request.number }}
4448
run: |
4549
COMMITS=$(gh api "repos/${{ github.repository }}/pulls/$PR_NUMBER/commits?per_page=100" \
@@ -58,7 +62,7 @@ jobs:
5862
if: steps.check-attempts.outputs.skip != 'true'
5963
id: failures
6064
env:
61-
GH_TOKEN: ${{ secrets.PHPSTAN_BOT_TOKEN }}
65+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6266
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
6367
run: |
6468
FAILED_RUNS=$(gh api "repos/${{ github.repository }}/actions/runs?head_sha=$HEAD_SHA&status=failure&per_page=20" \
@@ -114,7 +118,6 @@ jobs:
114118
with:
115119
ref: ${{ github.head_ref }}
116120
fetch-depth: 0
117-
token: ${{ secrets.PHPSTAN_BOT_TOKEN }}
118121

119122
- name: "Install PHP"
120123
if: steps.check-attempts.outputs.skip != 'true' && steps.failures.outputs.skip != 'true'
@@ -196,7 +199,7 @@ jobs:
196199
if: steps.check-attempts.outputs.skip != 'true' && steps.failures.outputs.skip != 'true'
197200
env:
198201
CLAUDE_CODE_OAUTH_TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
199-
GH_TOKEN: ${{ secrets.PHPSTAN_BOT_TOKEN }}
202+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
200203
run: |
201204
git config user.name "phpstan-bot"
202205
git config user.email "ondrej+phpstanbot@mirtes.cz"

.github/workflows/claude-random-easy-fixes.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ jobs:
1818
outputs:
1919
matrix: ${{ steps.pick-issues.outputs.matrix }}
2020

21+
permissions:
22+
contents: read
23+
issues: read
24+
2125
steps:
2226
- name: "Pick random Easy fix issues"
2327
id: pick-issues

.github/workflows/claude-react-on-comment.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,17 @@ jobs:
3939
if: needs.check-trigger.outputs.triggered == 'true'
4040
runs-on: blacksmith-4vcpu-ubuntu-2404
4141
timeout-minutes: 60
42+
permissions:
43+
contents: read
44+
issues: write
45+
pull-requests: write
46+
id-token: write
4247

4348
steps:
4449
- name: "Checkout"
4550
uses: actions/checkout@v4
4651
with:
4752
fetch-depth: 0
48-
token: ${{ secrets.PHPSTAN_BOT_TOKEN }}
4953

5054
- name: "Install PHP"
5155
uses: "shivammathur/setup-php@v2"
@@ -61,7 +65,6 @@ jobs:
6165
uses: anthropics/claude-code-action@v1
6266
with:
6367
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
64-
github_token: ${{ secrets.PHPSTAN_BOT_TOKEN }}
6568
trigger_phrase: "@phpstan-bot"
6669
claude_args: "--model claude-opus-4-6"
6770
bot_name: "phpstan-bot"

.github/workflows/issue-bot.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,15 @@ jobs:
236236
if: github.event_name == 'pull_request' && github.event.pull_request.user.login == 'phpstan-bot'
237237
runs-on: blacksmith-4vcpu-ubuntu-2404
238238
timeout-minutes: 60
239+
permissions:
240+
contents: read
241+
pull-requests: write
239242

240243
steps:
241244
- name: "Check for feedback loop"
242245
id: check
243246
env:
244-
GH_TOKEN: ${{ secrets.PHPSTAN_BOT_TOKEN }}
247+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
245248
run: |
246249
COMMIT_MSG=$(gh api "repos/${{ github.repository }}/commits/${{ github.event.pull_request.head.sha }}" --jq '.commit.message' 2>/dev/null || true)
247250
if [[ "$COMMIT_MSG" == "Add regression test for #"* ]]; then
@@ -257,7 +260,6 @@ jobs:
257260
with:
258261
ref: ${{ github.head_ref }}
259262
fetch-depth: 0
260-
token: ${{ secrets.PHPSTAN_BOT_TOKEN }}
261263

262264
- name: "Download step summary"
263265
if: steps.check.outputs.skip != 'true'
@@ -292,7 +294,7 @@ jobs:
292294
if: steps.check.outputs.skip != 'true'
293295
env:
294296
CLAUDE_CODE_OAUTH_TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
295-
GH_TOKEN: ${{ secrets.PHPSTAN_BOT_TOKEN }}
297+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
296298
run: |
297299
git config user.name "phpstan-bot"
298300
git config user.email "ondrej+phpstanbot@mirtes.cz"
@@ -318,7 +320,7 @@ jobs:
318320
- name: "Update PR description"
319321
if: steps.check.outputs.skip != 'true'
320322
env:
321-
GH_TOKEN: ${{ secrets.PHPSTAN_BOT_TOKEN }}
323+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
322324
run: |
323325
BEFORE_SHA="${{ steps.before.outputs.sha }}"
324326
CURRENT_SHA="$(git rev-parse HEAD)"

0 commit comments

Comments
 (0)