The issue you're encountering is likely due to differences in the environment between your local machine and the GitHub Actions runner. Here are a few steps to troubleshoot and potentially resolve the issue:
-
Ensure Database Migrations and Seeders are Run: Make sure that your database is properly set up before running the tests. This includes running migrations and possibly seeding the database.
-
Check for Missing Environment Variables: Ensure that all necessary environment variables are set correctly in your GitHub Actions workflow.
-
Session Configuration: Ensure that the session is properly configured and that the session driver is set to
fileor another appropriate driver that works in the GitHub Actions environment. -
Debugging: Add some debugging steps to your GitHub Actions workflow to output the state of the application and the database.
Here is an updated version of your GitHub Actions workflow with additional steps to ensure the database is set up correctly and to add some debugging information:
name: tests
on:
push:
pull_request:
jobs:
tests:
runs-on: ubuntu-24.04
strategy:
fail-fast: true
matrix:
php: ['8.2']
laravel: [11]
name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }}
env:
DB_DATABASE: laravel
DB_USERNAME: root
DB_PASSWORD: password
NOVA_USERNAME: ${{ secrets.NOVA_USERNAME }}
NOVA_LICENSE_KEY: ${{ secrets.NOVA_LICENSE_KEY }}
services:
mysql:
image: mysql:latest
env:
MYSQL_ALLOW_EMPTY_PASSWORD: false
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: laravel
ports:
- 3306/tcp
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, bcmath
ini-values: error_reporting=E_ALL
tools: composer:v2
coverage: none
- name: Install dependencies
run: |
composer require "illuminate/contracts=^${{ matrix.laravel }}" --no-update
composer update --prefer-dist --no-interaction --no-progress
- name: Prepare Laravel Application
run: |
cp .env.ci .env
php artisan key:generate
php artisan migrate --force
php artisan db:seed --force
- name: Debugging: List database tables
run: |
mysql -u root -ppassword -e 'SHOW TABLES;' laravel
- name: Execute tests
run: vendor/bin/pest
env:
DB_PORT: ${{ job.services.mysql.ports['3306'] }}
Explanation:
-
Database Migrations and Seeders:
- Added
php artisan migrate --forceandphp artisan db:seed --forceto ensure the database is properly set up before running the tests.
- Added
-
Debugging:
- Added a step to list the database tables to ensure the database is correctly set up and accessible.
Additional Tips:
-
Session Configuration: Ensure that your
config/session.phpis properly configured for the GitHub Actions environment. You might want to set the session driver tofilefor simplicity. -
Environment Variables: Double-check that all necessary environment variables are set correctly in your
.env.cifile.
By following these steps, you should be able to identify and resolve the issue causing the test to fail in the GitHub Actions environment.