Skip to content

Commit d5b1020

Browse files
Refactor GitHub Actions for PSModule:
- Update action.yml files to improve readability and maintainability by adding comments and adjusting paths. - Simplify Get-GitHubPullRequest function by removing IsOpen property and related logic. - Enhance Resolve-ReleaseDecision function to streamline prerelease handling and version bump logic. - Modify test data and cases to reflect changes in logic and improve clarity. - Remove outdated DEPENDENCIES.md file to declutter the repository. - Add jscpd configuration for code duplication checks. - Update PSScriptAnalyzer configuration to exclude specific rules.
1 parent b41d5a9 commit d5b1020

13 files changed

Lines changed: 312 additions & 597 deletions

File tree

.github/actionlint.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
# Get-PesterCodeCoverage
2+
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
16+
17+
## Usage
18+
19+
### Inputs
20+
21+
| Name | Description | Required | Default |
22+
| ---- | ----------- | -------- | ------- |
23+
| `Debug` | Enable debug output | No | `false` |
24+
| `Verbose` | Enable verbose output | No | `false` |
25+
| `Version` | Version of the GitHub module to install; accepts an exact version or a NuGet version range (for example `[1.2.0, 2.0.0)`) | 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
100+
101+
# Custom selection
102+
StepSummary_Mode: Missed, Files
103+
```
104+
105+
## Troubleshooting
106+
107+
Enable debugging by setting inputs:
108+
```yaml
109+
with:
110+
Debug: true
111+
Verbose: true
112+
```
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Get-PesterTestResults
2+
3+
A GitHub Action that gathers Pester test results for the PSModule process by analyzing test artifacts from the workflow run.
4+
It validates test execution and results, providing a summary and failing if any tests are unsuccessful.
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+
## Usage
10+
11+
This action retrieves test artifacts named `*-TestResults`, processes the contained JSON files, and checks for test failures, unexecuted tests,
12+
or missing results. It supports three categories of test suites: Source Code, PSModule, and Module tests.
13+
14+
### Inputs
15+
16+
| Input | Description | Required | Default |
17+
|-------------------------|-------------------------------------------------------------------------------------------------------------------------------|----------|-----------|
18+
| `SourceCodeTestSuites` | JSON array specifying OS names for Source Code test suites. Example: `[{"OSName": "Windows"}]` | Yes | |
19+
| `PSModuleTestSuites` | JSON array specifying OS names for PSModule test suites. Example: `[{"OSName": "Linux"}]` | Yes | |
20+
| `ModuleTestSuites` | JSON array specifying TestName and OSName for Module test suites. Example: `[{"TestName": "Integration", "OSName": "MacOS"}]` | Yes | |
21+
| `Debug` | Enable debug output (`true`/`false`). | No | `false` |
22+
| `Verbose` | Enable verbose output (`true`/`false`). | No | `false` |
23+
| `Version` | Exact version of the GitHub module to install (e.g., `1.0.0`). | No | Latest |
24+
| `Prerelease` | Allow installing prerelease module versions (`true`/`false`). | No | `false` |
25+
| `WorkingDirectory` | Working directory for the script. | No | `.` |
26+
27+
### Secrets
28+
29+
No secrets are required if the action runs in the same repository. The action uses the default `GITHUB_TOKEN` provided by GitHub Actions to access workflow artifacts.
30+
31+
### Outputs
32+
33+
This action does not define explicit outputs. Instead:
34+
35+
- If any tests fail or errors occur, the action exits with a non-zero code, marking the workflow step as failed.
36+
- Detailed results are logged in the workflow run's output.
37+
38+
### Example
39+
40+
```yaml
41+
- name: Run and Collect Pester Tests
42+
uses: PSModule/Get-PesterTestResults@v1
43+
with:
44+
SourceCodeTestSuites: '[{"OSName": "Windows"}, {"OSName": "Linux"}]'
45+
PSModuleTestSuites: '[{"OSName": "Windows"}]'
46+
ModuleTestSuites: '[{"TestName": "Integration", "OSName": "Windows"}]'
47+
```
48+
49+
### Notes
50+
- **Test Suite Inputs**: Must be valid JSON arrays.
51+
- `SourceCodeTestSuites` and `PSModuleTestSuites` require `OSName`.
52+
- `ModuleTestSuites` requires both `TestName` and `OSName`.
53+
- **Artifact Names**: The action expects artifacts named `*-TestResults` containing Pester JSON reports.
54+
- **Failure Conditions**: The action fails if tests are unexecuted, explicitly failed, or if result files are missing.

.github/actions/Get-PesterTestResults/action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,5 @@ runs:
5353
WorkingDirectory: ${{ inputs.WorkingDirectory }}
5454
ShowInfo: false
5555
Script: |
56+
# Get Pester test results
5657
${{ github.action_path }}/src/main.ps1
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Install-PSModuleHelpers
2+
3+
A GitHub Action to install and configure the PSModule helper modules for use in continuous integration and delivery (CI/CD) workflows. This action is
4+
a critical component for setting up a standardized PowerShell environment across repositories using the PSModule framework.
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+
## What this action does
10+
11+
- Removes any existing instances of the `Helpers` module from the PowerShell session.
12+
- Copies the latest version of the `Helpers` module into the PowerShell module directory.
13+
- Imports the `Helpers` module, ensuring it is available for subsequent steps.
14+
15+
This action helps maintain consistency and reliability across workflows that depend on the PSModule framework.
16+
17+
## Usage
18+
19+
```yaml
20+
- name: Install PSModule Helpers
21+
uses: PSModule/Install-PSModuleHelpers@v1
22+
```
23+
24+
## Inputs
25+
26+
_No inputs required._
27+
28+
## Secrets
29+
30+
_No secrets required._
31+
32+
## Outputs
33+
34+
This action does not provide any outputs.
35+
36+
## Example
37+
38+
Here's a complete workflow example demonstrating how to use the Install-PSModuleHelpers action:
39+
40+
```yaml
41+
name: CI
42+
43+
on:
44+
push:
45+
branches:
46+
- main
47+
48+
jobs:
49+
build:
50+
runs-on: ubuntu-latest
51+
52+
steps:
53+
- uses: actions/checkout@v4
54+
55+
- name: Install PSModule Helpers
56+
uses: PSModule/Install-PSModuleHelpers@v1
57+
58+
- name: Run additional steps
59+
shell: pwsh
60+
run: |
61+
# Example usage of imported Helpers module
62+
Get-Command -Module Helpers
63+
```

.github/actions/Publish-PSModule/action.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,6 @@ runs:
7979
env:
8080
PSMODULE_PUBLISH_PSMODULE_INPUT_WhatIf: ${{ inputs.WhatIf }}
8181
PSMODULE_PUBLISH_PSMODULE_CONTEXT_ReleaseTag: ${{ env.PSMODULE_PUBLISH_PSMODULE_CONTEXT_ReleaseTag }}
82-
run: ${{ github.action_path }}/src/cleanup.ps1
82+
run: |
83+
# Cleanup prerelease tags
84+
${{ github.action_path }}/src/cleanup.ps1

.github/actions/Resolve-PSModuleVersion/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ runs:
7070
PSMODULE_RESOLVE_PSMODULEVERSION_INPUT_Settings: ${{ inputs.Settings }}
7171
PSMODULE_RESOLVE_PSMODULEVERSION_INPUT_Name: ${{ inputs.Name }}
7272
PSMODULE_RESOLVE_PSMODULEVERSION_INPUT_EventJson: ${{ inputs.EventJson }}
73-
PSMODULE_ACTION_PATH: ${{ github.action_path }}
7473
GITHUB_EVENT_PATH: ${{ inputs.EventPath || github.event_path }}
7574
run: |
76-
& "$env:PSMODULE_ACTION_PATH/src/main.ps1"
75+
# Resolve module version
76+
${{ github.action_path }}/scripts/main.ps1

0 commit comments

Comments
 (0)