Skip to content

Commit afccd35

Browse files
committed
ci: consolidate style workflows into one auto-fix workflow
Replace php-cs-fixer.yml (hard gate) and format_php.yml (both referenced removed composer scripts) with a single coding-standard.yml that runs Rector, PHP-CS-Fixer and phpcbf, then commits fixes back. `composer cs` now chains both tools. README links to the workflow as a usage example.
1 parent 01ed102 commit afccd35

6 files changed

Lines changed: 53 additions & 152 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Coding standard
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.php'
7+
- '**.xml'
8+
- 'composer.*'
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: write
13+
14+
concurrency:
15+
group: coding-standard-${{ github.ref }}
16+
cancel-in-progress: true
17+
18+
jobs:
19+
coding-standard:
20+
name: Coding standard
21+
runs-on: ubuntu-latest
22+
timeout-minutes: 7
23+
steps:
24+
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7
25+
26+
- name: Setup PHP
27+
uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # v2
28+
with:
29+
php-version: 8.4
30+
coverage: none
31+
32+
- name: Install Composer dependencies
33+
uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0
34+
with:
35+
composer-options: '--no-scripts'
36+
37+
- name: Apply Rector
38+
run: composer rector
39+
40+
- name: Apply Coding Standard
41+
run: composer cs
42+
43+
- name: Commit Fixes (if any)
44+
uses: stefanzweifel/git-auto-commit-action@b863ae1933cb653a53c021fe36dbb774e1fb9403 # v5.2.0
45+
with:
46+
commit_message: 'style: apply coding standard'

‎.github/workflows/format_php.yml‎

Lines changed: 0 additions & 78 deletions
This file was deleted.

‎.github/workflows/php-cs-fixer.yml‎

Lines changed: 0 additions & 48 deletions
This file was deleted.
File renamed without changes.

‎README.md‎

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ Two tools, two roles, meant to run together:
2424
```shell
2525
composer require --dev interaction-design-foundation/coding-standard
2626
```
27+
## Configuration
2728

28-
## PHP-CS-Fixer
29+
### PHP-CS-Fixer
2930

3031
Create `.php-cs-fixer.php` in your project root:
3132

@@ -67,7 +68,7 @@ Run it:
6768
vendor/bin/php-cs-fixer fix
6869
```
6970

70-
## PHP_CodeSniffer
71+
### PHP_CodeSniffer
7172

7273
Create `phpcs.xml` in your project root:
7374

@@ -93,7 +94,7 @@ vendor/bin/phpcbf # fix
9394
vendor/bin/phpcs # check (dry-run)
9495
```
9596

96-
## Composer scripts (recommended)
97+
### Composer scripts (recommended)
9798

9899
Wire both tools into `composer.json` so the whole team runs them the same way:
99100

@@ -116,25 +117,5 @@ composer cs
116117

117118
## Continuous integration
118119

119-
Run the fixer in CI and commit the result back, so the branch is always formatted without blocking the build. Example GitHub Actions workflow (`.github/workflows/coding-standard.yml`):
120-
121-
```yaml
122-
name: Coding standard
123-
124-
on: [push, pull_request]
125-
126-
jobs:
127-
cs:
128-
runs-on: ubuntu-latest
129-
steps:
130-
- uses: actions/checkout@v4
131-
- uses: shivammathur/setup-php@v2
132-
with:
133-
php-version: '8.4'
134-
coverage: none
135-
- run: composer install --no-interaction --no-progress --prefer-dist
136-
- run: composer cs
137-
- uses: stefanzweifel/git-auto-commit-action@b863ae1933cb653a53c021fe36dbb774e1fb9403 # v5.2.0
138-
with:
139-
commit_message: 'style: apply coding standard'
140-
```
120+
Run the fixer in CI and commit the result back, so the branch is always formatted without blocking the build.
121+
This repository dogfoods that pattern; copy its workflow as a starting point: [`.github/workflows/coding-standard.yml`](.github/workflows/coding-standard.yml).

‎composer.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"sort-packages": true
3535
},
3636
"scripts": {
37-
"cs": "@cs:fix",
37+
"cs": ["@php-cs-fixer", "@cs:fix"],
3838
"cs:fix": "phpcbf -p --colors --cache=.cache/phpcs",
3939
"php-cs-fixer": "php-cs-fixer fix --no-interaction",
4040
"rector": "rector",

0 commit comments

Comments
 (0)