-
Notifications
You must be signed in to change notification settings - Fork 800
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: Initial code to process coverage data (#40016)
To be able to inform the author about the coverage on their PR, we'll need to extract a summary of coverage changes from the raw data we're collecting. This is a first step towards that, combining the raw coverage data into combined files and producing a summary of covered lines in each file. Also, since it annoyed me, I added `WordPress.WP.GlobalVariablesOverride` to our `Jetpack-NoWP` ruleset so non-WordPress code doesn't get useless complaints about common variable names like `$path`. Also, fix Boost coverage that was missing some config settings.
- Loading branch information
Showing
19 changed files
with
196 additions
and
22 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
/composer.lock | ||
/node_modules |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
/** | ||
* Phan config. | ||
* | ||
* @package automattic/jetpack-monorepo | ||
*/ | ||
|
||
// Require base config. | ||
require dirname( __DIR__, 4 ) . '/.phan/config.base.php'; | ||
|
||
return make_phan_config( dirname( __DIR__ ), array( 'stubs' => array() ) ); |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"require-dev": { | ||
"yoast/phpunit-polyfills": "^1.1.1", | ||
"phpunit/phpcov": "^8.2" | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
.github/files/coverage-munger/extract-php-summary-data.php
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
/** | ||
* Script to output summary data from a PHPUnit raw config. | ||
* | ||
* @package automattic/jetpack | ||
*/ | ||
|
||
// @phan-file-suppress PhanAccessMethodInternal -- Nothing much we can do to avoid it. | ||
|
||
use SebastianBergmann\CodeCoverage\Node\File; | ||
|
||
if ( $argc < 2 ) { | ||
fprintf( STDERR, "USAGE: $0 <php.cov> <monorepo-root-path>\n" ); | ||
exit( 1 ); | ||
} | ||
|
||
require __DIR__ . '/vendor/autoload.php'; | ||
$cov = require $argv[1]; | ||
$report = $cov->getReport(); | ||
|
||
foreach ( $report as $item ) { | ||
if ( ! $item instanceof File ) { | ||
continue; | ||
} | ||
|
||
$path = $item->pathAsString(); | ||
|
||
fputcsv( | ||
STDOUT, | ||
array( $path, $item->numberOfExecutableLines() + $item->numberOfExecutableBranches(), $item->numberOfExecutedLines() + $item->numberOfExecutedBranches() ), | ||
"\t", | ||
'"', | ||
'' | ||
); | ||
} |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"private": true, | ||
"name": "jetpack-gh-config-munger", | ||
"devDependencies": { | ||
"istanbul-merge": "^2.0.0", | ||
"nyc": "^17.1.0" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/bash | ||
|
||
set -eo pipefail | ||
|
||
BASE=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd) | ||
|
||
[[ -d coverage ]] && find coverage -type d -empty -delete | ||
if [[ ! -d coverage ]]; then | ||
echo 'No coverage was generated.' | ||
exit 0 | ||
fi | ||
|
||
echo '::group::Copy coverage into artifacts' | ||
tar --owner=0 --group=0 --xz -cvvf artifacts/coverage.tar.xz coverage | ||
echo '::endgroup::' | ||
|
||
TMP_DIR=$( mktemp -d ) | ||
trap 'rm -rf "$TMP_DIR"' exit | ||
|
||
echo "::group::Combining PHP coverage" | ||
composer --working-dir="$BASE" update | ||
"$BASE"/vendor/bin/phpcov merge --php artifacts/php-combined.cov coverage | ||
perl -i -pwe 'BEGIN { $prefix = shift; $prefix=~s!/*$!/!; $re = qr/\Q$prefix\E/; $l = length( $prefix ); } s!s:(\d+):"$re! sprintf( qq(s:%d:"), $1 - $l ) !ge' "$GITHUB_WORKSPACE" artifacts/php-combined.cov | ||
echo '::endgroup::' | ||
|
||
echo "::group::Combining JS coverage" | ||
pnpm --filter=jetpack-gh-config-munger exec istanbul-merge --out "$PWD"/artifacts/js-combined.json $( find "$PWD/coverage" -name '*.json' ) | ||
perl -i -pwe 'BEGIN { $prefix = shift; $prefix=~s!/*$!/!; $re = qr/\Q$prefix\E/; } s!"$re!"!g' "$GITHUB_WORKSPACE" artifacts/js-combined.json | ||
echo '::endgroup::' | ||
|
||
echo "::group::Creating PHP coverage summary" | ||
"$BASE"/extract-php-summary-data.php artifacts/php-combined.cov > "$TMP_DIR/php-summary.tsv" | ||
echo '::endgroup::' | ||
|
||
echo "::group::Creating JS coverage summary" | ||
mkdir "$TMP_DIR/js" | ||
cp artifacts/js-combined.json "$TMP_DIR/js" | ||
pnpm --filter=jetpack-gh-config-munger exec nyc report --no-exclude-after-remap --report-dir="$TMP_DIR" --temp-dir="$TMP_DIR/js" --reporter=json-summary | ||
jq -r 'to_entries[] | select( .key != "total" ) | [ .key, .value.lines.total, .value.lines.covered ] | @tsv' "$TMP_DIR/coverage-summary.json" > "$TMP_DIR/js-summary.tsv" | ||
echo '::endgroup::' | ||
|
||
echo "::group::Combining coverage summaries" | ||
sort "$TMP_DIR/php-summary.tsv" "$TMP_DIR/js-summary.tsv" > artifacts/summary.tsv | ||
echo '::endgroup::' |
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
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
// Monorepo pseudo-projects. These are things that have their own composer.json but aren't actual projects. | ||
{ | ||
"monorepo/actions-tool-setup-composer-plugin": ".github/actions/tool-setup/composer-plugin/", | ||
"monorepo/coverage-munger": ".github/files/coverage-munger/", | ||
"monorepo/cli-doc-parser": "tools/cli/helpers/doc-parser/", | ||
"monorepo/e2e-commons": "tools/e2e-commons/" | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -4,3 +4,4 @@ packages: | |
- 'tools/cli' | ||
- 'tools/e2e-commons' | ||
- 'tools/js-tools' | ||
- '.github/files/coverage-munger' |
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
4 changes: 4 additions & 0 deletions
4
projects/packages/codesniffer/changelog/add-coverage-processing
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: changed | ||
|
||
Add `WordPress.WP.GlobalVariablesOverride` to `Jetpack-NoWP` ruleset. |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Significance: patch | ||
Type: fixed | ||
Comment: Fix Boost coverage | ||
|
||
|
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
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
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
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