← Back to engineering
#refactoring

Automating code style with Laravel Pint and GitHub Actions

By Krodox Team 3 min read

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]
jobs:
  phplint:
    name: Laravel Pint
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v7
      - name: Laravel Pint
        uses: aglipanci/laravel-pint-action@2.6
        with:
          configPath: "pint.json"
          pintVersion: 1.32.1

We trigger on push rather than pull_request for simplicity: on a push the checkout is the branch itself, so the action can commit back to it. A pull_request run checks out a merge commit instead, and you would need ref: ${{ github.head_ref }} on the checkout step to push anything back. The permissions: contents: write line is what allows the job's token to push that commit.

The pint.json in the project root is the single source of configuration, which is why we do not pass a preset input: the rules stay identical whether Pint runs locally or in CI.

Committing the fixes automatically

On its own the workflow above is not enough. Without testMode, Pint does fix the files, but only in the runner's copy of the repository, and those changes are discarded when the job ends. 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]
jobs:
  phplint:
    name: Laravel Pint
    runs-on: ubuntu-latest
    permissions:
      contents: write
    steps:
      - uses: actions/checkout@v7
      - name: Laravel Pint
        uses: aglipanci/laravel-pint-action@2.6
        with:
          configPath: "pint.json"
          pintVersion: 1.32.1

      - 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.

Related reading

We use cookies to enhance your experience and keep your data secure. Privacy Policy