|
1 | | -# Template-Action |
| 1 | +# Get-PesterCodeCoverage |
2 | 2 |
|
3 | | -A template repository for GitHub Actions |
| 3 | +A GitHub Action that aggregates Pester code coverage reports and generates a detailed summary with coverage statistics. |
| 4 | +Fails the workflow if coverage falls below specified targets. |
| 5 | + |
| 6 | +This GitHub Action is a part of the [PSModule framework](https://github.com/PSModule). It is recommended to use the |
| 7 | +[Process-PSModule workflow](https://github.com/PSModule/Process-PSModule) to automate the whole process of managing the PowerShell module. |
| 8 | + |
| 9 | +## Features |
| 10 | + |
| 11 | +- Combines multiple code coverage reports from parallel test runs |
| 12 | +- Generates markdown/HTML tables showing missed & executed commands |
| 13 | +- Displays analyzed files and coverage statistics |
| 14 | +- Configurable step summary sections |
| 15 | +- Threshold enforcement for minimum code coverage |
4 | 16 |
|
5 | 17 | ## Usage |
6 | 18 |
|
7 | 19 | ### Inputs |
8 | 20 |
|
9 | | -### Secrets |
| 21 | +| Name | Description | Required | Default | |
| 22 | +|------|-------------|----------|---------| |
| 23 | +| `Debug` | Enable debug output | No | `false` | |
| 24 | +| `Verbose` | Enable verbose output | No | `false` | |
| 25 | +| `Version` | Exact version of GitHub module to install | No | Latest | |
| 26 | +| `Prerelease` | Allow prerelease versions | No | `false` | |
| 27 | +| `WorkingDirectory` | Working directory for the action | No | `.` | |
| 28 | +| `StepSummary_Mode` | Controls which sections to show in the GitHub step summary. Use 'Full' for all sections, 'None' to disable, or a comma-separated list of 'Missed, Executed, Files'. | No | `Missed, Files` | |
| 29 | +| `CodeCoveragePercentTarget` | Target code coverage percentage | No | Max target from individual reports | |
| 30 | + |
| 31 | +### Example Workflow |
| 32 | + |
| 33 | +```yaml |
| 34 | + - name: Process Code Coverage |
| 35 | + uses: PSModule/Get-PesterCodeCoverage@v1 |
| 36 | + with: |
| 37 | + StepSummary_Mode: Full |
| 38 | + CodeCoveragePercentTarget: 80 |
| 39 | +``` |
| 40 | +
|
| 41 | +## Outputs |
| 42 | +
|
| 43 | +### GitHub Step Summary |
| 44 | +
|
| 45 | +The action generates a detailed summary visible in the GitHub Actions UI: |
| 46 | +
|
| 47 | +1. **Coverage Overview Table** |
| 48 | + - Coverage percentage vs target |
| 49 | + - Analyzed/executed/missed command counts |
| 50 | + - Number of files analyzed |
| 51 | +
|
| 52 | +2. **Expandable Sections** |
| 53 | + - **Missed Commands**: HTML table with code snippets |
| 54 | + - **Executed Commands**: HTML table with code snippets |
| 55 | + - **Analyzed Files**: List of covered files |
| 56 | +
|
| 57 | +Example summary: |
| 58 | +
|
| 59 | +```markdown |
| 60 | +✅ Code Coverage Report |
| 61 | + |
| 62 | +Summary: |
| 63 | +| Coverage | Target | Analyzed | Executed | Missed | Files | |
| 64 | +|----------|--------|---------------|---------------|---------------|---------------| |
| 65 | +| 85% | 80% | 1000 commands | 850 commands | 150 commands | 15 files | |
| 66 | + |
| 67 | +▶️ Missed commands [150] (click to expand) |
| 68 | +▶️ Executed commands [850] (click to expand) |
| 69 | +▶️ Files analyzed [15] (click to expand) |
| 70 | +``` |
| 71 | + |
| 72 | +## Requirements |
| 73 | + |
| 74 | +1. **Pester Code Coverage Reports** |
| 75 | + Preceding steps must generate JSON coverage reports named `*-CodeCoverage*.json` |
| 76 | + |
| 77 | +2. **GitHub CLI** |
| 78 | + The action uses `gh run download` to fetch artifacts from the current workflow run |
| 79 | + |
| 80 | +## Behavior |
| 81 | + |
| 82 | +1. **Coverage Calculation** |
| 83 | + - Combines multiple coverage reports |
| 84 | + - Removes duplicate entries |
| 85 | + - Calculates aggregate coverage percentage |
| 86 | + |
| 87 | +2. **Threshold Enforcement** |
| 88 | + Fails the workflow if coverage is below either: |
| 89 | + - Explicitly specified `CodeCoveragePercentTarget` |
| 90 | + - Highest target from individual reports (if no target specified) |
| 91 | + |
| 92 | +3. **Output Control** |
| 93 | + Configure visibility of sections using `StepSummary_Mode`: |
| 94 | + ```yaml |
| 95 | + # Show all sections |
| 96 | + StepSummary_Mode: Full |
| 97 | + |
| 98 | + # Disable summary |
| 99 | + StepSummary_Mode: None |
10 | 100 |
|
11 | | -### Outputs |
| 101 | + # Custom selection |
| 102 | + StepSummary_Mode: Missed, Files |
| 103 | + ``` |
12 | 104 |
|
13 | | -### Example |
| 105 | +## Troubleshooting |
14 | 106 |
|
| 107 | +Enable debugging by setting inputs: |
15 | 108 | ```yaml |
16 | | -Example here |
| 109 | +with: |
| 110 | + Debug: true |
| 111 | + Verbose: true |
17 | 112 | ``` |
0 commit comments