Skip to content

Commit 331d42c

Browse files
🩹 [Patch]: Improve test output (#87)
## Description This pull request includes several changes to improve the logging and output. The primary changes involve replacing `Write-Verbose` with `Write-Host` for better visibility and formatting of the output, as well as some restructuring for clarity. Changes to logging and output: * [`scripts/helpers/Resolve-PSModuleDependency.ps1`](diffhunk://#diff-48557b471e7d62a89be3627235334ab8a39eb6119174abb61714b92d844508e2L27-R31): Replaced multiple instances of `Write-Verbose` with `Write-Host` to ensure messages are always displayed. [[1]](diffhunk://#diff-48557b471e7d62a89be3627235334ab8a39eb6119174abb61714b92d844508e2L27-R31) [[2]](diffhunk://#diff-48557b471e7d62a89be3627235334ab8a39eb6119174abb61714b92d844508e2L47-R59) * [`scripts/helpers/Test-PSModule.ps1`](diffhunk://#diff-2100eb52126417766eeb5b98f9c6a0da1dd10302b3b7c05d476295e3bd76ce76L46-R50): Replaced `Write-Verbose` with `Write-Host` and `Write-GitHubWarning` for better output formatting and visibility. Additionally, restructured some output to use `Format-List`. [[1]](diffhunk://#diff-2100eb52126417766eeb5b98f9c6a0da1dd10302b3b7c05d476295e3bd76ce76L46-R50) [[2]](diffhunk://#diff-2100eb52126417766eeb5b98f9c6a0da1dd10302b3b7c05d476295e3bd76ce76L66-R67) [[3]](diffhunk://#diff-2100eb52126417766eeb5b98f9c6a0da1dd10302b3b7c05d476295e3bd76ce76L80-R80) [[4]](diffhunk://#diff-2100eb52126417766eeb5b98f9c6a0da1dd10302b3b7c05d476295e3bd76ce76L95-R94) [[5]](diffhunk://#diff-2100eb52126417766eeb5b98f9c6a0da1dd10302b3b7c05d476295e3bd76ce76L112-R110) [[6]](diffhunk://#diff-2100eb52126417766eeb5b98f9c6a0da1dd10302b3b7c05d476295e3bd76ce76L124-R125) [[7]](diffhunk://#diff-2100eb52126417766eeb5b98f9c6a0da1dd10302b3b7c05d476295e3bd76ce76L177-R176) * [`scripts/main.ps1`](diffhunk://#diff-dc2e5a659836b1b73abb03421c567f5018c2755677c4a0aa764cb26117b68011L7-R59): Replaced `Write-Verbose` with `Write-Host` and `Write-GitHubError` for better output visibility and error reporting. Also restructured some sections for clarity. Enhancements to script execution: * [`action.yml`](diffhunk://#diff-1243c5424efaaa19bd8e813c5e6f6da46316e63761421b3e5f5c8ced9a36e6b6R69-R72): Added `ShowOutput: true` to the `runs:` section to ensure script output is displayed. ## Type of change <!-- Use the check-boxes [x] on the options that are relevant. --> - [ ] 📖 [Docs] - [ ] 🪲 [Fix] - [x] 🩹 [Patch] - [ ] ⚠️ [Security fix] - [ ] 🚀 [Feature] - [ ] 🌟 [Breaking change] ## Checklist <!-- Use the check-boxes [x] on the options that are relevant. --> - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas
1 parent 14d8042 commit 331d42c

File tree

4 files changed

+45
-61
lines changed

4 files changed

+45
-61
lines changed

action.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ runs:
6666
Prerelease: ${{ inputs.Prerelease }}
6767
Verbose: ${{ inputs.Verbose }}
6868
Version: ${{ inputs.Version }}
69+
ShowOutput: true
6970
Script: |
7071
# Test-PSModule
71-
. "${{ github.action_path }}\scripts\main.ps1"
72+
. (Join-Path -Path '${{ github.action_path }}' -ChildPath 'scripts\main.ps1')
7273
7374
- name: Upload test results
7475
uses: actions/upload-artifact@v4

scripts/helpers/Resolve-PSModuleDependency.ps1

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@
2424
[string] $ManifestFilePath
2525
)
2626

27-
Write-Verbose 'Resolving dependencies'
27+
Write-Host 'Resolving dependencies'
2828

2929
$manifest = Import-PowerShellDataFile -Path $ManifestFilePath
30-
Write-Verbose "Reading [$ManifestFilePath]"
31-
Write-Verbose "Found [$($manifest.RequiredModules.Count)] modules to install"
30+
Write-Host "Reading [$ManifestFilePath]"
31+
Write-Host "Found [$($manifest.RequiredModules.Count)] modules to install"
3232

