Skip to content

ci: Surface code coverage results in module CI - #12

Merged
tablackburn merged 1 commit into
mainfrom
ci/139-publish-code-coverage
Aug 28, 2026
Merged

tablackburn merged 1 commit into
mainfrom
ci/139-publish-code-coverage

Conversation

@tablackburn

Copy link
Copy Markdown
Contributor

What

Surface code coverage in the shared module CI workflow. Until now ModuleCI.yml uploaded and published testResults.xml but nothing collected the JaCoCo report a module's Pester task can produce.

Each test job (the pwsh matrix and the Windows PowerShell 5.1 job) gains two steps:

  • Upload Code Coverage Results - uploads the JaCoCo report as its own artifact.
  • Summarize Code Coverage - parses the report's totals and writes a small table to the run summary, so the number is visible without downloading anything.

The unit test publisher now downloads only the Unit Test Results* artifacts, so the new coverage artifacts are not handed to publish-unit-test-result-action as if they were test results.

Which option, and why

Refs psake/PowerShellBuild#139, which listed three options in ascending ambition. This is option 1 plus the cheapest honest form of option 2.

  • Option 1 alone (artifact only) leaves the number invisible unless somebody downloads a zip. Not much of an improvement.
  • Option 2 via a third-party action was the first thing I reached for and it does not fit. irongut/CodeCoverageSummary reads Cobertura, not JaCoCo. The JaCoCo PR-comment actions are Java-oriented: they map sourcefilename onto source directories and report per-changed-file coverage, which does not line up with what Pester emits for a PowerShell module. A dozen lines of PowerShell in a PowerShell org's workflow is less machinery than an action that needs coaxing, and it keeps the caveat below attached to the number it describes. It also avoids a second bot comment on every pull request - publish-unit-test-result-action already comments, and a duplicate for an understated number is noise.
  • Option 3 (Codecov and similar) adds a third-party service and a repository secret to an org that has not asked for one, for a metric that is a floor rather than a measurement. Not worth it. If a maintainer later wants badges, this change does not stand in the way.

Reports, never gates

Pester instruments the current session only. Tests that exercise code in child processes do not contribute - PowerShellBuild has a lot of those, its help tests and the Test-PSBuildPester subprocess matrix among them - so the measured number understates real coverage. It is a trend line, not an absolute.

So there is no threshold and no failure path. A build-failing gate over an understated number would be actively harmful. The caveat is printed under the table in the run summary, and stated in the workflow comments above the step.

Guarding consumers that produce no coverage

Both new steps carry if: always() && hashFiles(inputs.code_coverage_report_path) != '', the same shape as the existing changelog step. Coverage is off by default in PowerShellBuild ($PSBPreference.Test.CodeCoverage.Enabled = $false), so most consumers produce no file at all and simply skip both steps. Nobody is failed for lacking a file they never claimed to have.

The path is a new workflow_call input, code_coverage_report_path, defaulting to tests/out/coverage.xml - the tests/out/ convention the test results already follow, and what psake/PowerShellBuild actually writes. A module that leaves $PSBPreference.Test.CodeCoverage.OutputFile at its default writes codeCoverage.xml to the project root instead and can point the input at that. No existing caller needs to change.

Verification

  • The YAML parses; jobs, steps and the new input were listed from the parsed document rather than eyeballed.
  • The summary script was run against a real tests/out/coverage.xml from a psake/PowerShellBuild build under both pwsh and Windows PowerShell 5.1. Byte-identical output on both, no BOM, LF endings. The JaCoCo DOCTYPE does not trip the [xml] cast on either engine.
  • No new permissions are required.

🤖 Generated with Claude Code

https://claude.ai/code/session_01U1Jhu7fgTRJq7LK5MuKteE

The workflow already uploaded and published testResults.xml, but nothing
collected the JaCoCo coverage report a module's Pester task can produce.

Each test job now uploads the report as its own artifact and renders the
JaCoCo totals into the run summary, both guarded on the file existing so a
module that does not measure coverage is unaffected. The path is a
workflow_call input because it differs per consumer: PowerShellBuild's
$PSBPreference.Test.CodeCoverage.OutputFile defaults to codeCoverage.xml in
the project root, while a repository following the tests/out/ convention the
test results already use writes tests/out/coverage.xml.

The summary reports and never gates. Pester instruments the current session
only, so anything a test exercises in a child process goes uncounted and the
figure understates real coverage; a build-failing threshold over it would be
actively misleading. The caveat is stated in the summary itself and in the
comments above the step.

The unit test publisher now downloads only the test result artifacts, so the
coverage reports are not fed to it as test results.

Refs psake/PowerShellBuild#139

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01U1Jhu7fgTRJq7LK5MuKteE
Copilot AI lite review requested due to automatic review settings August 28, 2026 20:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@tablackburn
tablackburn merged commit 2eb2803 into main Aug 28, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants