-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #119 from wp-cli/code-coverage
- Loading branch information
Showing
1 changed file
with
57 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
|
@@ -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", | ||
|
@@ -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", | ||
|
@@ -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 | ||
|
@@ -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) }} | ||
|
@@ -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 }} | ||
|
@@ -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 | ||
|
@@ -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) }} | ||
|
@@ -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 }} | ||
|
@@ -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 }} |