3333
foreach ($requiredModule in $manifest.RequiredModules) {
3434
$installParams = @{}
@@ -44,17 +44,17 @@
4444
$installParams.Force = $true
4545
$installParams.Verbose = $false
4646

47-
Write-Verbose "[$($installParams.Name)] - Installing module"
47+
Write-Host "[$($installParams.Name)] - Installing module"
4848
$VerbosePreferenceOriginal = $VerbosePreference
4949
$VerbosePreference = 'SilentlyContinue'
5050
Install-Module @installParams -AllowPrerelease:$false
5151
$VerbosePreference = $VerbosePreferenceOriginal
52-
Write-Verbose "[$($installParams.Name)] - Importing module"
52+
Write-Host "[$($installParams.Name)] - Importing module"
5353
$VerbosePreferenceOriginal = $VerbosePreference
5454
$VerbosePreference = 'SilentlyContinue'
5555
Import-Module @installParams
5656
$VerbosePreference = $VerbosePreferenceOriginal
57-
Write-Verbose "[$($installParams.Name)] - Done"
57+
Write-Host "[$($installParams.Name)] - Done"
5858
}
59-
Write-Verbose 'Resolving dependencies - Done'
59+
Write-Host 'Resolving dependencies - Done'
6060
}

scripts/helpers/Test-PSModule.ps1

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,11 @@
4343
$PSSAModule = Get-PSResource -Name PSScriptAnalyzer -Verbose:$false | Sort-Object Version -Descending | Select-Object -First 1
4444
$pesterModule = Get-PSResource -Name Pester -Verbose:$false | Sort-Object Version -Descending | Select-Object -First 1
4545

46-
Write-Verbose 'Testing with:'
47-
Write-Verbose " PowerShell $($PSVersionTable.PSVersion.ToString())"
48-
Write-Verbose " Pester $($pesterModule.version)"
49-
Write-Verbose " PSScriptAnalyzer $($PSSAModule.version)"
46+
[PSCustomObject]@{
47+
PowerShell = $PSVersionTable.PSVersion.ToString()
48+
Pester = $pesterModule.version
49+
PSScriptAnalyzer = $PSSAModule.version
50+
} | Format-List
5051
}
5152

5253
LogGroup 'Add test - Common - PSScriptAnalyzer' {
@@ -63,8 +64,7 @@
6364
Verbose = $false
6465
}
6566
}
66-
Write-Verbose 'ContainerParams:'
67-
Write-Verbose "$($containerParams | ConvertTo-Json)"
67+
Write-Host ($containerParams | ConvertTo-Json)
6868
$containers += New-PesterContainer @containerParams
6969
}
7070

@@ -77,8 +77,7 @@
7777
Verbose = $false
7878
}
7979
}
80-
Write-Verbose 'ContainerParams:'
81-
Write-Verbose "$($containerParams | ConvertTo-Json)"
80+
Write-Host ($containerParams | ConvertTo-Json)
8281
$containers += New-PesterContainer @containerParams
8382
}
8483

@@ -92,8 +91,7 @@
9291
Verbose = $false
9392
}
9493
}
95-
Write-Verbose 'ContainerParams:'
96-
Write-Verbose "$($containerParams | ConvertTo-Json)"
94+
Write-Host ($containerParams | ConvertTo-Json)
9795
$containers += New-PesterContainer @containerParams
9896
}
9997
}
@@ -109,8 +107,7 @@
109107
Verbose = $false
110108
}
111109
}
112-
Write-Verbose 'ContainerParams:'
113-
Write-Verbose "$($containerParams | ConvertTo-Json)"
110+
Write-Host ($containerParams | ConvertTo-Json)
114111
$containers += New-PesterContainer @containerParams
115112
}
116113
}
@@ -121,12 +118,11 @@
121118
$containerParams = @{
122119
Path = $moduleTestsPath
123120
}
124-
Write-Verbose 'ContainerParams:'
125-
Write-Verbose "$($containerParams | ConvertTo-Json)"
121+
Write-Host ($containerParams | ConvertTo-Json)
126122
$containers += New-PesterContainer @containerParams
127123
}
128124
} else {
129-
Write-Warning "⚠️ No tests found - [$moduleTestsPath]"
125+
Write-GitHubWarning "⚠️ No tests found - [$moduleTestsPath]"
130126
}
131127
}
132128

@@ -174,13 +170,8 @@
174170
}
175171
}
176172
}
177-
Write-Verbose 'PesterParams:'
178-
Write-Verbose "$($pesterParams | ConvertTo-Json -Depth 4 -WarningAction SilentlyContinue)"
173+
Write-Host ($pesterParams | ConvertTo-Json -Depth 5 -WarningAction SilentlyContinue)
179174
}
180175

181-
#region Run tests
182-
$results = Invoke-Pester @pesterParams
183-
#endregion
184-
185-
$results
176+
Invoke-Pester @pesterParams
186177
}

