Continuous integration
Fail the build on unformatted code, with annotations on GitHub Actions and Code Quality reports on GitLab.
Run --check in CI. It fails the build on unformatted code.
vendor/bin/laravel-fmt --checkTo check only what a branch changed, add --since:
vendor/bin/laravel-fmt --check --since origin/main--since needs the full git history. On GitHub Actions, set fetch-depth: 0 on actions/checkout.
GitHub Actions
name: format
on:
pull_request:
push:
branches: [main]
jobs:
laravel-fmt:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: shivammathur/setup-php@v2
with:
php-version: '8.4'
- uses: ramsey/composer-install@v4
- run: vendor/bin/laravel-fmt --checkOn GitHub Actions, each unformatted file and each parse error gets an annotation. The job summary lists every unformatted file and every failure.
GitLab CI
image: php:8.4-cli
laravel-fmt:
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
cache:
key:
files:
- composer.lock
paths:
- vendor/
before_script:
- apt-get update && apt-get install -y git unzip
- curl -sS https://getcomposer.org/download/latest-stable/composer.phar -o /usr/local/bin/composer
- chmod +x /usr/local/bin/composer
script:
- composer install --no-interaction --no-progress
- vendor/bin/laravel-fmt --check --reporter gitlab > gl-code-quality-report.json
artifacts:
when: always
reports:
codequality: gl-code-quality-report.jsonOn GitLab, each unformatted file and each parse error shows up in the merge request’s Code Quality report.
Windows runners
With core.autocrlf on, Git checks files out with CRLF and every file looks unformatted. Add this to
.gitattributes:
* text=auto eol=lfIf your project uses CRLF, set "endOfLine": "crlf" in laravel-fmt.json instead.
Showing the changes
--diff prints the changes instead of file names. Use --check on GitHub Actions for annotations.
vendor/bin/laravel-fmt --diff