1+ name : PHP Auto-Fix & Quality Check
2+
3+ on :
4+ push :
5+ branches :
6+ - ' **'
7+ pull_request :
8+ types : [opened, synchronize, reopened]
9+
10+ jobs :
11+ # 🔧 Auto-fix coding standards (only once, PHP 8.1)
12+ phpcbf-fix :
13+ runs-on : ubuntu-latest
14+ steps :
15+ # 1️⃣ Checkout code
16+ - name : Checkout code
17+ uses : actions/checkout@v4
18+ with :
19+ ref : ${{ github.head_ref || github.ref_name }}
20+ persist-credentials : false # allows bot to push fixes
21+
22+ # 2️⃣ Setup PHP (single version for auto-fix)
23+ - name : Setup PHP 8.3
24+ uses : shivammathur/setup-php@v2
25+ with :
26+ php-version : 8.3
27+ coverage : none
28+
29+ # 3️⃣ Install PHPCS
30+ - name : Install PHPCS
31+ run : |
32+ composer global require squizlabs/php_codesniffer
33+ echo "$HOME/.config/composer/vendor/bin" >> $GITHUB_PATH
34+
35+ # 4️⃣ Run PHPCBF (auto-fix issues)
36+ - name : Run PHPCBF
37+ run : phpcbf --standard=PSR12 src/ || true
38+
39+ # 5️⃣ Commit & push fixes back to branch
40+ - name : Commit and push PHPCBF fixes
41+ if : github.ref != 'refs/heads/main' # optional: skip main
42+ env :
43+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
44+ run : |
45+ git config user.name "github-actions[bot]"
46+ git config user.email "github-actions[bot]@users.noreply.github.com"
47+ git add .
48+ # commit only if there are changes
49+ if ! git diff-index --quiet HEAD; then
50+ git commit -m "PHPCBF: auto-fix coding standards"
51+ # determine branch for PRs or direct pushes
52+ BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
53+ # pull remote changes to avoid rejection
54+ git fetch origin $BRANCH
55+ git rebase origin/$BRANCH
56+ # push fixes
57+ git push https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git HEAD:$BRANCH
58+ else
59+ echo "No changes to commit, skipping push."
60+ fi
61+
62+ # 🧪 Run PHPCS + PHPStan on multiple PHP versions
63+ php-quality :
64+ runs-on : ubuntu-latest
65+ needs : phpcbf-fix
66+ strategy :
67+ fail-fast : false
68+ matrix :
69+ php-version : [7.3, 7.4, 8.0, 8.1, 8.2, 8.3]
70+
71+ steps :
72+ # 1️⃣ Checkout code
73+ - name : Checkout code
74+ uses : actions/checkout@v4
75+
76+ # 2️⃣ Setup PHP for matrix
77+ - name : Setup PHP ${{ matrix.php-version }}
78+ uses : shivammathur/setup-php@v2
79+ with :
80+ php-version : ${{ matrix.php-version }}
81+ coverage : none
82+
83+ # 3️⃣ Install PHPStan + PHPCS
84+ - name : Install PHPStan and PHPCS
85+ run : |
86+ composer global require phpstan/phpstan squizlabs/php_codesniffer
87+ echo "$HOME/.config/composer/vendor/bin" >> $GITHUB_PATH
88+
89+ # 4️⃣ Run PHPStan
90+ - name : Run PHPStan
91+ run : phpstan analyse src --memory-limit=1G
92+
93+ # 5️⃣ Run PHPCS
94+ - name : Run PHPCS (lint only)
95+ run : phpcs --standard=PSR12 --warning-severity=0 src/
0 commit comments