scripts/main.ps1

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,65 +4,57 @@ param()
44
$path = (Join-Path -Path $PSScriptRoot -ChildPath 'helpers')
55
LogGroup "Loading helper scripts from [$path]" {
66
Get-ChildItem -Path $path -Filter '*.ps1' -Recurse | ForEach-Object {
7-
Write-Verbose "[$($_.FullName)]"
7+
Write-Host " - $($_.FullName)"
88
. $_.FullName
99
}
1010
}
1111

1212
LogGroup 'Loading inputs' {
13-
$moduleName = if ($env:GITHUB_ACTION_INPUT_Name | IsNullOrEmpty) { $env:GITHUB_REPOSITORY_NAME } else { $env:GITHUB_ACTION_INPUT_Name }
14-
Write-Verbose "Module name: [$moduleName]"
15-
13+
$moduleName = ($env:GITHUB_ACTION_INPUT_Name | IsNullOrEmpty) ? $env:GITHUB_REPOSITORY_NAME : $env:GITHUB_ACTION_INPUT_Name
1614
$codeToTest = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath "$env:GITHUB_ACTION_INPUT_Path\$moduleName"
17-
if (Test-Path -Path $codeToTest) {
18-
Write-Verbose "Code to test: [$codeToTest]"
19-
} else {
15+
if (-not (Test-Path -Path $codeToTest)) {
2016
$codeToTest = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $env:GITHUB_ACTION_INPUT_Path
2117
}
22-
23-
Write-Verbose "Code to test: [$codeToTest]"
2418
if (-not (Test-Path -Path $codeToTest)) {
2519
throw "Path [$codeToTest] does not exist."
2620
}
27-
Write-Verbose "Test type to run: [$env:GITHUB_ACTION_INPUT_TestType]"
2821

29-
$testsPath = $env:GITHUB_ACTION_INPUT_TestsPath
30-
Write-Verbose "Path to tests: [$testsPath]"
31-
if (-not (Test-Path -Path $testsPath)) {
32-
throw "Path [$testsPath] does not exist."
22+
if (-not (Test-Path -Path $env:GITHUB_ACTION_INPUT_TestsPath)) {
23+
throw "Path [$env:GITHUB_ACTION_INPUT_TestsPath] does not exist."
3324
}
3425

35-
$StackTraceVerbosity = $env:GITHUB_ACTION_INPUT_StackTraceVerbosity
36-
Write-Verbose "StackTraceVerbosity: [$StackTraceVerbosity]"
37-
$Verbosity = $env:GITHUB_ACTION_INPUT_Verbosity
38-
Write-Verbose "Verbosity: [$Verbosity]"
39-
26+
[pscustomobject]@{
27+
ModuleName = $moduleName
28+
CodeToTest = $codeToTest
29+
TestType = $env:GITHUB_ACTION_INPUT_TestType
30+
TestsPath = $env:GITHUB_ACTION_INPUT_TestsPath
31+
StackTraceVerbosity = $env:GITHUB_ACTION_INPUT_StackTraceVerbosity
32+
Verbosity = $env:GITHUB_ACTION_INPUT_Verbosity
33+
} | Format-List
4034
}
4135

4236
$params = @{
4337
Path = $codeToTest
4438
TestType = $env:GITHUB_ACTION_INPUT_TestType
45-
TestsPath = $testsPath
46-
StackTraceVerbosity = $StackTraceVerbosity
47-
Verbosity = $Verbosity
39+
TestsPath = $env:GITHUB_ACTION_INPUT_TestsPath
40+
StackTraceVerbosity = $env:GITHUB_ACTION_INPUT_StackTraceVerbosity
41+
Verbosity = $env:GITHUB_ACTION_INPUT_Verbosity
4842
}
49-
$results = Test-PSModule @params
43+
$testResults = Test-PSModule @params
5044

5145
LogGroup 'Test results' {
52-
Write-Verbose ($results | Out-String)
46+
$testResults | Format-List
5347
}
5448

55-
$failedTests = $results.FailedCount
49+
$failedTests = [int]$testResults.FailedCount
5650

57-
if ($failedTests -gt 0) {
58-
Write-Host '::error::❌ Some tests failed.'
59-
}
60-
if ($results.Result -ne 'Passed') {
61-
Write-Host '::error::❌ Some tests failed.'
51+
if (($failedTests -gt 0) -or ($testResults.Result -ne 'Passed')) {
52+
Write-GitHubError "❌ Some [$failedTests] tests failed."
6253
}
6354
if ($failedTests -eq 0) {
64-
Write-Host '::notice::✅ All tests passed.'
55+
Write-GitHubNotice '✅ All tests passed.'
6556
}
6657

6758
Set-GitHubOutput -Name 'passed' -Value ($failedTests -eq 0)
59+
Write-Host '━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━'
6860
exit $failedTests

0 commit comments

Comments
 (0)