Skip to main content

๐Ÿค– CI/CD Integration

Laravel Migration Linter integrates seamlessly with GitHub Actions, GitLab CI, and other continuous integration pipelines.
It ensures no unsafe schema changes reach production by failing builds when risky migrations are detected.


๐Ÿงฐ GitHub Actions Exampleโ€‹

name: Laravel Migration Linter

on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]

jobs:
lint-migrations:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: 8.3
extensions: mbstring, pdo, bcmath, curl, dom, xml
tools: composer:v2

# ๐Ÿงฉ Example: setting up a test Laravel project using your local package
- run: composer create-project laravel/laravel test-laravel-app --quiet

- name: Install Laravel Migration Linter (local path)
run: |
cd test-laravel-app
composer config repositories.sufyandev path ../
composer require sufyandev/laravel-migration-linter:@dev --no-interaction

- name: Run Migration Linter
run: |
cd test-laravel-app
php artisan migrate:lint --json > lint-report.json


๐Ÿงช Example in CI Consoleโ€‹

๐Ÿ” Running Laravel Migration Linter...

โš ๏ธ Lint Report
+-------------------------------------+-------------------------------------------+-----------+----------+----------------------------------------------------------+
| File | Rule | Column | Severity | Message |
+-------------------------------------+-------------------------------------------+-----------+----------+----------------------------------------------------------+
| 0001_01_01_000000_create_users.php | AddNonNullableColumnWithoutDefault | email | warning | Adding NOT NULL column without default value. |
| 2025_10_15_000000_create_orders.php | FloatColumnForMoney | price | warning | Using float() for price โ€” use decimal(10,2) instead. |
+-------------------------------------+-------------------------------------------+-----------+----------+----------------------------------------------------------+

[Suggestion #1] AddNonNullableColumnWithoutDefault:
Option 1: Add a default value to the column (e.g., ->default('value'))
Option 2: Make it nullable with ->nullable(), backfill existing rows, then alter
๐Ÿ“– Learn more: https://docs.example.com/rules#AddNonNullableColumnWithoutDefault

[Suggestion #2] FloatColumnForMoney:
Use decimal(10,2) or decimal(19,4) for precise monetary calculations
๐Ÿ“– Learn more: https://docs.example.com/rules#FloatColumnForMoney

๐Ÿ“Š Exit Codes and Build Behaviorโ€‹

Severity ThresholdDescriptionExit CodeBuild Result
infoAdvisory messages only0โœ… Pass
warningPotential issues found, not fatal0โœ… Pass
errorMigration-breaking or data-loss risks1โŒ Fail

You can adjust this threshold via config/migration-linter.php:

'severity_threshold' => 'error',

When set to 'error', only error-level issues cause your CI pipeline to fail.


๐Ÿง  Tips for CI/CD Integrationโ€‹

  • ๐Ÿ’พ Commit the baseline file (migration-linter-baseline.json) once generated.
  • This prevents known legacy issues from reappearing in reports.
  • ๐Ÿงฉ Use --json output to generate structured reports for custom dashboards.
  • You can also upload the JSON artifact for analysis.
  • ๏ฟฝ Suggestions are included in both CLI and JSON output โ€” use them to guide developers on fixes.
  • ๏ฟฝ๐Ÿšฆ Fail fast: set 'severity_threshold' => 'error' in config to stop deployments on risky migrations.
  • ๐Ÿ” Run on every PR โ€” this ensures every migration is linted before merge.

๐Ÿงพ GitLab CI Exampleโ€‹

If you're using GitLab, add a stage like this:

stages:
- lint

lint_migrations:
stage: lint
image: php:8.3
script:
- apt-get update && apt-get install -y unzip git
- curl -sS https://getcomposer.org/installer | php
- php composer.phar install --no-interaction
- php artisan migrate:lint --json > lint-report.json

โœ… Result: Your CI/CD pipeline now automatically enforces safe, production-ready migrations โ€” blocking schema-breaking changes before they reach your main branch.