Streamlining the development process is crucial for any project, especially when dealing with the complexities of web applications. Manual testing quickly becomes a bottleneck as features proliferate. This is where Continuous Integration (CI) and Continuous Deployment (CD) shine, automating testing and deployment, saving developers valuable time and reducing the risk of errors. This article provides a comprehensive guide to setting up a robust CI/CD pipeline for your Laravel projects using GitHub Actions. We'll walk you through the entire process, from creating a new Laravel project to monitoring test results directly within your GitHub repository.
composer create-project --prefer-dist laravel/laravel my-laravel-project
cd my-laravel-project
git init
git add .
git commit -m "Initial commit"
git remote add origin <your_github_repository_url>
git push -u origin main
name: Laravel Test Workflow
on:
push:
branches:
- main #Specify the branch to trigger the workflow
jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '8.1' # Use a supported PHP version
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv
coverage: none
- name: Install dependencies
run: composer install --no-interaction --no-progress --optimize-autoloader
- name: Generate application key
run: php artisan key:generate --show
- name: Copy environment file
run: cp .env.example .env
- name: Database migrations
run: php artisan migrate --database=testing
- name: Run tests
run: php artisan test --testdox
- name: Upload test results (optional)
uses: actions/upload-artifact@v3
with:
name: test-results
path: tests/
name : This line simply names the workflow.on: push : This triggers the workflow whenever code is pushed to the specified branch (main in this case). You can customize this to trigger on other events like pull requests.jobs: test : This defines a job named "test" that will run the testing steps.runs-on: ubuntu-latest : This specifies that the job will run on a Ubuntu virtual machine.steps : This section defines the individual steps within the job. Each step can be a shell command or a reusable action. The steps above cover checking out the code, setting up PHP, installing dependencies, generating an application key, running database migrations (if any), and running the tests using the php artisan test command. The --testdox flag provides a more readable output of the test results. The optional artifact upload step allows you to archive test results for later review.
git add .github/workflows/laravel-test.yml
git commit -m "Added GitHub Actions workflow"
git push origin main
0 comments:
Post a Comment