generated from PSModule/Template-Action
-
Notifications
You must be signed in to change notification settings - Fork 0
🌟 [Major]: Introducing Get-PesterCodeCoverage
#1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 74 commits
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
b7a5559
Update action.yml and main.ps1 for Get-PesterCodeCoverage GitHub Action
MariusStorhaug 09ebe97
Add functionality to merge coverage reports and output a combined XML…
MariusStorhaug 92c4c6b
Refactor main.ps1 to improve code readability and maintainability by …
MariusStorhaug 9b4e9c9
Enhance code coverage logging by summarizing JSON content and improvi…
MariusStorhaug 434e58b
Refactor logging in main.ps1 to improve output format and remove unus…
MariusStorhaug dcea16b
Sort CodeCoverage files by name for improved output consistency
MariusStorhaug 9fc1d1e
Refactor log group names in main.ps1 for clarity and consistency
MariusStorhaug dcb81ba
Refactor log group naming in main.ps1 for improved clarity
MariusStorhaug 56cc096
Update log group naming in main.ps1 for improved readability
MariusStorhaug 138b773
Enhance summary log group formatting in main.ps1 for better visual se…
MariusStorhaug b195b10
Refactor coverage report generation in main.ps1 for improved clarity …
MariusStorhaug 461df5e
Enhance code coverage reporting in main.ps1 with detailed output and …
MariusStorhaug 369d74a
Add module installation and improve coverage report formatting in mai…
MariusStorhaug a9e6210
Refactor markdown output in main.ps1 for improved structure and clarity
MariusStorhaug 90b4d63
Sort commands in coverage report for improved readability and organiz…
MariusStorhaug 910a27e
Add helper function to convert file paths to relative format in main.ps1
MariusStorhaug 7159c76
Remove unnecessary formatting from code coverage report tables for cl…
MariusStorhaug 7c985c5
Update details in coverage report to include counts for missed, execu…
MariusStorhaug 9ff9cb7
Rename Convert-ToRelativePath function to ConvertTo-RelativePath for …
MariusStorhaug 4002aec
Update coverage check to use Write-GitHubError and Write-GitHubNotice…
MariusStorhaug 32b596d
Enhance code coverage report by formatting command output with markdo…
MariusStorhaug 83ce1ab
Refactor code coverage report to generate HTML tables for missed and …
MariusStorhaug b7bd674
Refactor HTML table generation in coverage report for missed and exec…
MariusStorhaug 756cfd7
Refactor command output in coverage report to remove HTML encoding, e…
MariusStorhaug c1c64d3
Normalize file paths in coverage report and transform command output …
MariusStorhaug 43b589e
Refactor command output in coverage report to HTML encode commands an…
MariusStorhaug 215ea4a
Refactor command output in coverage report to replace spaces with non…
MariusStorhaug 0721fdd
Refactor command output in coverage report to remove HTML encoding, e…
MariusStorhaug 3d85c7c
Add Normalize-IndentationExceptFirst function to adjust indentation i…
MariusStorhaug 43b1b82
Refactor command output in coverage report to use preformatted text f…
MariusStorhaug 763bd4b
Refactor command output in coverage report to use code formatting for…
MariusStorhaug 3cd3042
Refactor Normalize-IndentationExceptFirst function to use HTML line b…
MariusStorhaug 6e0f3d4
Refactor command output formatting in coverage report to enhance read…
MariusStorhaug 6775fb3
Escape curly braces in command output for improved HTML rendering in …
MariusStorhaug e4c7cd3
Remove unnecessary escaping of curly braces in command output for imp…
MariusStorhaug cf7b9af
Add inline style for preserving whitespace in command output for impr…
MariusStorhaug 29692b5
Refactor command output formatting in coverage report to escape curly…
MariusStorhaug 19a2258
Fix HTML attribute quotes in command output formatting for consistency
MariusStorhaug d87ad46
Update code block language from 'pwsh' to 'powershell' for improved s…
MariusStorhaug 1d6ab4e
Refactor command output formatting to ensure consistent HTML renderin…
MariusStorhaug f69b4a2
Fix command output formatting to ensure consistent HTML rendering in …
MariusStorhaug 925ce64
Refactor command output to build HTML tables for missed and executed …
MariusStorhaug 6f0346e
Refactor command output processing to improve HTML encoding and inden…
MariusStorhaug 3e438fb
Remove HTML encoding from command output for missed and executed comm…
MariusStorhaug dfd9702
Refactor command processing to improve handling of missed and execute…
MariusStorhaug 1225f8e
Replace HTML line break with environment-specific new line in indenta…
MariusStorhaug 8b9d99d
Refactor command output to separate display for executed commands, im…
MariusStorhaug 782ade6
Refactor command handling to streamline normalization of missed and e…
MariusStorhaug b023068
Enhance coverage report by listing analyzed files in a clearer format
MariusStorhaug ef5637f
Update default working directory in action.yml to use a relative path
MariusStorhaug e2b31bc
Remove GITHUB_TOKEN environment variable from Auto-Release workflow
MariusStorhaug c1faae5
Add path normalization function for PSModulePath and update file proc…
MariusStorhaug 3c894b9
Refactor path normalization in ConvertTo-NormalizedModulePath functio…
MariusStorhaug 20bbc3e
Refactor ConvertTo-NormalizedModulePath for improved readability and …
MariusStorhaug 6908310
Refactor path normalization logic and remove unused ConvertTo-Relativ…
MariusStorhaug 134c719
Refactor file path normalization logic and simplify output formatting…
MariusStorhaug f89342c
Implement retry logic for module installation in main.ps1 to enhance …
MariusStorhaug c80b707
Sort and remove duplicates from FilesAnalyzed in main.ps1 for improve…
MariusStorhaug e434034
Add StepSummary_Mode input to control GitHub step summary sections in…
MariusStorhaug ab58843
Refactor JSON file processing in main.ps1 to improve path normalizati…
MariusStorhaug 9b8919d
Remove unnecessary blank line in main.ps1 for cleaner code formatting
MariusStorhaug dd7da3d
Update log output to use BaseName instead of Name for improved clarit…
MariusStorhaug 0964127
Round coverage percentages to two decimal places for improved readabi…
MariusStorhaug 01eb305
Add logging for file listing and improve group name formatting in mai…
MariusStorhaug f618ace
Remove '-CodeCoverage-Report' suffix from group name for cleaner outp…
MariusStorhaug df2c4dc
Add CodeCoveragePercentTarget input to action.yml and update main.ps1…
MariusStorhaug 87db5ed
Add optional CodeCoveragePercentTarget input to action.yml and enhanc…
MariusStorhaug e397d4e
Add ShowInfo input to action.yml for improved script execution control
MariusStorhaug edacad4
Add success indicator
MariusStorhaug 3d6cfbe
Rename log group titles to include 'Step Summary' for improved clarit…
MariusStorhaug 268af1d
Add initial code coverage report for PSModuleTest
MariusStorhaug 349704d
Refactor documentation formatting in Helpers.psm1 and update comment …
MariusStorhaug a9bc669
Update CodeCoveragePercentTarget to 50 in Action-Test.yml for adjuste…
MariusStorhaug 5097429
Update README.md to specify markdown formatting for example summary
MariusStorhaug 06798d4
Enhance descriptions for StepSummary_Mode in README.md and action.yml…
MariusStorhaug File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -30,5 +30,3 @@ jobs: | |
|
||
- name: Auto-Release | ||
uses: PSModule/Auto-Release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ github.token }} |
This file contains hidden or 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,17 +1,112 @@ | ||
# Template-Action | ||
# Get-PesterCodeCoverage | ||
|
||
A template repository for GitHub Actions | ||
A GitHub Action that aggregates Pester code coverage reports and generates a detailed summary with coverage statistics. | ||
Fails the workflow if coverage falls below specified targets. | ||
|
||
This GitHub Action is a part of the [PSModule framework](https://github.com/PSModule). It is recommended to use the | ||
[Process-PSModule workflow](https://github.com/PSModule/Process-PSModule) to automate the whole process of managing the PowerShell module. | ||
|
||
## Features | ||
|
||
- Combines multiple code coverage reports from parallel test runs | ||
- Generates markdown/HTML tables showing missed & executed commands | ||
- Displays analyzed files and coverage statistics | ||
- Configurable step summary sections | ||
- Threshold enforcement for minimum code coverage | ||
|
||
## Usage | ||
|
||
### Inputs | ||
|
||
### Secrets | ||
| Name | Description | Required | Default | | ||
|------|-------------|----------|---------| | ||
| `Debug` | Enable debug output | No | `false` | | ||
| `Verbose` | Enable verbose output | No | `false` | | ||
| `Version` | Exact version of GitHub module to install | No | Latest | | ||
| `Prerelease` | Allow prerelease versions | No | `false` | | ||
| `WorkingDirectory` | Working directory for the action | No | `.` | | ||
| `StepSummary_Mode` | Step summary sections to show (`Full`, `None`, or comma-separated list of `Missed,Executed,Files`) | No | `Missed,Files` | | ||
| `CodeCoveragePercentTarget` | Target code coverage percentage | No | Max target from individual reports | | ||
|
||
### Example Workflow | ||
|
||
```yaml | ||
- name: Process Code Coverage | ||
uses: PSModule/Get-PesterCodeCoverage@v1 | ||
with: | ||
StepSummary_Mode: Full | ||
CodeCoveragePercentTarget: 80 | ||
``` | ||
|
||
## Outputs | ||
|
||
### GitHub Step Summary | ||
|
||
The action generates a detailed summary visible in the GitHub Actions UI: | ||
|
||
1. **Coverage Overview Table** | ||
- Coverage percentage vs target | ||
- Analyzed/executed/missed command counts | ||
- Number of files analyzed | ||
|
||
2. **Expandable Sections** | ||
- **Missed Commands**: HTML table with code snippets | ||
- **Executed Commands**: HTML table with code snippets | ||
- **Analyzed Files**: List of covered files | ||
|
||
Example summary: | ||
|
||
```markdown | ||
✅ Code Coverage Report | ||
|
||
Summary: | ||
| Coverage | Target | Analyzed | Executed | Missed | Files | | ||
|----------|--------|---------------|---------------|---------------|---------------| | ||
| 85% | 80% | 1000 commands | 850 commands | 150 commands | 15 files | | ||
|
||
▶️ Missed commands [150] (click to expand) | ||
▶️ Executed commands [850] (click to expand) | ||
▶️ Files analyzed [15] (click to expand) | ||
``` | ||
|
||
## Requirements | ||
|
||
1. **Pester Code Coverage Reports** | ||
Preceding steps must generate JSON coverage reports named `*-CodeCoverage*.json` | ||
|
||
2. **GitHub CLI** | ||
The action uses `gh run download` to fetch artifacts from the current workflow run | ||
|
||
## Behavior | ||
|
||
1. **Coverage Calculation** | ||
- Combines multiple coverage reports | ||
- Removes duplicate entries | ||
- Calculates aggregate coverage percentage | ||
|
||
2. **Threshold Enforcement** | ||
Fails the workflow if coverage is below either: | ||
- Explicitly specified `CodeCoveragePercentTarget` | ||
- Highest target from individual reports (if no target specified) | ||
|
||
3. **Output Control** | ||
Configure visibility of sections using `StepSummary_Mode`: | ||
```yaml | ||
# Show all sections | ||
StepSummary_Mode: Full | ||
|
||
# Disable summary | ||
StepSummary_Mode: None | ||
|
||
### Outputs | ||
# Custom selection | ||
StepSummary_Mode: Missed,Files | ||
``` | ||
|
||
### Example | ||
## Troubleshooting | ||
|
||
Enable debugging by setting inputs: | ||
```yaml | ||
Example here | ||
with: | ||
Debug: true | ||
Verbose: true | ||
``` |
This file contains hidden or 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 hidden or 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,68 @@ | ||
function Normalize-IndentationExceptFirst { | ||
<# | ||
.SYNOPSIS | ||
Normalizes the indentation of a multi-line string, except for the first line. | ||
|
||
.DESCRIPTION | ||
This function takes a multi-line string and normalizes the indentation of all lines except the first one. | ||
It removes the minimum leading whitespace from all subsequent lines. | ||
|
||
.PARAMETER Code | ||
The multi-line string to normalize. | ||
|
||
.OUTPUTS | ||
Returns the normalized multi-line string. | ||
s#> | ||
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSUseApprovedVerbs', '', Scope = 'Function', Justification = 'Function isnt exported.')] | ||
[OutputType([string])] | ||
[CmdletBinding()] | ||
param( | ||
[Parameter(Mandatory)] | ||
[string]$Code | ||
) | ||
|
||
# Split the code into lines | ||
$lines = $Code -split "`r?`n" | ||
|
||
# If there's 0 or 1 line, there's nothing special to do | ||
if ($lines.Count -le 1) { | ||
return $Code | ||
} | ||
|
||
# The first line stays as-is; we skip it for indentation measurement | ||
$firstLine = $lines[0] | ||
$subsequentLines = $lines[1..($lines.Count - 1)] | ||
|
||
# Find the minimum leading indentation among the *subsequent* lines | ||
$minIndent = ($subsequentLines | Where-Object { $_ -match '\S' } | ForEach-Object { | ||
# If the line starts with whitespace, capture how many characters | ||
if ($_ -match '^(\s+)') { | ||
$matches[1].Length | ||
} else { | ||
0 | ||
} | ||
} | Measure-Object -Minimum).Minimum | ||
|
||
# Remove that leading indentation from each subsequent line | ||
for ($i = 0; $i -lt $subsequentLines.Count; $i++) { | ||
$line = $subsequentLines[$i] | ||
|
||
# Only attempt to remove indentation if we actually have some whitespace | ||
if ($line -match '^(\s+)(.*)$') { | ||
# $matches[1] = leading whitespace; $matches[2] = the rest | ||
$leading = $matches[1] | ||
$rest = $matches[2] | ||
|
||
# If we have enough whitespace to remove $minIndent worth, do it | ||
if ($leading.Length -ge $minIndent) { | ||
$leading = $leading.Substring($minIndent) | ||
} | ||
# Recombine | ||
$subsequentLines[$i] = $leading + $rest | ||
} | ||
} | ||
|
||
$newLine = [Environment]::NewLine | ||
# Reconstruct the final code: first line + adjusted subsequent lines | ||
return ($firstLine + $newLine + ($subsequentLines -join $newLine)) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.