Skip to content

Feat: coverage in sharding#1758

Open
MrPunyapal wants to merge 16 commits into
pestphp:5.xfrom
MrPunyapal:feat/coverage-in-sharding
Open

Feat: coverage in sharding#1758
MrPunyapal wants to merge 16 commits into
pestphp:5.xfrom
MrPunyapal:feat/coverage-in-sharding

Conversation

@MrPunyapal

Copy link
Copy Markdown
Contributor

What:

  • Bug Fix
  • New Feature

Description

This PR adds first-class code coverage support for sharded Pest runs.

Previously, running --coverage together with --shard=X/Y collected coverage independently for each shard, but Pest did not provide a built-in way to combine those results into a single coverage report.

With this PR, each shard stores its coverage data during execution, and a final merge step generates the same consolidated coverage report users expect from a non-sharded run.

What's Changed

  • pest --shard=X/Y --coverage now stores shard coverage data in .pest/coverage/ instead of generating a coverage report for each shard.
  • Added pest --shards-coverage to merge all shard coverage into a single report.
  • The merged report supports the existing coverage options:
    • --min
    • --exactly
    • --only-covered
  • Added --clean to remove temporary shard coverage files after a successful merge.
  • During sharded runs, report-generating coverage flags (such as --coverage-html and --coverage-clover) are ignored, and Pest prints a reminder showing how to generate the final merged report.
  • Updated the help output and added test coverage for the new workflow.

How To Use Locally

Run each shard with coverage enabled:

pest --shard=1/2 --coverage
pest --shard=2/2 --coverage

Generate the merged coverage report:

pest --shards-coverage

Additional examples:

pest --shard=1/3 --coverage
pest --shard=2/3 --coverage
pest --shard=3/3 --coverage

pest --shards-coverage --min=80
pest --shards-coverage --exactly=91.5
pest --shards-coverage --only-covered
pest --shards-coverage --clean

Notes

  • Temporary shard coverage files are stored in .pest/coverage/{shard}.cov.
  • --clean removes the temporary coverage files after the merged report has been generated.
  • Coverage report options (such as --coverage-html, --coverage-clover, etc.) are ignored during sharded runs because reports can only be generated after all shard coverage has been merged.

Example CI Workflow

Run each shard in parallel and upload the generated coverage directory as an artifact:

# shard jobs
- run: php bin/pest --shard=${{ matrix.shard }}/3 --coverage

- uses: actions/upload-artifact@v4
  with:
    name: coverage-shard-${{ matrix.shard }}
    path: .pest/coverage/

Merge coverage in a follow-up job:

- uses: actions/download-artifact@v4
  with:
    pattern: coverage-shard-*
    merge-multiple: true
    path: .pest/coverage/

- run: pest --shards-coverage --min=80 --clean
20260424-1834-59.9415647.mp4

@MrPunyapal
MrPunyapal force-pushed the feat/coverage-in-sharding branch from 007cebb to a99c26d Compare July 19, 2026 10:32
@MrPunyapal
MrPunyapal marked this pull request as ready for review July 19, 2026 11:02
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.

1 participant