Skip to content

Commit 9dfaed3

Browse files
committed
fix: make php-cs-fixer action work with fork PRs
The checkout step used `ref: ${{ github.head_ref }}` which tries to fetch the PR head branch from the base repository. For PRs from forks, this branch doesn't exist in the base repo, causing the git fetch to fail. Additionally, the auto-commit step cannot push to fork branches using the base repo's GITHUB_TOKEN. Fix by using the default checkout (which fetches the merge commit for pull_request events, working for both fork and same-repo PRs) and switching from `fix` to `check --diff` mode. This reports formatting issues without trying to auto-commit, which is the correct behavior for an open-source project accepting external contributions. https://claude.ai/code/session_01TRNQg795oQmXbu8pXNgYCT
1 parent 7c59b0f commit 9dfaed3

File tree

1 file changed

+1
-13
lines changed

1 file changed

+1
-13
lines changed

.github/workflows/cs-fixer.yml

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,11 @@ name: PHP CS Fixer
33
on:
44
pull_request:
55

6-
permissions:
7-
contents: write
8-
96
jobs:
107
cs-fixer:
118
runs-on: ubuntu-22.04
129
steps:
1310
- uses: actions/checkout@v6
14-
with:
15-
ref: ${{ github.head_ref }}
16-
token: ${{ secrets.GITHUB_TOKEN }}
1711

1812
- name: Install PHP
1913
uses: shivammathur/setup-php@v2
@@ -35,10 +29,4 @@ jobs:
3529
run: composer install --prefer-dist
3630

3731
- name: Run PHP CS Fixer
38-
run: ./bin/php-cs-fixer fix --diff
39-
40-
- name: Commit CS Fixer fixes
41-
uses: stefanzweifel/git-auto-commit-action@v7
42-
with:
43-
commit_message: "style: apply php-cs-fixer changes"
44-
commit_author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"
32+
run: ./bin/php-cs-fixer check --diff

0 commit comments

Comments
 (0)