add a workflow for tests #1
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Setup environment and execute tests for a Laravel project | ||
on: | ||
workflow_call: | ||
inputs: | ||
PHP_VERSIONS: | ||
description: A comma separated list of PHP versions to be used when executing the tests. | ||
required: true | ||
type: string | ||
LARAVEL_VERSIONS: | ||
description: A comma separated list of Laravel versions to be used when executing the tests. | ||
required: true | ||
type: string | ||
MYSQL_DATABASE: | ||
description: The name of the MySQL database. | ||
required: true | ||
type: string | ||
TEST_COMMANDS: | ||
description: The commands which execute the tests. | ||
required: false | ||
type: string | ||
default: | | ||
php artisan migrate:fresh --env=ci | ||
php artisan test --env=ci --no-coverage | ||
jobs: | ||
execute-tests: | ||
runs-on: ubuntu-latest | ||
services: | ||
mysql: | ||
image: mysql:8.0 | ||
env: | ||
MYSQL_ALLOW_EMPTY_PASSWORD: yes | ||
MYSQL_DATABASE: ${{ inputs.MYSQL_DATABASE }} | ||
ports: | ||
- 3306 | ||
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 | ||
strategy: | ||
fail-fast: true | ||
matrix: | ||
php: [ ${{ inputs.PHP_VERSIONS }} ] | ||
laravel: [ ${{ inputs.LARAVEL_VERSIONS }} ] | ||
dependency-version: [ prefer-stable ] | ||
name: PHP ${{ matrix.php }} with Laravel ${{ matrix.laravel }} (${{ matrix.dependency-version }}) | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: ${{ matrix.php }} | ||
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd | ||
tools: composer:v2 | ||
coverage: none | ||
- name: Get composer cache directory | ||
id: get-cache-dir | ||
run: echo "directory=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | ||
- name: Cache composer dependencies | ||
uses: actions/cache@v4 | ||
with: | ||
path: ${{ steps.get-cache-dir.outputs.directory }} | ||
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} | ||
restore-keys: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer- | ||
- name: Install dependencies | ||
run: | | ||
composer require "laravel/framework:${{ matrix.laravel }}" --no-interaction --no-update --dev --no-progress | ||
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-progress | ||
- name: Execute tests | ||
run: ${{ inputs.TEST_COMMANDS }} | ||
env: | ||
DB_PORT: ${{ job.services.mysql.ports[3306] }} |