diff --git a/.github/linters/.powershell-psscriptanalyzer.psd1 b/.github/linters/.powershell-psscriptanalyzer.psd1 index 09cc3d0..b8e264a 100644 --- a/.github/linters/.powershell-psscriptanalyzer.psd1 +++ b/.github/linters/.powershell-psscriptanalyzer.psd1 @@ -51,6 +51,7 @@ } ExcludeRules = @( 'PSMissingModuleManifestField', # This rule is not applicable until the module is built. - 'PSUseToExportFieldsInManifest' + 'PSUseToExportFieldsInManifest', + "PSAvoidUsingWriteHost" # Write-Host works well in runners. ) } diff --git a/README.md b/README.md index 921d0ca..d109b4a 100644 --- a/README.md +++ b/README.md @@ -15,53 +15,54 @@ customize rule selection, severity filtering, and custom rule inclusion. ## Inputs -| Input | Description | Required | Default | -|--------------------------------------|--------------------------------------------------------------------------------|----------|-----------------------------------------------------------------------------| -| `Path` | The path to the code to test. | false | `'.'` | -| `SettingsFilePath` | The path to the settings file. | false | `.github/linters/.powershell-psscriptanalyzer.psd1` | -| `Debug` | Enable debug output. | false | `'false'` | -| `Verbose` | Enable verbose output. | false | `'false'` | -| `Version` | Specifies the exact version of the GitHub module to install. | false | | -| `Prerelease` | Allow prerelease versions if available. | false | `'false'` | -| `WorkingDirectory` | The working directory where the script runs. | false | `'.'` | -| `ReportAsJson` | Output generated reports in JSON format in addition to the configured format. | false | `'true'` | -| `StepSummary_Enabled` | Controls if a GitHub step summary should be shown. | false | `'true'` | -| `StepSummary_ShowTestOverview` | Controls whether to show the test overview table in the GitHub step summary. | false | `'true'` | -| `StepSummary_ShowTests` | Controls which tests to show in the GitHub step summary (Full/Failed/None). | false | `'Failed'` | -| `StepSummary_ShowConfiguration` | Controls whether to show the configuration details in the GitHub step summary. | false | `'false'` | -| `Run_ExcludePath` | Directories or files to be excluded from the run. | false | | -| `Run_Exit` | Exit with non-zero exit code when the test run fails. | false | | -| `Run_Throw` | Throw an exception when test run fails. | false | | -| `Run_SkipRun` | Runs the discovery phase but skips run. | false | | -| `Run_SkipRemainingOnFailure` | Skips remaining tests after failure (None/Run/Container/Block). | false | | -| `CodeCoverage_Enabled` | Enable CodeCoverage. | false | | -| `CodeCoverage_OutputFormat` | Format to use for code coverage report (JaCoCo/CoverageGutters/Cobertura). | false | | -| `CodeCoverage_OutputPath` | Path relative to the current directory where code coverage report is saved. | false | | -| `CodeCoverage_OutputEncoding` | Encoding of the output file. | false | | -| `CodeCoverage_Path` | Directories or files to be used for code coverage. | false | | -| `CodeCoverage_ExcludeTests` | Exclude tests from code coverage. | false | | -| `CodeCoverage_RecursePaths` | Will recurse through directories in the Path option. | false | | -| `CodeCoverage_CoveragePercentTarget` | Target percent of code coverage that you want to achieve. | false | | -| `CodeCoverage_UseBreakpoints` | EXPERIMENTAL: Use Profiler based tracer instead of breakpoints when false. | false | | -| `CodeCoverage_SingleHitBreakpoints` | Remove breakpoint when it is hit. | false | | -| `TestResult_Enabled` | Enable TestResult. | false | | -| `TestResult_OutputFormat` | Format to use for test result report (NUnitXml/NUnit2.5/NUnit3/JUnitXml). | false | | -| `TestResult_OutputPath` | Path relative to the current directory where test result report is saved. | false | | -| `TestResult_OutputEncoding` | Encoding of the output file. | false | | -| `TestResult_TestSuiteName` | Set the name assigned to the root 'test-suite' element. | false | `PSScriptAnalyzer` | -| `Should_ErrorAction` | Controls if Should throws on error. Use 'Stop' or 'Continue'. | false | | -| `Debug_ShowFullErrors` | Show full errors including Pester internal stack. | false | | -| `Debug_WriteDebugMessages` | Write Debug messages to screen. | false | | -| `Debug_WriteDebugMessagesFrom` | Write Debug messages from a given source. | false | | -| `Debug_ShowNavigationMarkers` | Write paths after every block and test, for easy navigation. | false | | -| `Debug_ReturnRawResultObject` | Returns unfiltered result object, for development only. | false | | -| `Output_Verbosity` | The verbosity of output (None/Normal/Detailed/Diagnostic). | false | | -| `Output_StackTraceVerbosity` | The verbosity of stacktrace output (None/FirstLine/Filtered/Full). | false | | -| `Output_CIFormat` | The CI format of error output (None/Auto/AzureDevops/GithubActions). | false | | -| `Output_CILogLevel` | The CI log level in build logs (Error/Warning). | false | | -| `Output_RenderMode` | The mode used to render console output (Auto/Ansi/ConsoleColor/Plaintext). | false | | -| `TestDrive_Enabled` | Enable TestDrive. | false | | -| `TestRegistry_Enabled` | Enable TestRegistry. | false | | +| Input | Description | Required | Default | +|--------------------------------------|--------------------------------------------------------------------------------|----------|-----------------------------------------------------| +| `Path` | The path to the code to test. | false | `'.'` | +| `SettingsFilePath` | The path to the settings file. | false | `.github/linters/.powershell-psscriptanalyzer.psd1` | +| `Debug` | Enable debug output. | false | `'false'` | +| `Verbose` | Enable verbose output. | false | `'false'` | +| `Version` | Specifies the exact version of the GitHub module to install. | false | | +| `Prerelease` | Allow prerelease versions if available. | false | `'false'` | +| `WorkingDirectory` | The working directory where the script runs. | false | `'.'` | +| `ReportAsJson` | Output generated reports in JSON format in addition to the configured format. | false | `'true'` | +| `Notice_Mode` | Controls when to show notices for test completion. | false | `'Failed'` | +| `StepSummary_Enabled` | Controls if a GitHub step summary should be shown. | false | `'true'` | +| `StepSummary_ShowTestOverview` | Controls whether to show the test overview table in the GitHub step summary. | false | `'true'` | +| `StepSummary_ShowTests` | Controls which tests to show in the GitHub step summary (Full/Failed/None). | false | `'Failed'` | +| `StepSummary_ShowConfiguration` | Controls whether to show the configuration details in the GitHub step summary. | false | `'false'` | +| `Run_ExcludePath` | Directories or files to be excluded from the run. | false | | +| `Run_Exit` | Exit with non-zero exit code when the test run fails. | false | | +| `Run_Throw` | Throw an exception when test run fails. | false | | +| `Run_SkipRun` | Runs the discovery phase but skips run. | false | | +| `Run_SkipRemainingOnFailure` | Skips remaining tests after failure (None/Run/Container/Block). | false | | +| `CodeCoverage_Enabled` | Enable CodeCoverage. | false | | +| `CodeCoverage_OutputFormat` | Format to use for code coverage report (JaCoCo/CoverageGutters/Cobertura). | false | | +| `CodeCoverage_OutputPath` | Path relative to the current directory where code coverage report is saved. | false | | +| `CodeCoverage_OutputEncoding` | Encoding of the output file. | false | | +| `CodeCoverage_Path` | Directories or files to be used for code coverage. | false | | +| `CodeCoverage_ExcludeTests` | Exclude tests from code coverage. | false | | +| `CodeCoverage_RecursePaths` | Will recurse through directories in the Path option. | false | | +| `CodeCoverage_CoveragePercentTarget` | Target percent of code coverage that you want to achieve. | false | | +| `CodeCoverage_UseBreakpoints` | EXPERIMENTAL: Use Profiler based tracer instead of breakpoints when false. | false | | +| `CodeCoverage_SingleHitBreakpoints` | Remove breakpoint when it is hit. | false | | +| `TestResult_Enabled` | Enable TestResult. | false | | +| `TestResult_OutputFormat` | Format to use for test result report (NUnitXml/NUnit2.5/NUnit3/JUnitXml). | false | | +| `TestResult_OutputPath` | Path relative to the current directory where test result report is saved. | false | | +| `TestResult_OutputEncoding` | Encoding of the output file. | false | | +| `TestResult_TestSuiteName` | Set the name assigned to the root 'test-suite' element. | false | `PSScriptAnalyzer` | +| `Should_ErrorAction` | Controls if Should throws on error. Use 'Stop' or 'Continue'. | false | | +| `Debug_ShowFullErrors` | Show full errors including Pester internal stack. | false | | +| `Debug_WriteDebugMessages` | Write Debug messages to screen. | false | | +| `Debug_WriteDebugMessagesFrom` | Write Debug messages from a given source. | false | | +| `Debug_ShowNavigationMarkers` | Write paths after every block and test, for easy navigation. | false | | +| `Debug_ReturnRawResultObject` | Returns unfiltered result object, for development only. | false | | +| `Output_Verbosity` | The verbosity of output (None/Normal/Detailed/Diagnostic). | false | | +| `Output_StackTraceVerbosity` | The verbosity of stacktrace output (None/FirstLine/Filtered/Full). | false | | +| `Output_CIFormat` | The CI format of error output (None/Auto/AzureDevops/GithubActions). | false | | +| `Output_CILogLevel` | The CI log level in build logs (Error/Warning). | false | | +| `Output_RenderMode` | The mode used to render console output (Auto/Ansi/ConsoleColor/Plaintext). | false | | +| `TestDrive_Enabled` | Enable TestDrive. | false | | +| `TestRegistry_Enabled` | Enable TestRegistry. | false | | ## Outputs diff --git a/action.yml b/action.yml index bdc803f..79c9988 100644 --- a/action.yml +++ b/action.yml @@ -37,6 +37,11 @@ inputs: Output generated reports in JSON format in addition to the configured format through Pester. required: false default: 'true' + 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_ShowTestOverview: description: | Controls whether to show the test overview table in the GitHub step summary. @@ -271,6 +276,7 @@ runs: Path: ${{ github.action_path }}/scripts/tests/PSScriptAnalyzer Run_Path: ${{ fromJson(steps.paths.outputs.result).CodePath }} ReportAsJson: ${{ inputs.ReportAsJson }} + Notice_Mode: ${{ inputs.Notice_Mode }} StepSummary_ShowTestOverview: ${{ inputs.StepSummary_ShowTestOverview }} StepSummary_Mode: ${{ inputs.StepSummary_Mode }} StepSummary_ShowConfiguration: ${{ inputs.StepSummary_ShowConfiguration }} diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 64410f1..4dac5f1 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -3,17 +3,19 @@ $testPath = Resolve-Path -Path "$PSScriptRoot/tests/PSScriptAnalyzer" | Select-O $path = [string]::IsNullOrEmpty($env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Path) ? '.' : $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Path $codePath = Resolve-Path -Path $path | Select-Object -ExpandProperty Path -# Try to resolve the settings file path, but allow it to be null if not found -[string]$settingsFilePath = '' -if (-not [string]::IsNullOrEmpty($env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath)) { - try { - $settingsFilePath = Resolve-Path -Path $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath -ErrorAction Stop | - Select-Object -ExpandProperty Path - Write-Information "Using settings file: $settingsFilePath" - } catch { - Write-Warning "Settings file not found at path: $($env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath). Using default settings." - } +Write-Host "List files:" +(Get-ChildItem -Path $pwd -Recurse -Force).FullName | Sort-Object + +Write-Host "Looking for settings file under $pwd" +$tmpSettingsFilePath = Join-Path -Path $pwd -ChildPath $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath +Write-Host "Checking: $tmpSettingsFilePath" +$settingsFileExists = Test-Path -Path $tmpSettingsFilePath +if ($settingsFileExists) { + $settingsFilePath = $tmpSettingsFilePath +} else { + $settingsFilePath = '' } +Write-Warning "Settings file not found at path: $($env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath). Using default settings." [pscustomobject]@{ CodePath = $codePath