Skip to content

Commit

Permalink
Merge pull request #119 from wp-cli/code-coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
swissspidy authored Jan 29, 2025
2 parents 8fc3577 + 77f02ae commit 22f7dbd
Showing 1 changed file with 57 additions and 21 deletions.
78 changes: 57 additions & 21 deletions .github/workflows/reusable-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ jobs:
MATRIX=$(cat << EOF
{
"include": [
{
"php": "5.6",
"wp": "3.7",
"mysql": "5.6"
},
{
"php": "5.6",
"wp": "6.2",
"mysql": "8.0"
},
{
"php": "7.2",
"wp": "latest",
Expand Down Expand Up @@ -93,6 +103,17 @@ jobs:
"wp": "latest",
"dbtype": "sqlite"
},
{
"php": "8.3",
"wp": "latest",
"mysql": "8.0",
"coverage": true
},
{
"php": "8.3",
"wp": "latest",
"dbtype": "sqlite"
},
{
"php": "7.2",
"wp": "trunk",
Expand Down Expand Up @@ -138,26 +159,11 @@ jobs:
"wp": "trunk",
"mysql": "8.0"
},
{
"php": "5.6",
"wp": "3.7",
"mysql": "5.6"
},
{
"php": "5.6",
"wp": "6.2",
"mysql": "8.0"
},
{
"php": "8.3",
"wp": "trunk",
"mysql": "8.0"
},
{
"php": "8.2",
"wp": "trunk",
"dbtype": "sqlite"
},
{
"php": "8.3",
"wp": "trunk",
Expand Down Expand Up @@ -209,7 +215,7 @@ jobs:
id: set-matrix
run: |
if [[ $FILE_EXISTS == 'true' ]]; then
echo "matrix=$(jq -c '.include |= map(with_entries(select(.key == "php"))) | .include |= map(select(.php >= "${{ inputs.minimum-php }}")) | .include |= unique_by(.php)' <<< $BASE_MATRIX)" >> $GITHUB_OUTPUT
echo "matrix=$(jq -c '.include |= map(with_entries(select(.key == "php", .key == "coverage"))) | .include |= map(select(.php >= "${{ inputs.minimum-php }}")) | .include |= unique_by(.php)' <<< $BASE_MATRIX)" >> $GITHUB_OUTPUT
else
echo "matrix=" >> $GITHUB_OUTPUT
fi
Expand All @@ -220,7 +226,7 @@ jobs:
unit: #-----------------------------------------------------------------------
needs: prepare-unit
if: ${{ needs.prepare-unit.outputs.matrix != '' }}
name: Unit test / PHP ${{ matrix.php }}
name: Unit test / PHP ${{ matrix.php }}${{ matrix.coverage && ' (with coverage)' || '' }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare-unit.outputs.matrix) }}
Expand All @@ -237,7 +243,7 @@ jobs:
with:
php-version: '${{ matrix.php }}'
ini-values: zend.assertions=1, error_reporting=-1, display_errors=On
coverage: none
coverage: ${{ matrix.coverage && 'xdebug' || 'none' }}
tools: composer,cs2pr
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -265,7 +271,20 @@ jobs:
run: echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Run PHPUnit
run: composer phpunit
run: |
if [[ ${{ matrix.coverage == true }} == true ]]; then
composer phpunit -- --coverage-clover build/logs/unit-coverage.xml
else
composer phpunit
fi
- name: Upload code coverage report
if: ${{ matrix.coverage }}
uses: codecov/[email protected]
with:
directory: build/logs
flags: unit
token: ${{ secrets.CODECOV_TOKEN }}

prepare-functional: #---------------------------------------------------------
name: Prepare matrix for functional tests
Expand Down Expand Up @@ -298,7 +317,7 @@ jobs:
functional: #-----------------------------------------------------------------
needs: prepare-functional
if: ${{ needs.prepare-functional.outputs.matrix != '' }}
name: Functional - WP ${{ matrix.wp }} on PHP ${{ matrix.php }} with ${{ matrix.dbtype != 'sqlite' && format('MySQL {0}', matrix.mysql) || 'SQLite' }}
name: Functional - WP ${{ matrix.wp }} on PHP ${{ matrix.php }} with ${{ matrix.dbtype != 'sqlite' && format('MySQL {0}', matrix.mysql) || 'SQLite' }}${{ matrix.coverage && ' (with coverage)' || '' }}
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.prepare-functional.outputs.matrix) }}
Expand All @@ -322,7 +341,7 @@ jobs:
# Disable error reporting for Behat tests on PHP 8.4+, as long as Behat is not upgraded to a newer version.
ini-values: ${{ matrix.php != '8.4' && matrix.php != 'nightly' && 'zend.assertions=1, error_reporting=-1, display_errors=On' || '' }}
extensions: gd, imagick, mysql, zip
coverage: none
coverage: ${{ matrix.coverage && 'xdebug' || 'none' }}
tools: composer
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -380,4 +399,21 @@ jobs:
WP_VERSION: '${{ matrix.wp }}'
WP_CLI_TEST_DBTYPE: ${{ matrix.dbtype || 'mysql' }}
WP_CLI_TEST_DBSOCKET: '${{ steps.setup-mysql.outputs.base-dir }}/tmp/mysql.sock'
WP_CLI_TEST_COVERAGE: ${{ matrix.coverage }}
run: composer behat || composer behat-rerun

- name: Retrieve list of coverage files
id: coverage_files
if: ${{ matrix.coverage }}
run: |
FILES=$(find "$GITHUB_WORKSPACE/build/logs" -path '*.*' | paste -s -d "," -)
echo "files=$FILES" >> $GITHUB_OUTPUT
- name: Upload code coverage report
if: ${{ matrix.coverage }}
uses: codecov/[email protected]
with:
# Because somehow providing `directory: build/logs` doesn't work for these files
files: ${{ steps.coverage_files.outputs.files }}
flags: feature
token: ${{ secrets.CODECOV_TOKEN }}

0 comments on commit 22f7dbd

Please sign in to comment.