diff --git a/.github/workflows/php-tests.yml b/.github/workflows/php-tests.yml index 64a8366..d48e3b3 100644 --- a/.github/workflows/php-tests.yml +++ b/.github/workflows/php-tests.yml @@ -59,13 +59,21 @@ on: type: string default: 'pcov' coverage-php-version: - description: If non-empty, run coverage-command on the matrix entry matching this PHP version (instead of test-script) and upload an HTML coverage artifact. Leave empty to skip coverage collection entirely. + description: If non-empty, collect coverage on the matrix entry matching this PHP version (instead of running test-script) and upload the artifact. Leave empty to skip coverage collection entirely. type: string default: '' - coverage-command: - description: Command run on the coverage matrix entry. Used only when coverage-php-version is non-empty. - type: string - default: 'vendor/bin/phpunit --coverage-text --coverage-html coverage-report --colors=never' + coverage-html: + description: Generate the PHPUnit HTML coverage report under coverage-report/. + type: boolean + default: true + coverage-text: + description: Generate the PHPUnit text coverage report at coverage-report/coverage.txt. + type: boolean + default: true + coverage-clover: + description: Generate the Clover XML coverage report at coverage-report/clover.xml. + type: boolean + default: true coverage-artifact-name: description: Artifact name for the uploaded coverage report type: string @@ -154,9 +162,29 @@ jobs: - name: Run tests with coverage if: ${{ inputs.coverage-php-version != '' && matrix.php-version == inputs.coverage-php-version }} + env: + COVERAGE_HTML: ${{ inputs.coverage-html }} + COVERAGE_TEXT: ${{ inputs.coverage-text }} + COVERAGE_CLOVER: ${{ inputs.coverage-clover }} run: | + set -euo pipefail + mkdir -p coverage-report + args=() + if [[ "$COVERAGE_HTML" = 'true' ]]; then + args+=(--coverage-html=coverage-report) + fi + if [[ "$COVERAGE_TEXT" = 'true' ]]; then + args+=(--coverage-text=coverage-report/coverage.txt) + fi + if [[ "$COVERAGE_CLOVER" = 'true' ]]; then + args+=(--coverage-clover=coverage-report/clover.xml) + fi + if (( ${#args[@]} == 0 )); then + echo '::error::At least one of coverage-html, coverage-text, coverage-clover must be true.' + exit 1 + fi echo "::group::Running PHPUnit with Coverage" - ${{ inputs.coverage-command }} + vendor/bin/phpunit "${args[@]}" --colors=never echo "::endgroup::" - name: Upload coverage report