|
1 | | -name: Coding style |
| 1 | +name: Code Style |
2 | 2 |
|
3 | 3 | on: |
4 | | - pull_request: |
| 4 | + push: |
| 5 | + branches: [main] |
5 | 6 | paths: |
6 | 7 | - '**.php' |
7 | | - - '.composer.json' |
8 | | - - '.php_cs' |
9 | | - - '.github/workflows/php-coding-style.yml' |
10 | | - push: |
| 8 | + - 'composer.json' |
| 9 | + pull_request: |
11 | 10 | paths: |
12 | 11 | - '**.php' |
13 | | - - '.composer.json' |
14 | | - - '.php_cs' |
15 | | - - '.github/workflows/php-coding-style.yml' |
16 | | - branches-ignore: |
17 | | - - main # protected |
| 12 | + - 'composer.json' |
18 | 13 |
|
19 | 14 | jobs: |
20 | | - style: |
| 15 | + fix: |
| 16 | + name: Auto-fix code style |
| 17 | + # Skip fork PRs — GITHUB_TOKEN can't push to external forks. |
| 18 | + # Fork contributors: run `composer rector && composer cs` locally. |
| 19 | + if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository |
21 | 20 | runs-on: ubuntu-latest |
| 21 | + steps: |
| 22 | + - name: Checkout code |
| 23 | + uses: actions/checkout@v6 |
| 24 | + with: |
| 25 | + ref: ${{ github.head_ref }} |
| 26 | + token: ${{ github.token }} |
| 27 | + |
| 28 | + - name: Setup PHP |
| 29 | + uses: shivammathur/setup-php@v2 |
| 30 | + with: |
| 31 | + php-version: 8.3 |
| 32 | + coverage: none |
| 33 | + |
| 34 | + - name: Install composer dependencies |
| 35 | + run: composer install --prefer-dist --no-progress --no-interaction |
| 36 | + |
| 37 | + - name: Rector |
| 38 | + run: composer rector |
22 | 39 |
|
| 40 | + - name: PHP CS Fixer |
| 41 | + run: composer cs |
| 42 | + |
| 43 | + - name: Commit fixes |
| 44 | + uses: stefanzweifel/git-auto-commit-action@v7 |
| 45 | + with: |
| 46 | + commit_message: 'style: auto-fix (rector + php-cs-fixer)' |
| 47 | + commit_author: 'GitHub Actions <actions@github.com>' |
| 48 | + |
| 49 | + check: |
| 50 | + name: Verify code style (forks) |
| 51 | + # Only run the check job on fork PRs where we can't auto-fix. |
| 52 | + if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository |
| 53 | + runs-on: ubuntu-latest |
23 | 54 | steps: |
24 | | - - name: Checkout code |
25 | | - uses: actions/checkout@v6 |
26 | | - |
27 | | - - name: Setup PHP |
28 | | - uses: shivammathur/setup-php@v2 |
29 | | - with: |
30 | | - php-version: 8.4 |
31 | | - coverage: none |
32 | | - env: |
33 | | - COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
34 | | - |
35 | | - - name: Install composer dependencies |
36 | | - run: composer install --no-interaction --no-progress --no-scripts |
37 | | - |
38 | | - - name: Lint facade docblocks |
39 | | - run: php -f vendor/bin/facade.php InteractionDesignFoundation\\GeoIP\\Facades\\GeoIP |
40 | | - |
41 | | - - name: Fix style |
42 | | - uses: docker://oskarstark/php-cs-fixer-ga |
43 | | - with: |
44 | | - args: --config=.php-cs-fixer.php --allow-risky=yes |
45 | | - |
46 | | - - name: Commit changes |
47 | | - uses: stefanzweifel/git-auto-commit-action@v7 |
48 | | - with: |
49 | | - commit_message: Fix coding style |
| 55 | + - name: Checkout code |
| 56 | + uses: actions/checkout@v6 |
| 57 | + |
| 58 | + - name: Setup PHP |
| 59 | + uses: shivammathur/setup-php@v2 |
| 60 | + with: |
| 61 | + php-version: 8.3 |
| 62 | + coverage: none |
| 63 | + |
| 64 | + - name: Install composer dependencies |
| 65 | + run: composer install --prefer-dist --no-progress --no-interaction |
| 66 | + |
| 67 | + - name: Rector (dry-run) |
| 68 | + run: composer rector:dry |
| 69 | + |
| 70 | + - name: PHP CS check |
| 71 | + run: composer cs:check |
0 commit comments