Skip to content

Commit 42d2652

Browse files
Update working directory and enhance test file discovery (#33)
## Description This pull request includes several updates to the GitHub Actions workflow configuration and documentation. The changes primarily focus on enhancing test result outputs and adding a new test job. Key changes include: ### Workflow Configuration Updates: * [`.github/workflows/Action-Test.yml`](diffhunk://#diff-a12ae5c885b0673c0ff6f70c2670886907590d624626e07da4c52e01aeaf56a4L24-R28): Added new outputs (`Executed` and `Result`) for all test jobs and introduced a new job `ActionTest1SimpleExecutionFailure`. Updated the job dependencies accordingly. [[1]](diffhunk://#diff-a12ae5c885b0673c0ff6f70c2670886907590d624626e07da4c52e01aeaf56a4L24-R28) [[2]](diffhunk://#diff-a12ae5c885b0673c0ff6f70c2670886907590d624626e07da4c52e01aeaf56a4L47-R54) [[3]](diffhunk://#diff-a12ae5c885b0673c0ff6f70c2670886907590d624626e07da4c52e01aeaf56a4R73-R108) [[4]](diffhunk://#diff-a12ae5c885b0673c0ff6f70c2670886907590d624626e07da4c52e01aeaf56a4L95-R135) [[5]](diffhunk://#diff-a12ae5c885b0673c0ff6f70c2670886907590d624626e07da4c52e01aeaf56a4R159) * [`.github/linters/.jscpd.json`](diffhunk://#diff-557094e283c00b23265c1c75872f41c6b1a524a00f0d99dd68ebd22cb63bfdd6L7-R8): Updated the ignore patterns to include `**/.github/workflows/Action-Test**`. ### Documentation Updates: * [`README.md`](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L161-R187): Updated the test outcome section to include new output fields (`Executed`, `Result`, `PassedCount`, `FailedCount`, `SkippedCount`, `InconclusiveCount`, `NotRunCount`, `TotalCount`). Also updated the example workflow to use `PSModule/Invoke-Pester@v3`. [[1]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L161-R187) [[2]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L232-R239) [[3]](diffhunk://#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5L256-R263) ### Other Minor Changes: * [`.github/workflows/Auto-Release.yml`](diffhunk://#diff-d3f6900ee5159d4bc4ba6d893e2dd8443c2691b0490d7351cffbd7a37ed8d95aL33-L34): Removed the `GITHUB_TOKEN` environment variable from the `Auto-Release` job. ## 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 a874096 commit 42d2652

8 files changed

Lines changed: 469 additions & 135 deletions

File tree

.github/linters/.jscpd.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"consoleFull"
55
],
66
"ignore": [
7-
"**/tests/**"
7+
"**/tests/**",
8+
"**/.github/workflows/Action-Test**"
89
],
910
"absolute": true
1011
}

.github/workflows/Action-Test.yml

Lines changed: 182 additions & 53 deletions
Large diffs are not rendered by default.

.github/workflows/Auto-Release.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,3 @@ jobs:
3030

3131
- name: Auto-Release
3232
uses: PSModule/Auto-Release@v1
33-
env:
34-
GITHUB_TOKEN: ${{ github.token }}

README.md

Lines changed: 162 additions & 69 deletions
Large diffs are not rendered by default.

action.yml

Lines changed: 86 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,57 @@ inputs:
205205
WorkingDirectory:
206206
description: The working directory where the script will run from.
207207
required: false
208-
default: ${{ github.workspace }}
208+
default: '.'
209+
210+
outputs:
211+
Outcome:
212+
description: |
213+
The outcome of the test run.
214+
value: ${{ steps.test.outcome }}
215+
Conclusion:
216+
description: |
217+
The conclusion of the test run.
218+
value: ${{ steps.test.conclusion }}
219+
Executed:
220+
description: |
221+
Whether tests were executed.
222+
value: ${{ steps.status.outputs.Executed }}
223+
Result:
224+
description: |
225+
Overall result of the Pester test run (e.g., Passed, Failed).
226+
value: ${{ steps.test.outputs.Result }}
227+
FailedCount:
228+
description: |
229+
Number of failed tests.
230+
value: ${{ steps.test.outputs.FailedCount }}
231+
FailedBlocksCount:
232+
description: |
233+
Number of failed blocks.
234+
value: ${{ steps.test.outputs.FailedBlocksCount }}
235+
FailedContainersCount:
236+
description: |
237+
Number of failed containers.
238+
value: ${{ steps.test.outputs.FailedContainersCount }}
239+
PassedCount:
240+
description: |
241+
Number of passed tests.
242+
value: ${{ steps.test.outputs.PassedCount }}
243+
SkippedCount:
244+
description: |
245+
Number of skipped tests.
246+
value: ${{ steps.test.outputs.SkippedCount }}
247+
InconclusiveCount:
248+
description: |
249+
Number of inconclusive tests.
250+
value: ${{ steps.test.outputs.InconclusiveCount }}
251+
NotRunCount:
252+
description: |
253+
Number of tests not run.
254+
value: ${{ steps.test.outputs.NotRunCount }}
255+
TotalCount:
256+
description: |
257+
Total count of tests.
258+
value: ${{ steps.test.outputs.TotalCount }}
209259

