Continuous Integration (CI) Boilerplate for Laravel with GitHub Actions
A boilerplate for setting up Continuous Integration (CI) for Laravel applications using GitHub Actions. This setup includes automated steps for code linting, quality checks, dependency installation, database configuration, and running tests to ensure code quality and stability before integration.
Continuous Integration (CI) is crucial for modern software development. It automates the process of testing and validating code changes to ensure they integrate smoothly with the existing codebase. By implementing CI, you can catch issues early, reduce manual testing efforts, and maintain a high standard of code quality. This leads to more reliable and maintainable code, faster development cycles, and fewer bugs in production.
The core of this CI boilerplate is the file. Here’s what you’ll find in this file:.github/workflows/laravel.yml
Main File: .github/workflows/laravel.yml
This boilerplate includes a GitHub Actions configuration file designed to guide you through setting up CI for Laravel. Here's a detailed breakdown of its key parts:
1. Branch Configuration:
branches: ["master"]
This section specifies that the workflow will run on pushes and pull requests to the master branch. You can customize this to include other branches if needed.
2. PHP Versions
php-version: ["8.1", "8.2"]
This sets up the CI pipeline to test your code against PHP versions 8.1 and 8.2, ensuring compatibility with these versions.
3. MySQL Docker Image
image: mysql:8.0
This specifies the MySQL version (8.0) used for database operations during testing. It ensures that your tests run in an environment that mimics production.
4. PHP Setup
extensions: mbstring, mysqli, pdo_mysql
tools: laravel/pint, overtrue/phplint
Installs essential PHP extensions like needed for Laravel to function properly.mbstring, mysqli, and pdo_mysql
Performs code style checks to ensure your code follows consistent standards.Laravel Pint:
Lints PHP code to detect potential issues and improve code quality.Overtrue PHPLint:
5. PHP Linting
phplint --exclude=*.log --exclude='*.txt' .
Runs PHP linting across your codebase, excluding certain file types like logs and text files. This helps catch syntax errors and potential issues in your PHP code.
6. Install Dependencies
composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
Installs all PHP dependencies listed in your composer.json file. This ensures that all required packages are available for your application.
7. Run Migrations
php artisan migrate --database=mysql
Runs Laravel migrations on the MySQL database to set up the required schema. This step is crucial for ensuring that your tests run against the correct database structure.
Fresh Project Setup
This boilerplate is built for Laravel 11 and is ideal for starting a fresh project. Whether you’re setting up a new Laravel application or integrating it into an existing project, this CI configuration provides a solid foundation for maintaining code quality and reliability.
More Details
To get started with your own project, check out the GitHub repository. There, you’ll find additional documentation and instructions to help you setup to project specific needs.