Skip to content

Commit c3b43d4

Browse files
Having issues with outputs into another step (#69)
## Description - Having issues with outputs into another step ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [ ] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas
1 parent de95e05 commit c3b43d4

File tree

6 files changed

+158
-147
lines changed

6 files changed

+158
-147
lines changed

.github/workflows/Action-Test-Src-Default.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,19 @@ jobs:
2727

2828
- name: Action-Test
2929
uses: ./
30+
id: action-test
3031
env:
3132
GITHUB_TOKEN: ${{ github.token }}
3233
with:
3334
Name: PSModuleTest
3435
Path: tests/src
3536
TestType: SourceCode
37+
38+
- name: Status
39+
shell: pwsh
40+
run: |
41+
$passed = '${{ steps.action-test.outputs.passed }}'
42+
Write-Host "Passed: [$Passed]"
43+
if ($passed -eq 'False') {
44+
exit 1
45+
}

.github/workflows/Action-Test-Src-WithManifest.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,19 @@ jobs:
2727

2828
- name: Action-Test
2929
uses: ./
30+
id: action-test
3031
env:
3132
GITHUB_TOKEN: ${{ github.token }}
3233
with:
3334
Name: PSModuleTest
3435
Path: tests/srcWithManifest
3536
TestType: SourceCode
37+
38+
- name: Status
39+
shell: pwsh
40+
run: |
41+
$passed = '${{ steps.action-test.outputs.passed }}'
42+
Write-Host "Passed: [$Passed]"
43+
if ($passed -eq 'False') {
44+
exit 1
45+
}

.github/workflows/Action-Test-outputs.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,19 @@ jobs:
2727

2828
- name: Action-Test
2929
uses: ./
30+
id: action-test
3031
env:
3132
GITHUB_TOKEN: ${{ github.token }}
3233
with:
3334
Name: PSModuleTest
3435
Path: tests/outputs/modules
3536
TestType: Module
37+
38+
- name: Status
39+
shell: pwsh
40+
run: |
41+
$passed = '${{ steps.action-test.outputs.passed }}'
42+
Write-Host "Passed: [$Passed]"
43+
if ($passed -eq 'False') {
44+
exit 1
45+
}

action.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ inputs:
1919
description: The path to the tests to run.
2020
required: false
2121
default: tests
22-
Shell:
23-
description: The shell to use for running the tests.
24-
required: false
25-
default: pwsh
2622

2723
outputs:
2824
passed:
@@ -34,21 +30,25 @@ runs:
3430
steps:
3531
- name: Run Test-PSModule
3632
uses: PSModule/GitHub-Script@v1
33+
34+
- name: Run Test-PSModule
35+
shell: pwsh
3736
id: test
3837
env:
3938
GITHUB_ACTION_INPUT_Name: ${{ inputs.Name }}
4039
GITHUB_ACTION_INPUT_Path: ${{ inputs.Path }}
4140
GITHUB_ACTION_INPUT_TestType: ${{ inputs.TestType }}
4241
GITHUB_ACTION_INPUT_TestsPath: ${{ inputs.TestsPath }}
43-
with:
44-
Script: |
45-
# Test-PSModule
46-
$passed = . "${{ github.action_path }}\scripts\main.ps1" -Verbose
47-
"passed=$passed" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
42+
run: |
43+
# Test-PSModule
44+
$passed = . "${{ github.action_path }}\scripts\main.ps1" -Verbose
45+
"passed=$passed" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
46+
47+
Write-Host "Passed: [$passed]"
4848
49-
if (-not $passed) {
50-
exit 1
51-
}
49+
if (-not $passed) {
50+
exit 1
51+
}
5252
5353
- name: Upload test results
5454
uses: actions/upload-artifact@v4

scripts/helpers/Test-PSModule.ps1

Lines changed: 94 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
#REQUIRES -Modules Utilities, PSScriptAnalyzer, Pester
2-
3-
function Test-PSModule {
1+
function Test-PSModule {
42
<#
53
.SYNOPSIS
64
Performs tests on a module.
@@ -27,156 +25,140 @@ function Test-PSModule {
2725
$testModule = $TestType -eq 'Module'
2826
$moduleTestsPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $TestsPath
2927

30-
#region Get test kit versions
31-
Start-LogGroup 'Get test kit versions'
32-
$PSSAModule = Get-PSResource -Name PSScriptAnalyzer -Verbose:$false | Sort-Object Version -Descending | Select-Object -First 1
33-
$pesterModule = Get-PSResource -Name Pester -Verbose:$false | Sort-Object Version -Descending | Select-Object -First 1
34-
35-
Write-Verbose 'Testing with:'
36-
Write-Verbose " PowerShell $($PSVersionTable.PSVersion.ToString())"
37-
Write-Verbose " Pester $($pesterModule.version)"
38-
Write-Verbose " PSScriptAnalyzer $($PSSAModule.version)"
39-
Stop-LogGroup
40-
#endregion
41-
42-
#region Add test - Common - PSScriptAnalyzer
43-
Start-LogGroup 'Add test - Common - PSScriptAnalyzer'
44-
$containers = @()
45-
$PSSATestsPath = Join-Path -Path $PSScriptRoot -ChildPath '..\tests\PSScriptAnalyzer'
46-
$settingsFileName = if ($testModule) { 'Settings.Module.psd1' } else { 'Settings.SourceCode.psd1' }
47-
$settingsFilePath = Join-Path -Path $PSSATestsPath -ChildPath $settingsFileName
48-
$containerParams = @{
49-
Path = Join-Path $PSSATestsPath 'PSScriptAnalyzer.Tests.ps1'
50-
Data = @{
51-
Path = $Path
52-
SettingsFilePath = $settingsFilePath
53-
Verbose = $true
54-
}
55-
}
56-
Write-Verbose 'ContainerParams:'
57-
Write-Verbose "$($containerParams | ConvertTo-Json)"
58-
$containers += New-PesterContainer @containerParams
59-
Stop-LogGroup
60-
#endregion
28+
LogGroup 'Get test kit versions' {
29+
$PSSAModule = Get-PSResource -Name PSScriptAnalyzer -Verbose:$false | Sort-Object Version -Descending | Select-Object -First 1
30+
$pesterModule = Get-PSResource -Name Pester -Verbose:$false | Sort-Object Version -Descending | Select-Object -First 1
6131

62-
#region Add test - Common - PSModule
63-
Start-LogGroup 'Add test - Common - PSModule'
64-
$containerParams = @{
65-
Path = Join-Path -Path $PSScriptRoot -ChildPath '..\tests\PSModule\Common.Tests.ps1'
66-
Data = @{
67-
Path = $Path
68-
Verbose = $true
69-
}
32+
Write-Verbose 'Testing with:'
33+
Write-Verbose " PowerShell $($PSVersionTable.PSVersion.ToString())"
34+
Write-Verbose " Pester $($pesterModule.version)"
35+
Write-Verbose " PSScriptAnalyzer $($PSSAModule.version)"
7036
}
71-
Write-Verbose 'ContainerParams:'
72-
Write-Verbose "$($containerParams | ConvertTo-Json)"
73-
$containers += New-PesterContainer @containerParams
74-
Stop-LogGroup
75-
#endregion
7637

77-
#region Add test - Module - PSModule
78-
if ($testModule) {
79-
Start-LogGroup 'Add test - Module - PSModule'
38+
LogGroup 'Add test - Common - PSScriptAnalyzer' {
39+
$containers = @()
40+
$PSSATestsPath = Join-Path -Path $PSScriptRoot -ChildPath '..\tests\PSScriptAnalyzer'
41+
$settingsFileName = if ($testModule) { 'Settings.Module.psd1' } else { 'Settings.SourceCode.psd1' }
42+
$settingsFilePath = Join-Path -Path $PSSATestsPath -ChildPath $settingsFileName
8043
$containerParams = @{
81-
Path = Join-Path -Path $PSScriptRoot -ChildPath '..\tests\PSModule\Module.Tests.ps1'
44+
Path = Join-Path $PSSATestsPath 'PSScriptAnalyzer.Tests.ps1'
8245
Data = @{
83-
Path = $Path
84-
Verbose = $true
46+
Path = $Path
47+
SettingsFilePath = $settingsFilePath
48+
Verbose = $true
8549
}
8650
}
8751
Write-Verbose 'ContainerParams:'
8852
Write-Verbose "$($containerParams | ConvertTo-Json)"
8953
$containers += New-PesterContainer @containerParams
90-
Stop-LogGroup
9154
}
92-
#endregion
9355

94-
#region Add test - SourceCode - PSModule
95-
if ($testSourceCode) {
96-
Start-LogGroup 'Add test - SourceCode - PSModule'
56+
LogGroup 'Add test - Common - PSModule' {
9757
$containerParams = @{
98-
Path = Join-Path -Path $PSScriptRoot -ChildPath '..\tests\PSModule\SourceCode.Tests.ps1'
58+
Path = Join-Path -Path $PSScriptRoot -ChildPath '..\tests\PSModule\Common.Tests.ps1'
9959
Data = @{
100-
Path = $Path
101-
TestsPath = $moduleTestsPath
102-
Verbose = $true
60+
Path = $Path
61+
Verbose = $true
10362
}
10463
}
10564
Write-Verbose 'ContainerParams:'
10665
Write-Verbose "$($containerParams | ConvertTo-Json)"
10766
$containers += New-PesterContainer @containerParams
108-
Stop-LogGroup
10967
}
110-
#endregion
11168

112-
#region Add test - Module - $moduleName
11369
if ($testModule) {
114-
if (Test-Path -Path $moduleTestsPath) {
115-
Start-LogGroup "Add test - Module - $moduleName"
70+
LogGroup 'Add test - Module - PSModule' {
71+
$containerParams = @{
72+
Path = Join-Path -Path $PSScriptRoot -ChildPath '..\tests\PSModule\Module.Tests.ps1'
73+
Data = @{
74+
Path = $Path
75+
Verbose = $true
76+
}
77+
}
78+
Write-Verbose 'ContainerParams:'
79+
Write-Verbose "$($containerParams | ConvertTo-Json)"
80+
$containers += New-PesterContainer @containerParams
81+
}
82+
}
83+
84+
if ($testSourceCode) {
85+
LogGroup 'Add test - SourceCode - PSModule' {
11686
$containerParams = @{
117-
Path = $moduleTestsPath
87+
Path = Join-Path -Path $PSScriptRoot -ChildPath '..\tests\PSModule\SourceCode.Tests.ps1'
11888
Data = @{
119-
Path = $Path
89+
Path = $Path
90+
TestsPath = $moduleTestsPath
91+
Verbose = $true
12092
}
12193
}
12294
Write-Verbose 'ContainerParams:'
12395
Write-Verbose "$($containerParams | ConvertTo-Json)"
12496
$containers += New-PesterContainer @containerParams
125-
Stop-LogGroup
97+
}
98+
}
99+
100+
if ($testModule) {
101+
if (Test-Path -Path $moduleTestsPath) {
102+
LogGroup "Add test - Module - $moduleName" {
103+
$containerParams = @{
104+
Path = $moduleTestsPath
105+
Data = @{
106+
Path = $Path
107+
}
108+
}
109+
Write-Verbose 'ContainerParams:'
110+
Write-Verbose "$($containerParams | ConvertTo-Json)"
111+
$containers += New-PesterContainer @containerParams
112+
}
126113
} else {
127114
Write-Warning "⚠️ No tests found - [$moduleTestsPath]"
128115
}
129116
}
130-
#endregion
131117

132-
#region Import module
133118
if ((Test-Path -Path $moduleTestsPath) -and $testModule) {
134-
Start-LogGroup 'Install module dependencies'
135-
$moduleManifestPath = Join-Path -Path $Path -ChildPath "$moduleName.psd1"
136-
Resolve-PSModuleDependency -ManifestFilePath $moduleManifestPath
137-
Stop-LogGroup
119+
LogGroup 'Install module dependencies' {
120+
$moduleManifestPath = Join-Path -Path $Path -ChildPath "$moduleName.psd1"
121+
Resolve-PSModuleDependency -ManifestFilePath $moduleManifestPath
122+
}
138123

139-
Start-LogGroup "Importing module: $moduleName"
140-
Add-PSModulePath -Path (Split-Path $Path -Parent)
141-
Get-Module -Name $moduleName -ListAvailable | Remove-Module -Force
142-
Import-Module -Name $moduleName -Force -RequiredVersion '999.0.0' -Global
143-
Stop-LogGroup
124+
LogGroup "Importing module: $moduleName" {
125+
Add-PSModulePath -Path (Split-Path $Path -Parent)
126+
Get-Module -Name $moduleName -ListAvailable | Remove-Module -Force
127+
Import-Module -Name $moduleName -Force -RequiredVersion '999.0.0' -Global
128+
}
144129
}
145-
#endregion
146130

147-
#region Pester config
148-
Start-LogGroup 'Pester config'
149-
$pesterParams = @{
150-
Configuration = @{
151-
Run = @{
152-
Path = $Path
153-
Container = $containers
154-
PassThru = $true
155-
}
156-
TestResult = @{
157-
Enabled = $testModule
158-
OutputFormat = 'NUnitXml'
159-
OutputPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'outputs\Test-Report.xml'
160-
TestSuiteName = 'Unit tests'
161-
}
162-
CodeCoverage = @{
163-
Enabled = $testModule
164-
OutputPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'outputs\CodeCoverage-Report.xml'
165-
OutputFormat = 'JaCoCo'
166-
OutputEncoding = 'UTF8'
167-
CoveragePercentTarget = 75
168-
}
169-
Output = @{
170-
CIFormat = 'Auto'
171-
StackTraceVerbosity = 'None'
172-
Verbosity = 'Detailed'
131+
LogGroup 'Pester config' {
132+
$pesterParams = @{
133+
Configuration = @{
134+
Run = @{
135+
Path = $Path
136+
Container = $containers
137+
PassThru = $true
138+
}
139+
TestResult = @{
140+
Enabled = $testModule
141+
OutputFormat = 'NUnitXml'
142+
OutputPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'outputs\Test-Report.xml'
143+
TestSuiteName = 'Unit tests'
144+
}
145+
CodeCoverage = @{
146+
Enabled = $testModule
147+
OutputPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath 'outputs\CodeCoverage-Report.xml'
148+
OutputFormat = 'JaCoCo'
149+
OutputEncoding = 'UTF8'
150+
CoveragePercentTarget = 75
151+
}
152+
Output = @{
153+
CIFormat = 'Auto'
154+
StackTraceVerbosity = 'None'
155+
Verbosity = 'Detailed'
156+
}
173157
}
174158
}
159+
Write-Verbose 'PesterParams:'
160+
Write-Verbose "$($pesterParams | ConvertTo-Json -Depth 4 -WarningAction SilentlyContinue)"
175161
}
176-
Write-Verbose 'PesterParams:'
177-
Write-Verbose "$($pesterParams | ConvertTo-Json -Depth 4 -WarningAction SilentlyContinue)"
178-
Stop-LogGroup
179-
#endregion
180162

181163
#region Run tests
182164
$verbosepref = $VerbosePreference

0 commit comments

Comments
 (0)