210260
runs:
211261
using: composite
@@ -268,14 +318,16 @@ runs:
268318
# Invoke-Pester (init)
269319
${{ github.action_path }}/scripts/init.ps1
270320
271-
- name: Invoke-Pester
321+
- name: Invoke-Pester (exec)
272322
shell: pwsh
273323
continue-on-error: true
274324
working-directory: ${{ inputs.WorkingDirectory }}
275325
env:
276326
PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson: ${{ inputs.ReportAsJson }}
277327
id: test
278-
run: ${{ github.action_path }}/scripts/main.ps1
328+
run: |
329+
# Invoke-Pester (exec)
330+
${{ github.action_path }}/scripts/exec.ps1
279331
280332
- name: Upload test results - [${{ steps.test.outputs.TestSuiteName }}-TestResults]
281333
uses: actions/upload-artifact@v4
@@ -297,10 +349,39 @@ runs:
297349

298350
- name: Status
299351
shell: pwsh
352+
id: status
300353
working-directory: ${{ inputs.WorkingDirectory }}
354+
env:
355+
PSMODULE_INVOKE_PESTER_INTERNAL_Executed: ${{ steps.test.outputs.Executed }}
356+
PSMODULE_INVOKE_PESTER_INTERNAL_Outcome: ${{ steps.test.outcome }}
357+
PSMODULE_INVOKE_PESTER_INTERNAL_Conclusion: ${{ steps.test.conclusion }}
301358
run: |
302-
$outcome = '${{ steps.test.outcome }}'
303-
Write-Host "outcome: [$outcome]"
359+
# Status
360+
$PSStyle.OutputRendering = 'Ansi'
361+
$executed = $env:PSMODULE_INVOKE_PESTER_INTERNAL_Executed -eq 'true'
362+
$outcome = $env:PSMODULE_INVOKE_PESTER_INTERNAL_Outcome
363+
$conclusion = $env:PSMODULE_INVOKE_PESTER_INTERNAL_Conclusion
364+
365+
"Executed=$executed" >> $env:GITHUB_OUTPUT
366+
367+
[PSCustomObject]@{
368+
Executed = $executed
369+
Outcome = $outcome
370+
Conclusion = $conclusion
371+
} | Format-List | Out-String
372+
373+
# If the tests did not execute, exit with a failure code
374+
if ($executed -ne 'true') {
375+
Write-Error "Tests did not execute."
376+
exit 1
377+
}
378+
# If the outcome is not success, exit with a failure code
304379
if ($outcome -ne 'success') {
380+
Write-Error "Tests did not pass."
381+
exit 1
382+
}
383+
# If the conclusion is not success
384+
if ($conclusion -ne 'success') {
385+
Write-Error "Tests did not pass."
305386
exit 1
306387
}

