From e3b6c061c457922196e87642d7c5431b0b75c91d Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 12 Aug 2022 08:35:10 +0200 Subject: [PATCH 1/4] Extracted definition of unit tests job to local reusable workflow --- .github/workflows/ci.yml | 55 +++++++++++++--------------------- .github/workflows/ci/tests.yml | 43 ++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 35 deletions(-) create mode 100644 .github/workflows/ci/tests.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c37524ab..f7d37f89 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,39 +29,20 @@ jobs: run: composer install --no-interaction --prefer-dist - run: composer ${{ matrix.command }} - tests: - runs-on: ubuntu-22.04 - strategy: - matrix: - php-version: ['8.1'] - test-group: ['unit', 'api', 'cli'] - steps: - - name: Checkout code - uses: actions/checkout@v2 - - name: Start postgres database server - if: ${{ matrix.test-group == 'api' }} - run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db_postgres - - name: Start maria database server - if: ${{ matrix.test-group == 'cli' }} - run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db_maria - - name: Use PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-version }} - tools: composer - extensions: openswoole-4.11.1 - coverage: pcov - ini-values: pcov.directory=module - - name: Install dependencies - run: composer install --no-interaction --prefer-dist - - run: composer test:${{ matrix.test-group }}:ci - - uses: actions/upload-artifact@v2 - if: ${{ matrix.php-version == '8.1' }} - with: - name: coverage-${{ matrix.test-group }} - path: | - build/coverage-${{ matrix.test-group }} - build/coverage-${{ matrix.test-group }}.cov + unit-tests: + uses: './.github/workflows/ci/tests.yml' + with: + test-group: unit + + api-tests: + uses: './.github/workflows/ci/tests.yml' + with: + test-group: api + + cli-tests: + uses: './.github/workflows/ci/tests.yml' + with: + test-group: cli db-tests: runs-on: ubuntu-22.04 @@ -106,7 +87,9 @@ jobs: mutation-tests: needs: - - tests + - unit-tests + - api-tests + - cli-tests - db-tests runs-on: ubuntu-22.04 strategy: @@ -138,7 +121,9 @@ jobs: upload-coverage: needs: - - tests + - unit-tests + - api-tests + - cli-tests - db-tests runs-on: ubuntu-22.04 strategy: diff --git a/.github/workflows/ci/tests.yml b/.github/workflows/ci/tests.yml new file mode 100644 index 00000000..1d2f5063 --- /dev/null +++ b/.github/workflows/ci/tests.yml @@ -0,0 +1,43 @@ +name: Tests + +on: + workflow_call: + inputs: + test-group: + type: string + required: true + description: One of unit, api or cli + +jobs: + tests: + runs-on: ubuntu-22.04 + strategy: + matrix: + php-version: ['8.1'] + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Start postgres database server + if: ${{ inputs.test-group == 'api' }} + run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db_postgres + - name: Start maria database server + if: ${{ inputs.test-group == 'cli' }} + run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db_maria + - name: Use PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + tools: composer + extensions: openswoole-4.11.1 + coverage: pcov + ini-values: pcov.directory=module + - name: Install dependencies + run: composer install --no-interaction --prefer-dist + - run: composer test:${{ inputs.test-group }}:ci + - uses: actions/upload-artifact@v2 + if: ${{ matrix.php-version == '8.1' }} + with: + name: coverage-${{ inputs.test-group }} + path: | + build/coverage-${{ inputs.test-group }} + build/coverage-${{ inputs.test-group }}.cov From 51536f8746178ffebc686db7ebc0dd891b370e70 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 12 Aug 2022 09:13:04 +0200 Subject: [PATCH 2/4] Moved reusable ci tests workflow to workflows folder --- .github/workflows/{ci/tests.yml => ci-tests.yml} | 0 .github/workflows/ci.yml | 6 +++--- 2 files changed, 3 insertions(+), 3 deletions(-) rename .github/workflows/{ci/tests.yml => ci-tests.yml} (100%) diff --git a/.github/workflows/ci/tests.yml b/.github/workflows/ci-tests.yml similarity index 100% rename from .github/workflows/ci/tests.yml rename to .github/workflows/ci-tests.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f7d37f89..6117d856 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,17 +30,17 @@ jobs: - run: composer ${{ matrix.command }} unit-tests: - uses: './.github/workflows/ci/tests.yml' + uses: './.github/workflows/ci-tests.yml' with: test-group: unit api-tests: - uses: './.github/workflows/ci/tests.yml' + uses: './.github/workflows/ci-tests.yml' with: test-group: api cli-tests: - uses: './.github/workflows/ci/tests.yml' + uses: './.github/workflows/ci-tests.yml' with: test-group: cli From 63832306789d4021e7ab5b16046bedc9613bdc3a Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 12 Aug 2022 09:30:52 +0200 Subject: [PATCH 3/4] Extracted DB tests and mutation tests to reusable workflows --- .github/workflows/ci-db-tests.yml | 50 ++++++++++ .github/workflows/ci-mutation-tests.yml | 38 ++++++++ .github/workflows/ci.yml | 123 ++++++++++-------------- 3 files changed, 140 insertions(+), 71 deletions(-) create mode 100644 .github/workflows/ci-db-tests.yml create mode 100644 .github/workflows/ci-mutation-tests.yml diff --git a/.github/workflows/ci-db-tests.yml b/.github/workflows/ci-db-tests.yml new file mode 100644 index 00000000..545e0e53 --- /dev/null +++ b/.github/workflows/ci-db-tests.yml @@ -0,0 +1,50 @@ +name: Database tests + +on: + workflow_call: + inputs: + platform: + type: string + required: true + description: One of sqlite:ci, mysql, maria, postgres or ms + +jobs: + db-tests: + runs-on: ubuntu-22.04 + strategy: + matrix: + php-version: [ '8.1' ] + env: + LC_ALL: C + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Install MSSQL ODBC + if: ${{ inputs.platform == 'ms' }} + run: sudo ./data/infra/ci/install-ms-odbc.sh + - name: Start database server + if: ${{ inputs.platform != 'sqlite:ci' }} + run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db_${{ inputs.platform }} + - name: Use PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + tools: composer + extensions: openswoole-4.11.1, pdo_sqlsrv-5.10.1 + coverage: pcov + ini-values: pcov.directory=module + - name: Install dependencies + run: composer install --no-interaction --prefer-dist + - name: Create test database + if: ${{ inputs.platform == 'ms' }} + run: docker-compose exec -T shlink_db_ms /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'Passw0rd!' -Q "CREATE DATABASE shlink_test;" + - name: Run tests + run: composer test:db:${{ inputs.platform }} + - name: Upload code coverage + uses: actions/upload-artifact@v2 + if: ${{ matrix.php-version == '8.1' && inputs.platform == 'sqlite:ci' }} + with: + name: coverage-db + path: | + build/coverage-db + build/coverage-db.cov diff --git a/.github/workflows/ci-mutation-tests.yml b/.github/workflows/ci-mutation-tests.yml new file mode 100644 index 00000000..4ed47af4 --- /dev/null +++ b/.github/workflows/ci-mutation-tests.yml @@ -0,0 +1,38 @@ +name: Mutation tests + +on: + workflow_call: + inputs: + test-group: + type: string + required: true + description: One of unit, db, api or cli + +jobs: + mutation-tests: + runs-on: ubuntu-22.04 + strategy: + matrix: + php-version: [ '8.1' ] + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Use PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + tools: composer + extensions: openswoole-4.11.1 + coverage: pcov + ini-values: pcov.directory=module + - name: Install dependencies + run: composer install --no-interaction --prefer-dist + - uses: actions/download-artifact@v2 + with: + path: build + - if: ${{ inputs.test-group == 'unit' }} + run: composer infect:ci:unit + env: + INFECTION_BADGE_API_KEY: ${{ secrets.INFECTION_BADGE_API_KEY }} + - if: ${{ inputs.test-group != 'unit' }} + run: composer infect:ci:${{ inputs.test-group }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6117d856..65fb6254 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,87 +44,65 @@ jobs: with: test-group: cli - db-tests: - runs-on: ubuntu-22.04 - strategy: - matrix: - php-version: ['8.1'] - platform: ['sqlite:ci', 'mysql', 'maria', 'postgres', 'ms'] - env: - LC_ALL: C - steps: - - name: Checkout code - uses: actions/checkout@v2 - - name: Install MSSQL ODBC - if: ${{ matrix.platform == 'ms' }} - run: sudo ./data/infra/ci/install-ms-odbc.sh - - name: Start database server - if: ${{ matrix.platform != 'sqlite:ci' }} - run: docker-compose -f docker-compose.yml -f docker-compose.ci.yml up -d shlink_db_${{ matrix.platform }} - - name: Use PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-version }} - tools: composer - extensions: openswoole-4.11.1, pdo_sqlsrv-5.10.1 - coverage: pcov - ini-values: pcov.directory=module - - name: Install dependencies - run: composer install --no-interaction --prefer-dist - - name: Create test database - if: ${{ matrix.platform == 'ms' }} - run: docker-compose exec -T shlink_db_ms /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P 'Passw0rd!' -Q "CREATE DATABASE shlink_test;" - - name: Run tests - run: composer test:db:${{ matrix.platform }} - - name: Upload code coverage - uses: actions/upload-artifact@v2 - if: ${{ matrix.php-version == '8.1' && matrix.platform == 'sqlite:ci' }} - with: - name: coverage-db - path: | - build/coverage-db - build/coverage-db.cov + sqlite-db-tests: + uses: './.github/workflows/ci-db-tests.yml' + with: + platform: 'sqlite:ci' - mutation-tests: + mysql-db-tests: + uses: './.github/workflows/ci-db-tests.yml' + with: + platform: 'mysql' + + maria-db-tests: + uses: './.github/workflows/ci-db-tests.yml' + with: + platform: 'maria' + + postgres-db-tests: + uses: './.github/workflows/ci-db-tests.yml' + with: + platform: 'postgres' + + ms-db-tests: + uses: './.github/workflows/ci-db-tests.yml' + with: + platform: 'ms' + + unit-mutation-tests: needs: - unit-tests + uses: './github/workflows/ci-mutation-tests.yml' + with: + test-group: unit + + db-mutation-tests: + needs: + - sqlite-db-tests + uses: './github/workflows/ci-mutation-tests.yml' + with: + test-group: db + + api-mutation-tests: + needs: - api-tests + uses: './github/workflows/ci-mutation-tests.yml' + with: + test-group: api + + cli-mutation-tests: + needs: - cli-tests - - db-tests - runs-on: ubuntu-22.04 - strategy: - matrix: - php-version: ['8.1'] - test-group: ['unit', 'db', 'api', 'cli'] - steps: - - name: Checkout code - uses: actions/checkout@v2 - - name: Use PHP - uses: shivammathur/setup-php@v2 - with: - php-version: ${{ matrix.php-version }} - tools: composer - extensions: openswoole-4.11.1 - coverage: pcov - ini-values: pcov.directory=module - - name: Install dependencies - run: composer install --no-interaction --prefer-dist - - uses: actions/download-artifact@v2 - with: - path: build - - if: ${{ matrix.test-group == 'unit' }} - run: composer infect:ci:unit - env: - INFECTION_BADGE_API_KEY: ${{ secrets.INFECTION_BADGE_API_KEY }} - - if: ${{ matrix.test-group != 'unit' }} - run: composer infect:ci:${{ matrix.test-group }} + uses: './github/workflows/ci-mutation-tests.yml' + with: + test-group: cli upload-coverage: needs: - unit-tests - api-tests - cli-tests - - db-tests + - sqlite-db-tests runs-on: ubuntu-22.04 strategy: matrix: @@ -154,7 +132,10 @@ jobs: delete-artifacts: needs: - - mutation-tests + - unit-mutation-tests + - db-mutation-tests + - api-mutation-tests + - cli-mutation-tests - upload-coverage runs-on: ubuntu-22.04 steps: From 0f796859f224526539dc1d2a235be0a64f679b89 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 12 Aug 2022 09:32:30 +0200 Subject: [PATCH 4/4] Fixed typo in ci workflow --- .github/workflows/ci.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 65fb6254..f3ed416f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -72,28 +72,28 @@ jobs: unit-mutation-tests: needs: - unit-tests - uses: './github/workflows/ci-mutation-tests.yml' + uses: './.github/workflows/ci-mutation-tests.yml' with: test-group: unit db-mutation-tests: needs: - sqlite-db-tests - uses: './github/workflows/ci-mutation-tests.yml' + uses: './.github/workflows/ci-mutation-tests.yml' with: test-group: db api-mutation-tests: needs: - api-tests - uses: './github/workflows/ci-mutation-tests.yml' + uses: './.github/workflows/ci-mutation-tests.yml' with: test-group: api cli-mutation-tests: needs: - cli-tests - uses: './github/workflows/ci-mutation-tests.yml' + uses: './.github/workflows/ci-mutation-tests.yml' with: test-group: cli