From a565f453a7a7dfc5a88a564fd9c2f57ed73f70ae Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 12 Oct 2025 21:20:50 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A9=B9=20[Enhancement]:=20Add=20Notice=5F?= =?UTF-8?q?Mode=20input=20to=20control=20test=20completion=20notifications?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + action.yml | 6 ++++++ scripts/exec.ps1 | 17 ++++++++++++++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 314d19ce..3b378028 100644 --- a/README.md +++ b/README.md @@ -264,6 +264,7 @@ jobs: | `Path` | Path to where tests are located or a configuration file. | *(none)* | | `ReportAsJson` | Output generated reports in JSON format in addition to the configured format through Pester. | `true` | | `Prescript` | Script to be executed before the test run. This script is executed in the same context as the test run. | *(none)* | +| `Notice_Mode` | Controls when to show notices for test completion. Allows "Full" (show on success and failure), "Failed" (show only on failure), or "None" (disable notices). | `Failed` | | `StepSummary_Mode` | Controls which tests to show in the GitHub step summary. Allows "Full" (all tests), "Failed" (only failed tests), or "None" (disable step summary). | `Failed` | | `StepSummary_ShowTestOverview` | Controls whether to show the test overview table in the GitHub step summary. | `false` | | `StepSummary_ShowConfiguration` | Controls whether to show the configuration details in the GitHub step summary. | `false` | diff --git a/action.yml b/action.yml index 098b995e..edbcb22a 100644 --- a/action.yml +++ b/action.yml @@ -19,6 +19,11 @@ inputs: description: | Script to be executed before the test run. This script is executed in the same context as the test run. required: false + Notice_Mode: + description: | + Controls when to show notices for test completion. Allows "Full" (show on success and failure), "Failed" (show only on failure), or "None" (disable notices). + required: false + default: 'Failed' StepSummary_Mode: description: | Controls which tests to show in the GitHub step summary. Allows "Full" (show all tests), "Failed" (only failed tests), or "None" (disable step summary). @@ -344,6 +349,7 @@ runs: working-directory: ${{ inputs.WorkingDirectory }} env: PSMODULE_INVOKE_PESTER_INPUT_ReportAsJson: ${{ inputs.ReportAsJson }} + PSMODULE_INVOKE_PESTER_INPUT_Notice_Mode: ${{ inputs.Notice_Mode }} PSMODULE_INVOKE_PESTER_INPUT_StepSummary_Mode: ${{ inputs.StepSummary_Mode }} PSMODULE_INVOKE_PESTER_INPUT_StepSummary_ShowTestOverview: ${{ inputs.StepSummary_ShowTestOverview }} PSMODULE_INVOKE_PESTER_INPUT_StepSummary_ShowConfiguration: ${{ inputs.StepSummary_ShowConfiguration }} diff --git a/scripts/exec.ps1 b/scripts/exec.ps1 index c9b25b2e..5a2599b5 100644 --- a/scripts/exec.ps1 +++ b/scripts/exec.ps1 @@ -138,23 +138,34 @@ $codeCoverageOutputFolderPath = $testResults.Configuration.CodeCoverage.OutputPa "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' + $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' + $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') { - '::notice::✅ All tests 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