scripts/main.ps1 renamed to scripts/exec.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ if (-not (Test-Path -Path $configPath)) {
3333
exit 1
3434
}
3535
Get-Content -Path $configPath -Raw
36+
'::endgroup::'
37+
38+
'::group::Exec - PesterConfiguration'
3639
$configuration = . $configPath
3740
$configuration.Run.Container = @()
3841
$containerFiles = Get-ChildItem -Path $path -Filter *.Container.* -Recurse | Sort-Object FullName
@@ -99,6 +102,16 @@ LogGroup 'Eval - Set outputs' {
99102
Set-GitHubOutput -Name 'TestResultOutputPath' -Value $testResultOutputFolderPath
100103
Set-GitHubOutput -Name 'CodeCoverageEnabled' -Value $testResults.Configuration.CodeCoverage.Enabled.Value
101104
Set-GitHubOutput -Name 'CodeCoverageOutputPath' -Value $codeCoverageOutputFolderPath
105+
Set-GitHubOutput -Name 'Executed' -Value $testResults.Executed
106+
Set-GitHubOutput -Name 'Result' -Value $testResults.Result
107+
Set-GitHubOutput -Name 'FailedCount' -Value $testResults.FailedCount
108+
Set-GitHubOutput -Name 'FailedBlocksCount' -Value $testResults.FailedBlocksCount
109+
Set-GitHubOutput -Name 'FailedContainersCount' -Value $testResults.FailedContainersCount
110+
Set-GitHubOutput -Name 'PassedCount' -Value $testResults.PassedCount
111+
Set-GitHubOutput -Name 'SkippedCount' -Value $testResults.SkippedCount
112+
Set-GitHubOutput -Name 'InconclusiveCount' -Value $testResults.InconclusiveCount
113+
Set-GitHubOutput -Name 'NotRunCount' -Value $testResults.NotRunCount
114+
Set-GitHubOutput -Name 'TotalCount' -Value $testResults.TotalCount
102115

103116
if ($env:PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson -eq 'true' -and $testResults.Configuration.TestResult.Enabled.Value) {
104117
$jsonOutputPath = $testResults.Configuration.TestResult.OutputPath.Value -Replace '\.xml$', '.json'

scripts/init.ps1

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,20 +194,37 @@ LogGroup 'Init - Export containers' {
194194
$containerFiles = Get-ChildItem -Path $testDir -Filter *.Container.* -Recurse
195195
Write-Output "Containers found in [$testDir]: [$($containerFiles.Count)]"
196196
if ($containerFiles.Count -eq 0) {
197-
# Look for test files and make a container for each test file.
198-
$testFiles = Get-ChildItem -Path $testDir -Filter *.Tests.ps1 -Recurse
199-
Write-Output "Test files found in [$testDir]: [$($testFiles.Count)]"
197+
# First, look for test files directly in the test directory (non-recursive)
198+
$rootTestFiles = Get-ChildItem -Path $testDir -Filter *.Tests.ps1 -File
199+
Write-Output "Root level test files found in [$testDir]: [$($rootTestFiles.Count)]"
200+
201+
# Then, look for test files in subdirectories
202+
$subfolderTestFiles = Get-ChildItem -Path $testDir -Filter *.Tests.ps1 -Recurse -File |
203+
Where-Object { $_.DirectoryName -ne $testDir }
204+
Write-Output "Subfolder test files found in [$testDir]: [$($subfolderTestFiles.Count)]"
205+
206+
# Combine all test files using a generic List
207+
$testFiles = [System.Collections.Generic.List[System.IO.FileInfo]]::new()
208+
if ($rootTestFiles) {
209+
$rootTestFiles | ForEach-Object { $testFiles.Add($_) }
210+
}
211+
if ($subfolderTestFiles) {
212+
$subfolderTestFiles | ForEach-Object { $testFiles.Add($_) }
213+
}
214+
Write-Output "Total test files found in [$testDir]: [$($testFiles.Count)]"
215+
200216
foreach ($testFile in $testFiles) {
201217
$container = @{
202218
Path = $testFile.FullName
203219
}
220+
$containerFileName = ($testFile | Split-Path -Leaf).Replace('.Tests.ps1', '.Container.ps1')
204221
LogGroup "Init - Export containers - Generated - $containerFileName" {
205-
$containerFileName = ($testFile | Split-Path -Leaf).Replace('.Tests.ps1', '.Container.ps1')
206222
Write-Output "Exporting container [$path/$containerFileName]"
207223
Export-Hashtable -Hashtable $container -Path "$path/$containerFileName"
208224
}
209-
Write-Output "Containers created from test files: [$($containers.Count)]"
225+
$containers += $container
210226
}
227+
Write-Output "Containers created from test files: [$($containers.Count)]"
211228
}
212229
foreach ($containerFile in $containerFiles) {
213230
$container = Import-Hashtable $containerFile
@@ -217,6 +234,7 @@ LogGroup 'Init - Export containers' {
217234
Write-Output "Exporting container [$path/$containerFileName]"
218235
Export-Hashtable -Hashtable $container -Path "$path/$containerFileName"
219236
}
237+
$containers += $container
220238
}
221239
}
222240
$configuration.Run.Container = @()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"Not a testfile"

0 commit comments

Comments
 (0)