From e3b6c061c457922196e87642d7c5431b0b75c91d Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Fri, 12 Aug 2022 08:35:10 +0200 Subject: [PATCH] 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