From 19470dc7cde0bed982345937aefad7ee8a26a416 Mon Sep 17 00:00:00 2001 From: Marco Szulik Date: Wed, 18 Dec 2024 08:47:27 +0100 Subject: [PATCH] refactor test workflow --- .github/workflows/tests-matrix.yml | 55 ++++++++++++++ .github/workflows/tests.yml | 72 +++++-------------- phpunit-ci-postgres.xml.dist | 26 ------- ...t-ci-mysql.xml.dist => phpunit-ci.xml.dist | 5 -- 4 files changed, 72 insertions(+), 86 deletions(-) create mode 100644 .github/workflows/tests-matrix.yml delete mode 100644 phpunit-ci-postgres.xml.dist rename phpunit-ci-mysql.xml.dist => phpunit-ci.xml.dist (84%) diff --git a/.github/workflows/tests-matrix.yml b/.github/workflows/tests-matrix.yml new file mode 100644 index 0000000..c9a1808 --- /dev/null +++ b/.github/workflows/tests-matrix.yml @@ -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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 411aa40..7c8d80d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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" diff --git a/phpunit-ci-postgres.xml.dist b/phpunit-ci-postgres.xml.dist deleted file mode 100644 index 47c7fd7..0000000 --- a/phpunit-ci-postgres.xml.dist +++ /dev/null @@ -1,26 +0,0 @@ - - - - - tests/feature - - - - - - - - - - - - - - - - - - ./src - - - diff --git a/phpunit-ci-mysql.xml.dist b/phpunit-ci.xml.dist similarity index 84% rename from phpunit-ci-mysql.xml.dist rename to phpunit-ci.xml.dist index 7855862..9de07ac 100644 --- a/phpunit-ci-mysql.xml.dist +++ b/phpunit-ci.xml.dist @@ -11,11 +11,6 @@ - - - - -