Automating code style with Laravel Pint and GitHub Actions
Code style should never be something a reviewer has to raise. Relying on each developer to remember to run PHP CS Fixer or Laravel Pint before pushing guarantees it will eventually be forgotten, and the diff noise lands in code review instead of the pipeline.
We recommend moving it into CI entirely: run Pint on every push, and let it commit its own corrections back to the branch.
Running Pint on every push
Add a .github/workflows/pint.yml to the repository. We use aglipanci/laravel-pint-action, which has proved reliable across the projects we maintain.
name: Check & fix styling
on: [push, pull_request]
jobs:
phplint:
name: Laravel Pint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 2
- name: Laravel Pint
uses: aglipanci/laravel-pint-action@2.6
with:
preset: laravel
configPath: "pint.json"
pintVersion: 1.29.3
The pint.json in the project root drives the configuration, so the rules stay identical whether Pint runs locally or in CI.
Committing the fixes automatically
On its own the workflow above only reports formatting problems — it still leaves someone to apply them. The step that makes this genuinely hands-off is git-auto-commit, which pushes the corrections back to the branch as their own commit.
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v7
with:
commit_message: Fixing styling
skip_fetch: true
Because the fixes arrive as a separate commit, the styling changes stay reviewable as a diff of their own rather than being mixed into feature work.
The complete workflow
name: Check & fix styling
on: [push, pull_request]
jobs:
phplint:
name: Laravel Pint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 2
- name: Laravel Pint
uses: aglipanci/laravel-pint-action@2.6
with:
preset: laravel
configPath: "pint.json"
pintVersion: 1.29.3
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v7
with:
commit_message: Fixing styling
skip_fetch: true
With this in place, every branch converges on the same Pint rules without anyone having to think about it, and code review is free to focus on behaviour instead of whitespace.