Skip to content

Commit

Permalink
refactor test workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mszulik committed Dec 18, 2024
1 parent 4dc54ee commit 19470dc
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 86 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/tests-matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
on:
workflow_call:
inputs:
DATABASE_IMAGE:
description: The Docker image to use for the database.
required: true
type: string
DATABASE_PORT:
description: The port of the database.
required: true
type: string
DATABASE_CONNECTION:
description: The database connection to use.
required: true
type: string
DATABASE_HOST:
description: The host of the database.
required: false
type: string
default: 127.0.0.1
DATABASE_USERNAME:
description: The username to use for the database.
required: true
type: string
DATABASE_OPTIONS:
description: The options to use for the database, such as health check.
required: true
type: string

jobs:
execute-test-matrix:
strategy:
fail-fast: true
matrix:
php: [ 8.1, 8.2, 8.3 ]
laravel: [ 9.*, 10.*, 11.* ]
dependency-version: [ prefer-stable ]
exclude:
- php: 8.3
laravel: 9.*
- php: 8.1
laravel: 11.*
uses: cybex-gmbh/github-workflows/.github/workflows/tests.yml@feature/pass-db-image
with:
DATABASE_IMAGE: ${{ inputs.DATABASE_IMAGE }}
DATABASE_NAME: protector_test
DATABASE_HOST: ${{ inputs.DATABASE_HOST }}
DATABASE_PORT: ${{ inputs.DATABASE_PORT }}
DATABASE_CONNECTION: ${{ inputs.DATABASE_CONNECTION }}
DATABASE_USERNAME: ${{ inputs.DATABASE_USERNAME }}
DATABASE_OPTIONS: ${{ inputs.DATABASE_OPTIONS }}
PHP_VERSION: ${{ matrix.php }}
LARAVEL_VERSION: ${{ matrix.laravel }}
DEPENDENCY_VERSION: ${{ matrix.dependency-version }}
TEST_COMMANDS: vendor/bin/phpunit -c phpunit-ci.xml.dist
72 changes: 17 additions & 55 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,61 +8,23 @@ on:
pull_request:
workflow_dispatch:

env:
MYSQL_IMAGE: mysql:8.0
MYSQL_PORT: 3306
MYSQL_DB_OPTIONS: "--health-cmd=\"mysqladmin ping\" --health-interval=10s --health-timeout=5s --health-retries=3"
MYSQL_PHPUNIT_CONFIG: "phpunit-ci-mysql.xml.dist"
POSTGRES_IMAGE: postgres:17
POSTGRES_PORT: 5432
POSTGRES_DB_OPTIONS: "--health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3"
POSTGRES_PHPUNIT_CONFIG: "phpunit-ci-postgres.xml.dist"

jobs:
# Environment variables are not available in the matrix context, so we have to define them as outputs.
prepare:
name: Prepare environment
runs-on: ubuntu-latest
outputs:
MYSQL_IMAGE: ${{ env.MYSQL_IMAGE }}
MYSQL_PORT: ${{ env.MYSQL_PORT }}
MYSQL_DB_OPTIONS: ${{ env.MYSQL_DB_OPTIONS }}
MYSQL_PHPUNIT_CONFIG: ${{ env.MYSQL_PHPUNIT_CONFIG }}
POSTGRES_IMAGE: ${{ env.POSTGRES_IMAGE }}
POSTGRES_PORT: ${{ env.POSTGRES_PORT }}
POSTGRES_DB_OPTIONS: ${{ env.POSTGRES_DB_OPTIONS }}
POSTGRES_PHPUNIT_CONFIG: ${{ env.POSTGRES_PHPUNIT_CONFIG }}
steps:
# Placeholder because a job needs a step.
- run: echo "null"

