Skip to content

Commit

Permalink
CI: optimize unit-test.
Browse files Browse the repository at this point in the history
  • Loading branch information
zerai committed Feb 22, 2025
1 parent cce5200 commit 4e7a54b
Showing 1 changed file with 127 additions and 0 deletions.
127 changes: 127 additions & 0 deletions .github/workflows/commit-stage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,133 @@ env:
PHP_EXTENSIONS_CACHE_KEY: cache-php-extensions-v1

jobs:
unit-test-optimized:
name: Unit tests (php-${{ matrix.php }} - ${{ matrix.dependencies }})
runs-on: ubuntu-22.04
timeout-minutes: 10
continue-on-error: ${{ matrix.is-php-experimental }}
strategy:
max-parallel: 5
matrix:
php:
- '7.3'
- '7.4'
- '8.0'
- '8.1'
- '8.2'
- '8.3'
dependencies:
- "lowest"
- "highest"
is-php-experimental: [false]
generate-coverage-report: [false]
include:
- php: '7.4'
is-php-experimental: false
generate-coverage-report: false
- php: '8.0'
is-php-experimental: false
generate-coverage-report: false
- php: '8.1'
is-php-experimental: false
generate-coverage-report: false
- php: '8.2'
is-php-experimental: false
generate-coverage-report: false
- php: '8.3'
is-php-experimental: false
generate-coverage-report: false
fail-fast: false
steps:
- name: Checkout on SHA-${{ inputs.triggering-sha }}
uses: actions/checkout@v4
with:
ref: ${{ inputs.triggering-sha }}

- name: Setup php extension cache environment
if: ${{ vars.USE_PHP_EXTENSION_CACHE }}
id: cache-php-extensions
uses: shivammathur/cache-extensions@v1
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.PHP_EXTENSIONS }}
key: ${{ env.PHP_EXTENSIONS_CACHE_KEY }}-${{ matrix.php }}

- name: Cache PHP extensions
if: ${{ vars.USE_PHP_EXTENSION_CACHE }}
uses: actions/cache@v4
with:
path: ${{ steps.cache-php-extensions.outputs.dir }}
key: ${{ steps.cache-php-extensions.outputs.key }}
restore-keys: ${{ steps.cache-php-extensions.outputs.key }}

- name: Setup PHP
uses: shivammathur/[email protected]
with:
php-version: ${{ matrix.php }}
extensions: ${{ env.PHP_EXTENSIONS }}
ini-values: memory_limit=-1
coverage: pcov

- name: Install composer deps.
uses: ramsey/composer-install@v3
with:
dependency-versions: ${{ matrix.dependencies }}

# - name: Set Composer Cache Directory
# if: ${{ vars.USE_COMPOSER_CACHE }}
# id: composer-cache
# run: |
# echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
#
# - name: Cache Composer dependencies
# uses: actions/cache@v4
# if: ${{ vars.USE_COMPOSER_CACHE }}
# with:
# path: ${{ steps.composer-cache.outputs.dir }}
# key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
# restore-keys: |
# ${{ runner.os }}-php-${{ matrix.php }}-composer-
#
# - name: Install dependencies
# run: |
# composer install --prefer-dist --no-progress --ansi
# continue-on-error: ${{ matrix.is-php-experimental }}

- name: Run unit tests
run: |
vendor/bin/phpunit --testsuite=unit --testdox --no-interaction --colors=always \
--coverage-clover ${{ vars.UNIT_TEST_CLOVER_FILENAME }} \
--testdox-text ${{ vars.UNIT_TEST_DOC_FILENAME }}
- name: Get Coverage artifact name
if: ${{ matrix.generate-coverage-report }}
id: coverage-artifact-name
run: echo "name=${{ vars.ARTIFATC_NAME_FOR_UNIT_TESTS_COVERAGE }}-$GITHUB_SHA" >> $GITHUB_OUTPUT

- name: Save coverage reports
if: ${{ matrix.generate-coverage-report }}
uses: actions/upload-artifact@v4
with:
name: ${{ steps.coverage-artifact-name.outputs.name }}
path: ${{ vars.UNIT_TEST_CLOVER_FILENAME }}

- name: Get Test doc artifact name
if: ${{ matrix.generate-coverage-report }}
id: test-doc-artifact-name
run: echo "name=${{ vars.ARTIFATC_NAME_FOR_UNIT_TESTS_DOCUMENTATION_REPORT }}-$GITHUB_SHA" >> $GITHUB_OUTPUT

- name: Save test doc reports
if: ${{ matrix.generate-coverage-report }}
uses: actions/upload-artifact@v4
with:
name: ${{ steps.test-doc-artifact-name.outputs.name }}
path: ${{ vars.UNIT_TEST_DOC_FILENAME }}





unit-test:
name: Unit tests (php-${{ matrix.php }})
runs-on: ubuntu-22.04
Expand Down

0 comments on commit 4e7a54b

Please sign in to comment.