Skip to content

Commit daa675d

Browse files
committed
ci: add automatic PHP CS Fixer workflow for PRs
Replace the dry-run CS check in build.yml with a dedicated workflow that automatically runs php-cs-fixer and commits any fixes directly to the PR branch via stefanzweifel/git-auto-commit-action. This removes the burden from contributors who forget to run CS Fixer locally, and ensures the correct PHP/CS Fixer version is always used regardless of the contributor's local environment. https://claude.ai/code/session_01WJEcEkXb8rGmmXPuF3nL95
1 parent 6780dfe commit daa675d

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,6 @@ jobs:
4242
- name: Install dependencies
4343
run: composer install --prefer-dist
4444

45-
- name: Coding Standard Checks
46-
if: ${{ matrix.php-versions == '8.0' }}
47-
run: PHP_CS_FIXER_IGNORE_ENV=1 ./bin/php-cs-fixer fix --dry-run --diff
48-
4945
- name: Static Analysis
5046
if: ${{ matrix.php-versions == '8.0' }}
5147
run: ./bin/psalm.phar --no-cache

.github/workflows/cs-fixer.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: PHP CS Fixer
2+
3+
on:
4+
pull_request:
5+
6+
permissions:
7+
contents: write
8+
9+
jobs:
10+
cs-fixer:
11+
runs-on: ubuntu-22.04
12+
steps:
13+
- uses: actions/checkout@v6
14+
with:
15+
ref: ${{ github.head_ref }}
16+
token: ${{ secrets.GITHUB_TOKEN }}
17+
18+
- name: Install PHP
19+
uses: shivammathur/setup-php@v2
20+
with:
21+
php-version: '8.2'
22+
tools: composer:v2.2
23+
env:
24+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
26+
- name: Cache Composer packages
27+
uses: actions/cache@v5
28+
with:
29+
path: vendor
30+
key: ${{ runner.os }}-php-cs-fixer-${{ hashFiles('**/composer.lock') }}
31+
restore-keys: |
32+
${{ runner.os }}-php-cs-fixer-
33+
34+
- name: Install dependencies
35+
run: composer install --prefer-dist
36+
37+
- 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@v5
42+
with:
43+
commit_message: "style: apply php-cs-fixer changes"
44+
commit_author: "github-actions[bot] <github-actions[bot]@users.noreply.github.com>"

0 commit comments

Comments
 (0)