mysql-tests:
name: Setup testing environment and execute tests
needs: prepare
uses: cybex-gmbh/github-workflows/.github/workflows/tests.yml@feature/pass-db-image
strategy:
fail-fast: true
matrix:
db-image: [ "${{ needs.prepare.outputs.MYSQL_IMAGE }}", "${{ needs.prepare.outputs.POSTGRES_IMAGE }}" ]
db-options: [ "${{ needs.prepare.outputs.MYSQL_DB_OPTIONS }}", "${{ needs.prepare.outputs.POSTGRES_DB_OPTIONS }}" ]
php: [ 8.1, 8.2, 8.3 ]
laravel: [ 9.*, 10.*, 11.* ]
dependency-version: [ prefer-stable ]
exclude:
- php: 8.3
laravel: 9.*
- php: 8.1
laravel: 11.*
- db-image: "${{ needs.prepare.outputs.MYSQL_IMAGE }}"
db-options: "${{ needs.prepare.outputs.POSTGRES_DB_OPTIONS }}"
- db-image: "${{ needs.prepare.outputs.POSTGRES_IMAGE }}"
db-options: "${{ needs.prepare.outputs.MYSQL_DB_OPTIONS }}"
name: MySQL
uses: ./.github/workflows/tests-matrix.yml
with:
DATABASE_IMAGE: mysql:8.0
DATABASE_PORT: 3306
DATABASE_USERNAME: root
DATABASE_CONNECTION: mysql
DATABASE_OPTIONS: "--health-cmd=\"mysqladmin ping\" --health-interval=10s --health-timeout=5s --health-retries=3"

postgres-tests:
name: PostgreSQL
uses: ./.github/workflows/tests-matrix.yml
with:
DATABASE_IMAGE: ${{ matrix.db-image }}
DATABASE_NAME: protector_test
DATABASE_PORT: ${{ matrix.db-image == needs.prepare.outputs.MYSQL_IMAGE && needs.prepare.outputs.MYSQL_PORT || needs.prepare.outputs.POSTGRES_PORT }}
DATABASE_OPTIONS: ${{ matrix.db-options }}
PHP_VERSION: ${{ matrix.php }}
LARAVEL_VERSION: ${{ matrix.laravel }}
DEPENDENCY_VERSION: ${{ matrix.dependency-version }}
TEST_COMMANDS: vendor/bin/phpunit -c ${{ matrix.db-image == needs.prepare.outputs.MYSQL_IMAGE && needs.prepare.outputs.MYSQL_PHPUNIT_CONFIG || needs.prepare.outputs.POSTGRES_PHPUNIT_CONFIG }}
DATABASE_IMAGE: postgres:17
DATABASE_PORT: 5432
DATABASE_USERNAME: postgres
DATABASE_CONNECTION: pgsql
DATABASE_OPTIONS: "--health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 3"
26 changes: 0 additions & 26 deletions phpunit-ci-postgres.xml.dist

This file was deleted.

5 changes: 0 additions & 5 deletions phpunit-ci-mysql.xml.dist → phpunit-ci.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
<env name="PROTECTOR_ENCRYPTED_MESSAGE" value="c93e1c30857b0a5a36dddd11237ff65ef153144e0c400304cc80501da7e9b41a99c568fb34491629577ba4b5c0ec632e50067d61cf1ece27e1eabc"/>
<env name="PROTECTOR_DECRYPTED_MESSAGE" value="hello world"/>
<env name="PROTECTOR_AUTH_TOKEN" value="1|bxa5BBNo7lXxgtRY4DN775JdAtQSAlN4UfgRnFhz"/>
<env name="DB_CONNECTION" value="mysql"/>
<env name="DB_HOST" value="127.0.0.1"/>
<env name="DB_DATABASE" value="protector_test"/>
<env name="DB_USERNAME" value="root"/>
<env name="DB_PASSWORD" value=""/>
<env name="APP_URL" value="http://protector.invalid"/>
</php>
<source>
Expand Down

0 comments on commit 19470dc

Please sign in to comment.