-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexec.ps1
More file actions
178 lines (152 loc) · 7.12 KB
/
Copy pathexec.ps1
File metadata and controls
178 lines (152 loc) · 7.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
[CmdletBinding()]
param()
$DebugPreference = $env:PSMODULE_INVOKE_PESTER_INPUT_Debug -eq 'true' ? 'Continue' : 'SilentlyContinue'
$VerbosePreference = $env:PSMODULE_INVOKE_PESTER_INPUT_Verbose -eq 'true' ? 'Continue' : 'SilentlyContinue'
$PSStyle.OutputRendering = 'Ansi'
'::group::Exec - Setup prerequisites'
Import-Module "$PSScriptRoot/Helpers.psm1"
'Pester' | Install-PSResourceWithRetry
'::endgroup::'
'::group::Exec - Get test kit versions'
$pesterModule = Get-PSResource -Name Pester -Verbose:$false | Sort-Object Version -Descending | Select-Object -First 1
[PSCustomObject]@{
PowerShell = $PSVersionTable.PSVersion.ToString()
Pester = $pesterModule.Version
} | Format-List
'::endgroup::'
'::group::Exec - Info about environment'
$path = Join-Path -Path $pwd.Path -ChildPath '.temp'
Test-Path -Path $path
Get-ChildItem -Path $path -Recurse | Sort-Object FullName | Format-Table -AutoSize | Out-String
'::group::Exec - Import Configuration'
$configPath = (Join-Path -Path $path -ChildPath 'Invoke-Pester.Configuration.ps1')
Write-Output "Importing configuration from [$configPath]"
if (-not (Test-Path -Path $configPath)) {
Write-Error "Configuration file [$configPath] not found."
exit 1
}
Get-Content -Path $configPath -Raw
'::endgroup::'
'::group::Exec - PesterConfiguration'
$configuration = . $configPath
$configuration.Run.Container = @()
$containerFiles = Get-ChildItem -Path $path -Filter *.Container.* -Recurse | Sort-Object FullName
foreach ($containerFile in $containerFiles) {
$container = & $($containerFile.FullName)
Write-Verbose "Processing container [$container]"
Write-Verbose 'Converting hashtable to PesterContainer'
$configuration.Run.Container += New-PesterContainer @container
}
$configuration | ConvertTo-Json
'::endgroup::'
'::group::Exec - Available modules'
Get-Module | Format-Table -AutoSize | Out-String
'::endgroup::'
$configuration = New-PesterConfiguration -Hashtable $configuration
$PSStyle.OutputRendering = 'Host' # Ensure propper XML rendering
$testResults = Invoke-Pester -Configuration $configuration
$PSStyle.OutputRendering = 'Ansi'
'::group::Eval - Setup prerequisites'
'Pester', 'Hashtable', 'TimeSpan', 'Markdown' | Install-PSResourceWithRetry
'::endgroup::'
'::group::Eval - Get test kit versions'
$pesterModule = Get-PSResource -Name Pester -Verbose:$false | Sort-Object Version -Descending | Select-Object -First 1
[PSCustomObject]@{
PowerShell = $PSVersionTable.PSVersion.ToString()
Pester = $pesterModule.Version
} | Format-List
'::endgroup::'
'::group::Eval - Test results'
if ($null -eq $testResults) {
'::error::❌ No test results were returned.'
exit 1
}
$testResults | Format-List | Out-String
'::endgroup::'
'::group::Eval - Test results summary'
$stepSummaryMode = $env:PSMODULE_INVOKE_PESTER_INPUT_StepSummary_Mode
$showTestOverview = $env:PSMODULE_INVOKE_PESTER_INPUT_StepSummary_ShowTestOverview -eq 'true'
$showConfiguration = $env:PSMODULE_INVOKE_PESTER_INPUT_StepSummary_ShowConfiguration -eq 'true'
# Only generate a step summary if the StepSummary setting is not 'None'
# AND at least one component is configured to be displayed
$generateSummary = $showTestOverview -or $showConfiguration -or ($stepSummaryMode -in @('Failed', 'Full'))
if ($generateSummary) {
$PSStyle.OutputRendering = 'Host'
$summaryParams = @{
ShowTestOverview = $showTestOverview
ShowTestsMode = $stepSummaryMode
ShowConfiguration = $showConfiguration
}
[PSCustomObject]$summaryParams | Format-List | Out-String
$content = $testResults | Set-PesterReportSummary @summaryParams
if ($content) {
$content >> $env:GITHUB_STEP_SUMMARY
} else {
Write-Verbose 'No content to display in step summary'
}
$PSStyle.OutputRendering = 'Ansi'
} else {
Write-Verbose 'Step summary has been disabled or no components are configured for display'
}
'::endgroup::'
'::group::Eval - Set outputs'
$testResultOutputFolderPath = $testResults.Configuration.TestResult.OutputPath.Value | Split-Path -Parent
$codeCoverageOutputFolderPath = $testResults.Configuration.CodeCoverage.OutputPath.Value | Split-Path -Parent
[pscustomobject]@{
TestSuiteName = $testResults.Configuration.TestResult.TestSuiteName.Value
TestResultEnabled = $testResults.Configuration.TestResult.Enabled.Value
TestResultOutputPath = $testResultOutputFolderPath
CodeCoverageEnabled = $testResults.Configuration.CodeCoverage.Enabled.Value
CodeCoverageOutputPath = $codeCoverageOutputFolderPath
} | Format-List | Out-String
"TestSuiteName=$($testResults.Configuration.TestResult.TestSuiteName.Value)" >> $env:GITHUB_OUTPUT
"TestResultEnabled=$($testResults.Configuration.TestResult.Enabled.Value)" >> $env:GITHUB_OUTPUT
"TestResultOutputPath=$($testResultOutputFolderPath)" >> $env:GITHUB_OUTPUT
"CodeCoverageEnabled=$($testResults.Configuration.CodeCoverage.Enabled.Value)" >> $env:GITHUB_OUTPUT
"CodeCoverageOutputPath=$($codeCoverageOutputFolderPath)" >> $env:GITHUB_OUTPUT
"Executed=$($testResults.Executed)" >> $env:GITHUB_OUTPUT
"Result=$($testResults.Result)" >> $env:GITHUB_OUTPUT
"FailedCount=$($testResults.FailedCount)" >> $env:GITHUB_OUTPUT
"FailedBlocksCount=$($testResults.FailedBlocksCount)" >> $env:GITHUB_OUTPUT
"FailedContainersCount=$($testResults.FailedContainersCount)" >> $env:GITHUB_OUTPUT
"PassedCount=$($testResults.PassedCount)" >> $env:GITHUB_OUTPUT
"SkippedCount=$($testResults.SkippedCount)" >> $env:GITHUB_OUTPUT
"InconclusiveCount=$($testResults.InconclusiveCount)" >> $env:GITHUB_OUTPUT
"NotRunCount=$($testResults.NotRunCount)" >> $env:GITHUB_OUTPUT
"TotalCount=$($testResults.TotalCount)" >> $env:GITHUB_OUTPUT
if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.TestResult.Enabled.Value) {
$jsonOutputPath = $testResults.Configuration.TestResult.OutputPath.Value -replace '\.xml$', '.json'
Write-Output "Exporting test results to [$jsonOutputPath]"
$testResults | Get-PesterTestTree | ConvertTo-Json -Depth 100 -Compress | Out-File -FilePath $jsonOutputPath
}
if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.CodeCoverage.Enabled.Value) {
$jsonOutputPath = $testResults.Configuration.CodeCoverage.OutputPath.Value -replace '\.xml$', '.json'
Write-Output "Exporting code coverage results to [$jsonOutputPath]"
$testResults.CodeCoverage | ConvertTo-Json -Depth 100 -Compress | Out-File -FilePath $jsonOutputPath
}
'::endgroup::'
'::group::Exit'
$noticeMode = $env:PSMODULE_INVOKE_PESTER_INPUT_Notice_Mode
$failedTests = $testResults.FailedCount
if ($testResults.Result -eq 'Passed') {
if ($noticeMode -eq 'Full') {
'::notice::✅ All tests passed.'
}
$script:exit = 0
} else {
if ($noticeMode -in @('Full', 'Failed')) {
if ($failedTests -gt 0) {
"::notice::❌ Some [$failedTests] tests failed."
} else {
'::notice::❌ Some tests failed.'
}
}
if ($failedTests -gt 0) {
"::error::❌ Some [$failedTests] tests failed."
$script:exit = $failedTests
} else {
'::error::❌ Some tests failed.'
$script:exit = 1
}
}
exit $script:exit