From af6bef38763ba605c16dcfd85e048ba7abc3c2bc Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 11 Oct 2025 18:31:32 +0200 Subject: [PATCH 01/13] =?UTF-8?q?=F0=9F=9A=80=20[Feature]:=20Enhance=20set?= =?UTF-8?q?tings=20file=20handling=20in=20Invoke-ScriptAnalyzer=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Action-Test.yml | 26 +++++++++ README.md | 35 ++++++++++-- scripts/main.ps1 | 22 ++++++-- .../PSScriptAnalyzer.Tests.ps1 | 54 ++++++++++++++----- tests/Get-AggregatedStatus.ps1 | 14 +++++ 5 files changed, 130 insertions(+), 21 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 1ee2812..93d2d30 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -89,6 +89,29 @@ jobs: Write-Host "Outcome: ${{ steps.action-test.outcome }}" Write-Host "Conclusion: ${{ steps.action-test.conclusion }}" + ActionTestSrcWithManifestDefault: + name: Action-Test - [Src-WithManifest-Default] + runs-on: ubuntu-latest + outputs: + Outcome: ${{ steps.action-test.outcome }} + Conclusion: ${{ steps.action-test.conclusion }} + steps: + - name: Checkout repo + uses: actions/checkout@v5 + + - name: Action-Test + uses: ./ + id: action-test + with: + Path: src + WorkingDirectory: tests/srcWithManifestTestRepo + + - name: Status + shell: pwsh + run: | + Write-Host "Outcome: ${{ steps.action-test.outcome }}" + Write-Host "Conclusion: ${{ steps.action-test.conclusion }}" + ActionTestOutputs: name: Action-Test - [outputs] runs-on: ubuntu-latest @@ -118,6 +141,7 @@ jobs: - ActionTestSrcSourceCode - ActionTestSrcCustom - ActionTestSrcWithManifest + - ActionTestSrcWithManifestDefault - ActionTestOutputs if: always() runs-on: ubuntu-latest @@ -128,6 +152,8 @@ jobs: ActionTestSrcCustomConclusion: ${{ needs.ActionTestSrcCustom.outputs.Conclusion }} ActionTestSrcWithManifestOutcome: ${{ needs.ActionTestSrcWithManifest.outputs.Outcome }} ActionTestSrcWithManifestConclusion: ${{ needs.ActionTestSrcWithManifest.outputs.Conclusion }} + ActionTestSrcWithManifestDefaultOutcome: ${{ needs.ActionTestSrcWithManifestDefault.outputs.Outcome }} + ActionTestSrcWithManifestDefaultConclusion: ${{ needs.ActionTestSrcWithManifestDefault.outputs.Conclusion }} ActionTestOutputsOutcome: ${{ needs.ActionTestOutputs.outputs.Outcome }} ActionTestOutputsConclusion: ${{ needs.ActionTestOutputs.outputs.Conclusion }} steps: diff --git a/README.md b/README.md index bd8f204..921d0ca 100644 --- a/README.md +++ b/README.md @@ -88,16 +88,41 @@ The action provides the following outputs: Choose a path for your code to test into the `Path` input. This can be a directory or a file. -2. **Configure settings file** +2. **Configure settings file (Optional)** Create a custom settings file to customize the analysis. The settings file is a hashtable that defines the rules to include, exclude, or customize. The settings file is in the format of a `.psd1` file. - By default, the action looks for a settings file at: - `.github/linters/.powershell-psscriptanalyzer.psd1` + **Settings File Precedence:** - You can override this by setting the `SettingsFilePath` input to point to your - custom settings file. + The action determines which settings to use in the following order: + + 1. **Custom Path**: If you provide a `SettingsFilePath` input, the action uses that file. + 2. **Default Action Path**: If no `SettingsFilePath` is provided, the action looks for a settings file at: + `.github/linters/.powershell-psscriptanalyzer.psd1` + 3. **PSScriptAnalyzer Defaults**: If no settings file is found in either location, the action uses + the default settings from the `Invoke-ScriptAnalyzer` cmdlet (all built-in rules with default severity). + + **Example configurations:** + + ```yaml + # Use a custom settings file + - uses: PSModule/Invoke-ScriptAnalyzer@v2 + with: + Path: src + SettingsFilePath: config/custom-rules.psd1 + + # Use the default action path (.github/linters/.powershell-psscriptanalyzer.psd1) + - uses: PSModule/Invoke-ScriptAnalyzer@v2 + with: + Path: src + + # Use PSScriptAnalyzer defaults (no settings file) + - uses: PSModule/Invoke-ScriptAnalyzer@v2 + with: + Path: src + SettingsFilePath: '' # Explicitly skip settings file + ``` For more info on how to create a settings file, see the [Settings Documentation](./Settings.md) file. diff --git a/scripts/main.ps1 b/scripts/main.ps1 index fd2ca24..35a75e1 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -2,7 +2,24 @@ $testPath = Resolve-Path -Path "$PSScriptRoot/tests/PSScriptAnalyzer" | Select-Object -ExpandProperty Path $path = [string]::IsNullOrEmpty($env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Path) ? '.' : $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Path $codePath = Resolve-Path -Path $path | Select-Object -ExpandProperty Path -$settingsFilePath = Resolve-Path -Path $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath | Select-Object -ExpandProperty Path + +# Try to resolve the settings file path, but allow it to be null if not found +$settingsFilePath = $null +if (-not [string]::IsNullOrEmpty($env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath)) { + try { + $resolvedPath = Resolve-Path -Path $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath -ErrorAction Stop | Select-Object -ExpandProperty Path + if (Test-Path -Path $resolvedPath) { + $settingsFilePath = $resolvedPath + Write-Information "Using settings file: $settingsFilePath" + } + } catch { + Write-Warning "Settings file not found at path: $($env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath). Using default settings." + } +} + +if ($null -eq $settingsFilePath) { + Write-Information 'No settings file specified or found. Using default PSScriptAnalyzer settings.' +} [pscustomobject]@{ CodePath = $codePath @@ -10,9 +27,6 @@ $settingsFilePath = Resolve-Path -Path $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT SettingsFilePath = $settingsFilePath } | Format-List | Out-String -if (!(Test-Path -Path $settingsFilePath)) { - throw "Settings file not found at path: $settingsFilePath" -} Set-GitHubOutput -Name CodePath -Value $codePath Set-GitHubOutput -Name TestPath -Value $testPath Set-GitHubOutput -Name SettingsFilePath -Value $settingsFilePath diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index d8298ed..f7d50fd 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -11,17 +11,25 @@ Justification = 'Write-Host is used for log output.' )] [CmdLetBinding()] -Param( +param( [Parameter(Mandatory)] [string] $Path, - [Parameter(Mandatory)] + [Parameter()] [string] $SettingsFilePath ) BeforeDiscovery { - LogGroup "PSScriptAnalyzer tests using settings file [$SettingsFilePath]" { - $settings = Import-PowerShellDataFile -Path $SettingsFilePath + $hasSettingsFile = -not [string]::IsNullOrEmpty($SettingsFilePath) + $settingsDescription = $hasSettingsFile ? "settings file [$SettingsFilePath]" : 'default settings' + + LogGroup "PSScriptAnalyzer tests using $settingsDescription" { + if ($hasSettingsFile) { + $settings = Import-PowerShellDataFile -Path $SettingsFilePath + } else { + $settings = @{} + } + $rules = [Collections.Generic.List[System.Collections.Specialized.OrderedDictionary]]::new() $ruleObjects = Get-ScriptAnalyzerRule -Verbose:$false | Sort-Object -Property Severity, CommonName $Severeties = $ruleObjects | Select-Object -ExpandProperty Severity -Unique @@ -65,13 +73,18 @@ BeforeDiscovery { Describe 'PSScriptAnalyzer' { BeforeAll { - $relativeSettingsFilePath = if ($SettingsFilePath.StartsWith($PSScriptRoot)) { - $SettingsFilePath.Replace($PSScriptRoot, 'Action:').Trim('\').Trim('/') - } elseif ($SettingsFilePath.StartsWith($env:GITHUB_WORKSPACE)) { - $SettingsFilePath.Replace($env:GITHUB_WORKSPACE, 'Workspace:').Trim('\').Trim('/') - } else { - $SettingsFilePath + $hasSettingsFile = -not [string]::IsNullOrEmpty($SettingsFilePath) + + if ($hasSettingsFile) { + $relativeSettingsFilePath = if ($SettingsFilePath.StartsWith($PSScriptRoot)) { + $SettingsFilePath.Replace($PSScriptRoot, 'Action:').Trim('\').Trim('/') + } elseif ($SettingsFilePath.StartsWith($env:GITHUB_WORKSPACE)) { + $SettingsFilePath.Replace($env:GITHUB_WORKSPACE, 'Workspace:').Trim('\').Trim('/') + } else { + $SettingsFilePath + } } + $Path = Resolve-Path -Path $Path | Select-Object -ExpandProperty Path $relativePath = if ($Path.StartsWith($PSScriptRoot)) { $Path.Replace($PSScriptRoot, 'Action:').Trim('\').Trim('/').Replace('\', '/') @@ -88,9 +101,26 @@ Describe 'PSScriptAnalyzer' { GITHUB_WORKSPACE = $env:GITHUB_WORKSPACE } - LogGroup "Invoke-ScriptAnalyzer -Path [$relativePath] -Settings [$relativeSettingsFilePath]" { - $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose + $invokeParams = @{ + Path = $Path + Recurse = $true + Verbose = $true + } + + if ($hasSettingsFile) { + $invokeParams['Settings'] = $SettingsFilePath } + + $logMessage = if ($hasSettingsFile) { + "Invoke-ScriptAnalyzer -Path [$relativePath] -Settings [$relativeSettingsFilePath]" + } else { + "Invoke-ScriptAnalyzer -Path [$relativePath] -Recurse (using default settings)" + } + + LogGroup $logMessage { + $testResults = Invoke-ScriptAnalyzer @invokeParams + } + LogGroup "TestResults [$($testResults.Count)]" { $testResults | Select-Object -Property * | Format-List | Out-String -Stream | ForEach-Object { Write-Verbose $_ -Verbose diff --git a/tests/Get-AggregatedStatus.ps1 b/tests/Get-AggregatedStatus.ps1 index d96cc5a..dd6c57f 100644 --- a/tests/Get-AggregatedStatus.ps1 +++ b/tests/Get-AggregatedStatus.ps1 @@ -35,6 +35,11 @@ $ActionTestSrcWithManifestOutcomeResult = $env:ActionTestSrcWithManifestOutcome $ActionTestSrcWithManifestExpectedConclusion = 'success' $ActionTestSrcWithManifestConclusionResult = $env:ActionTestSrcWithManifestConclusion -eq $ActionTestSrcWithManifestExpectedConclusion +$ActionTestSrcWithManifestDefaultExpectedOutcome = 'success' +$ActionTestSrcWithManifestDefaultOutcomeResult = $env:ActionTestSrcWithManifestDefaultOutcome -eq $ActionTestSrcWithManifestDefaultExpectedOutcome +$ActionTestSrcWithManifestDefaultExpectedConclusion = 'success' +$ActionTestSrcWithManifestDefaultConclusionResult = $env:ActionTestSrcWithManifestDefaultConclusion -eq $ActionTestSrcWithManifestDefaultExpectedConclusion + $ActionTestOutputsExpectedOutcome = 'success' $ActionTestOutputsOutcomeResult = $env:ActionTestOutputsOutcome -eq $ActionTestOutputsExpectedOutcome $ActionTestOutputsExpectedConclusion = 'success' @@ -68,6 +73,15 @@ $jobs = @( ExpectedConclusion = $ActionTestSrcWithManifestExpectedConclusion PassedConclusion = $ActionTestSrcWithManifestConclusionResult }, + [PSCustomObject]@{ + Name = 'Action-Test - [Src-WithManifest-Default]' + Outcome = $env:ActionTestSrcWithManifestDefaultOutcome + ExpectedOutcome = $ActionTestSrcWithManifestDefaultExpectedOutcome + PassedOutcome = $ActionTestSrcWithManifestDefaultOutcomeResult + Conclusion = $env:ActionTestSrcWithManifestDefaultConclusion + ExpectedConclusion = $ActionTestSrcWithManifestDefaultExpectedConclusion + PassedConclusion = $ActionTestSrcWithManifestDefaultConclusionResult + }, [PSCustomObject]@{ Name = 'Action-Test - [outputs]' Outcome = $env:ActionTestOutputsOutcome From 53bd7f4d19d482fd244f32896867e74387a376a3 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 11 Oct 2025 18:55:46 +0200 Subject: [PATCH 02/13] Update scripts/main.ps1 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- scripts/main.ps1 | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 35a75e1..e0452f9 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -8,10 +8,8 @@ $settingsFilePath = $null if (-not [string]::IsNullOrEmpty($env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath)) { try { $resolvedPath = Resolve-Path -Path $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath -ErrorAction Stop | Select-Object -ExpandProperty Path - if (Test-Path -Path $resolvedPath) { - $settingsFilePath = $resolvedPath - Write-Information "Using settings file: $settingsFilePath" - } + $settingsFilePath = $resolvedPath + Write-Information "Using settings file: $settingsFilePath" } catch { Write-Warning "Settings file not found at path: $($env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath). Using default settings." } From 3c113d402580ade7cfe8b28e9f5e0766266c22ae Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 11 Oct 2025 18:57:52 +0200 Subject: [PATCH 03/13] Update scripts/main.ps1 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- scripts/main.ps1 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index e0452f9..366ecfa 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -7,8 +7,7 @@ $codePath = Resolve-Path -Path $path | Select-Object -ExpandProperty Path $settingsFilePath = $null if (-not [string]::IsNullOrEmpty($env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath)) { try { - $resolvedPath = Resolve-Path -Path $env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath -ErrorAction Stop | Select-Object -ExpandProperty Path - $settingsFilePath = $resolvedPath + $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." From 3cba608880ad4404fa361d1651e6836c582240d1 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 11 Oct 2025 19:30:06 +0200 Subject: [PATCH 04/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Output=20empty?= =?UTF-8?q?=20string=20instead=20of=20null=20for=20SettingsFilePath=20to?= =?UTF-8?q?=20prevent=20GitHub=20Actions=20from=20interpreting=20null=20as?= =?UTF-8?q?=20"null"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/main.ps1 | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 366ecfa..45f9e3b 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -26,4 +26,5 @@ if ($null -eq $settingsFilePath) { Set-GitHubOutput -Name CodePath -Value $codePath Set-GitHubOutput -Name TestPath -Value $testPath -Set-GitHubOutput -Name SettingsFilePath -Value $settingsFilePath +# Output empty string instead of null to avoid GitHub Actions converting null to the string "null" +Set-GitHubOutput -Name SettingsFilePath -Value ($null -eq $settingsFilePath ? '' : $settingsFilePath) From 2b77ba0cac5a8d7ea1cc278dbc3717fa9eeb4d1e Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 11 Oct 2025 19:38:19 +0200 Subject: [PATCH 05/13] =?UTF-8?q?=F0=9F=9A=80=20[Feature]:=20Update=20Invo?= =?UTF-8?q?ke-ScriptAnalyzer=20to=20output=20empty=20string=20for=20Settin?= =?UTF-8?q?gsFilePath=20and=20enhance=20logging=20in=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/main.ps1 | 1 - scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 45f9e3b..f9e7478 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -26,5 +26,4 @@ if ($null -eq $settingsFilePath) { Set-GitHubOutput -Name CodePath -Value $codePath Set-GitHubOutput -Name TestPath -Value $testPath -# Output empty string instead of null to avoid GitHub Actions converting null to the string "null" Set-GitHubOutput -Name SettingsFilePath -Value ($null -eq $settingsFilePath ? '' : $settingsFilePath) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index f7d50fd..c2b8ade 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -104,7 +104,6 @@ Describe 'PSScriptAnalyzer' { $invokeParams = @{ Path = $Path Recurse = $true - Verbose = $true } if ($hasSettingsFile) { @@ -112,7 +111,7 @@ Describe 'PSScriptAnalyzer' { } $logMessage = if ($hasSettingsFile) { - "Invoke-ScriptAnalyzer -Path [$relativePath] -Settings [$relativeSettingsFilePath]" + "Invoke-ScriptAnalyzer -Path [$relativePath] -Recurse -Settings [$relativeSettingsFilePath]" } else { "Invoke-ScriptAnalyzer -Path [$relativePath] -Recurse (using default settings)" } From 80910d4e18cf4c65f7762d2f3b2c95fba2f2503a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 11 Oct 2025 19:44:06 +0200 Subject: [PATCH 06/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20log=20?= =?UTF-8?q?message=20formatting=20in=20PSScriptAnalyzer=20tests=20for=20co?= =?UTF-8?q?nsistency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index c2b8ade..daed804 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -111,9 +111,9 @@ Describe 'PSScriptAnalyzer' { } $logMessage = if ($hasSettingsFile) { - "Invoke-ScriptAnalyzer -Path [$relativePath] -Recurse -Settings [$relativeSettingsFilePath]" + "Invoke-ScriptAnalyzer -Path '$relativePath' -Recurse -Settings '$relativeSettingsFilePath'" } else { - "Invoke-ScriptAnalyzer -Path [$relativePath] -Recurse (using default settings)" + "Invoke-ScriptAnalyzer -Path '$relativePath' -Recurse (using default settings)" } LogGroup $logMessage { From 9abfd714373656f65405f91df69cc88f26e73201 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 11 Oct 2025 19:55:37 +0200 Subject: [PATCH 07/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20Action?= =?UTF-8?q?-Test=20workflow=20to=20continue=20on=20error=20and=20adjust=20?= =?UTF-8?q?expected=20outcome=20for=20default=20manifest=20test?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Action-Test.yml | 5 ++--- tests/Get-AggregatedStatus.ps1 | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 93d2d30..cd9213e 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -101,6 +101,7 @@ jobs: - name: Action-Test uses: ./ + continue-on-error: true id: action-test with: Path: src @@ -163,6 +164,4 @@ jobs: - name: Aggregated Status uses: PSModule/Github-Script@v1 with: - Script: | - # Aggregated Status - tests/Get-AggregatedStatus.ps1 + Script: tests/Get-AggregatedStatus.ps1 diff --git a/tests/Get-AggregatedStatus.ps1 b/tests/Get-AggregatedStatus.ps1 index dd6c57f..90dc2e4 100644 --- a/tests/Get-AggregatedStatus.ps1 +++ b/tests/Get-AggregatedStatus.ps1 @@ -35,7 +35,7 @@ $ActionTestSrcWithManifestOutcomeResult = $env:ActionTestSrcWithManifestOutcome $ActionTestSrcWithManifestExpectedConclusion = 'success' $ActionTestSrcWithManifestConclusionResult = $env:ActionTestSrcWithManifestConclusion -eq $ActionTestSrcWithManifestExpectedConclusion -$ActionTestSrcWithManifestDefaultExpectedOutcome = 'success' +$ActionTestSrcWithManifestDefaultExpectedOutcome = 'failure' $ActionTestSrcWithManifestDefaultOutcomeResult = $env:ActionTestSrcWithManifestDefaultOutcome -eq $ActionTestSrcWithManifestDefaultExpectedOutcome $ActionTestSrcWithManifestDefaultExpectedConclusion = 'success' $ActionTestSrcWithManifestDefaultConclusionResult = $env:ActionTestSrcWithManifestDefaultConclusion -eq $ActionTestSrcWithManifestDefaultExpectedConclusion From b013966122128be463750375d2d1ec31d0cb9588 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 11 Oct 2025 20:02:49 +0200 Subject: [PATCH 08/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Ensure=20Settin?= =?UTF-8?q?gsFilePath=20is=20set=20to=20an=20empty=20string=20when=20not?= =?UTF-8?q?=20provided=20and=20update=20output=20accordingly?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/main.ps1 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index f9e7478..7cc53c5 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -12,6 +12,8 @@ if (-not [string]::IsNullOrEmpty($env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Setti } catch { Write-Warning "Settings file not found at path: $($env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath). Using default settings." } +} else { + $settingsFilePath = '' } if ($null -eq $settingsFilePath) { @@ -26,4 +28,4 @@ if ($null -eq $settingsFilePath) { Set-GitHubOutput -Name CodePath -Value $codePath Set-GitHubOutput -Name TestPath -Value $testPath -Set-GitHubOutput -Name SettingsFilePath -Value ($null -eq $settingsFilePath ? '' : $settingsFilePath) +Set-GitHubOutput -Name SettingsFilePath -Value $settingsFilePath From a2762b4eac6497f1ae1e0aec54b3e581bab5f8c9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 11 Oct 2025 20:10:34 +0200 Subject: [PATCH 09/13] Update scripts/main.ps1 Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- scripts/main.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 7cc53c5..8c1119e 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -16,7 +16,7 @@ if (-not [string]::IsNullOrEmpty($env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Setti $settingsFilePath = '' } -if ($null -eq $settingsFilePath) { +if ([string]::IsNullOrEmpty($settingsFilePath)) { Write-Information 'No settings file specified or found. Using default PSScriptAnalyzer settings.' } From 90ed94c99204a10adff04e21e123d11146737fe7 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 11 Oct 2025 20:22:19 +0200 Subject: [PATCH 10/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20vari?= =?UTF-8?q?able=20names=20for=20clarity=20in=20Get-AggregatedStatus=20test?= =?UTF-8?q?s=20and=20improve=20settings=20file=20path=20handling=20in=20In?= =?UTF-8?q?voke-ScriptAnalyzer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/main.ps1 | 3 +- tests/Get-AggregatedStatus.ps1 | 80 +++++++++++++++++----------------- 2 files changed, 42 insertions(+), 41 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index 7cc53c5..483144d 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -7,7 +7,8 @@ $codePath = Resolve-Path -Path $path | Select-Object -ExpandProperty Path $settingsFilePath = $null 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 + $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." diff --git a/tests/Get-AggregatedStatus.ps1 b/tests/Get-AggregatedStatus.ps1 index 90dc2e4..f9dd08b 100644 --- a/tests/Get-AggregatedStatus.ps1 +++ b/tests/Get-AggregatedStatus.ps1 @@ -20,25 +20,25 @@ } # Build an array of objects for each job -$ActionTestSrcSourceCodeExpectedOutcome = 'success' -$ActionTestSrcSourceCodeOutcomeResult = $env:ActionTestSrcSourceCodeOutcome -eq $ActionTestSrcSourceCodeExpectedOutcome -$ActionTestSrcSourceCodeExpectedConclusion = 'success' -$ActionTestSrcSourceCodeConclusionResult = $env:ActionTestSrcSourceCodeConclusion -eq $ActionTestSrcSourceCodeExpectedConclusion +$SourceCodeExpectedOutcome = 'success' +$SourceCodeOutcomeResult = $env:SourceCodeOutcome -eq $SourceCodeExpectedOutcome +$SourceCodeExpectedConclusion = 'success' +$SourceCodeConclusionResult = $env:SourceCodeConclusion -eq $SourceCodeExpectedConclusion -$ActionTestSrcCustomExpectedOutcome = 'success' -$ActionTestSrcCustomOutcomeResult = $env:ActionTestSrcCustomOutcome -eq $ActionTestSrcCustomExpectedOutcome -$ActionTestSrcCustomExpectedConclusion = 'success' -$ActionTestSrcCustomConclusionResult = $env:ActionTestSrcCustomConclusion -eq $ActionTestSrcCustomExpectedConclusion +$CustomExpectedOutcome = 'success' +$CustomOutcomeResult = $env:CustomOutcome -eq $CustomExpectedOutcome +$CustomExpectedConclusion = 'success' +$CustomConclusionResult = $env:CustomConclusion -eq $CustomExpectedConclusion -$ActionTestSrcWithManifestExpectedOutcome = 'failure' -$ActionTestSrcWithManifestOutcomeResult = $env:ActionTestSrcWithManifestOutcome -eq $ActionTestSrcWithManifestExpectedOutcome -$ActionTestSrcWithManifestExpectedConclusion = 'success' -$ActionTestSrcWithManifestConclusionResult = $env:ActionTestSrcWithManifestConclusion -eq $ActionTestSrcWithManifestExpectedConclusion +$WithManifestExpectedOutcome = 'failure' +$WithManifestOutcomeResult = $env:WithManifestOutcome -eq $WithManifestExpectedOutcome +$WithManifestExpectedConclusion = 'success' +$WithManifestConclusionResult = $env:WithManifestConclusion -eq $WithManifestExpectedConclusion -$ActionTestSrcWithManifestDefaultExpectedOutcome = 'failure' -$ActionTestSrcWithManifestDefaultOutcomeResult = $env:ActionTestSrcWithManifestDefaultOutcome -eq $ActionTestSrcWithManifestDefaultExpectedOutcome -$ActionTestSrcWithManifestDefaultExpectedConclusion = 'success' -$ActionTestSrcWithManifestDefaultConclusionResult = $env:ActionTestSrcWithManifestDefaultConclusion -eq $ActionTestSrcWithManifestDefaultExpectedConclusion +$WithManifestDefaultExpectedOutcome = 'failure' +$WithManifestDefaultOutcomeResult = $env:WithManifestDefaultOutcome -eq $WithManifestDefaultExpectedOutcome +$WithManifestDefaultExpectedConclusion = 'success' +$WithManifestDefaultConclusionResult = $env:WithManifestDefaultConclusion -eq $WithManifestDefaultExpectedConclusion $ActionTestOutputsExpectedOutcome = 'success' $ActionTestOutputsOutcomeResult = $env:ActionTestOutputsOutcome -eq $ActionTestOutputsExpectedOutcome @@ -48,39 +48,39 @@ $ActionTestOutputsConclusionResult = $env:ActionTestOutputsConclusion -eq $Actio $jobs = @( [PSCustomObject]@{ Name = 'Action-Test - [Src-SourceCode]' - Outcome = $env:ActionTestSrcSourceCodeOutcome - ExpectedOutcome = $ActionTestSrcSourceCodeExpectedOutcome - PassedOutcome = $ActionTestSrcSourceCodeOutcomeResult - Conclusion = $env:ActionTestSrcSourceCodeConclusion - ExpectedConclusion = $ActionTestSrcSourceCodeExpectedConclusion - PassedConclusion = $ActionTestSrcSourceCodeConclusionResult + Outcome = $env:SourceCodeOutcome + ExpectedOutcome = $SourceCodeExpectedOutcome + PassedOutcome = $SourceCodeOutcomeResult + Conclusion = $env:SourceCodeConclusion + ExpectedConclusion = $SourceCodeExpectedConclusion + PassedConclusion = $SourceCodeConclusionResult }, [PSCustomObject]@{ Name = 'Action-Test - [Src-Custom]' - Outcome = $env:ActionTestSrcCustomOutcome - ExpectedOutcome = $ActionTestSrcCustomExpectedOutcome - PassedOutcome = $ActionTestSrcCustomOutcomeResult - Conclusion = $env:ActionTestSrcCustomConclusion - ExpectedConclusion = $ActionTestSrcCustomExpectedConclusion - PassedConclusion = $ActionTestSrcCustomConclusionResult + Outcome = $env:CustomOutcome + ExpectedOutcome = $CustomExpectedOutcome + PassedOutcome = $CustomOutcomeResult + Conclusion = $env:CustomConclusion + ExpectedConclusion = $CustomExpectedConclusion + PassedConclusion = $CustomConclusionResult }, [PSCustomObject]@{ Name = 'Action-Test - [Src-WithManifest]' - Outcome = $env:ActionTestSrcWithManifestOutcome - ExpectedOutcome = $ActionTestSrcWithManifestExpectedOutcome - PassedOutcome = $ActionTestSrcWithManifestOutcomeResult - Conclusion = $env:ActionTestSrcWithManifestConclusion - ExpectedConclusion = $ActionTestSrcWithManifestExpectedConclusion - PassedConclusion = $ActionTestSrcWithManifestConclusionResult + Outcome = $env:WithManifestOutcome + ExpectedOutcome = $WithManifestExpectedOutcome + PassedOutcome = $WithManifestOutcomeResult + Conclusion = $env:WithManifestConclusion + ExpectedConclusion = $WithManifestExpectedConclusion + PassedConclusion = $WithManifestConclusionResult }, [PSCustomObject]@{ Name = 'Action-Test - [Src-WithManifest-Default]' - Outcome = $env:ActionTestSrcWithManifestDefaultOutcome - ExpectedOutcome = $ActionTestSrcWithManifestDefaultExpectedOutcome - PassedOutcome = $ActionTestSrcWithManifestDefaultOutcomeResult - Conclusion = $env:ActionTestSrcWithManifestDefaultConclusion - ExpectedConclusion = $ActionTestSrcWithManifestDefaultExpectedConclusion - PassedConclusion = $ActionTestSrcWithManifestDefaultConclusionResult + Outcome = $env:WithManifestDefaultOutcome + ExpectedOutcome = $WithManifestDefaultExpectedOutcome + PassedOutcome = $WithManifestDefaultOutcomeResult + Conclusion = $env:WithManifestDefaultConclusion + ExpectedConclusion = $WithManifestDefaultExpectedConclusion + PassedConclusion = $WithManifestDefaultConclusionResult }, [PSCustomObject]@{ Name = 'Action-Test - [outputs]' From ca0ea5e797a09cb5bf0da04a1bf86efff1d4ba7b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 11 Oct 2025 20:31:32 +0200 Subject: [PATCH 11/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20workfl?= =?UTF-8?q?ows=20to=20disable=20credential=20persistence=20for=20better=20?= =?UTF-8?q?security?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Action-Test.yml | 12 ++++++++++++ .github/workflows/Auto-Release.yml | 2 ++ .github/workflows/Linter.yml | 4 ++++ 3 files changed, 18 insertions(+) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index cd9213e..e10d913 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -26,6 +26,8 @@ jobs: steps: - name: Checkout repo uses: actions/checkout@v5 + with: + persist-credentials: false - name: Action-Test uses: ./ @@ -49,6 +51,8 @@ jobs: steps: - name: Checkout repo uses: actions/checkout@v5 + with: + persist-credentials: false - name: Action-Test uses: ./ @@ -73,6 +77,8 @@ jobs: steps: - name: Checkout repo uses: actions/checkout@v5 + with: + persist-credentials: false - name: Action-Test uses: ./ @@ -98,6 +104,8 @@ jobs: steps: - name: Checkout repo uses: actions/checkout@v5 + with: + persist-credentials: false - name: Action-Test uses: ./ @@ -122,6 +130,8 @@ jobs: steps: - name: Checkout repo uses: actions/checkout@v5 + with: + persist-credentials: false - name: Action-Test uses: ./ @@ -160,6 +170,8 @@ jobs: steps: - name: Checkout repo uses: actions/checkout@v5 + with: + persist-credentials: false - name: Aggregated Status uses: PSModule/Github-Script@v1 diff --git a/.github/workflows/Auto-Release.yml b/.github/workflows/Auto-Release.yml index 50a5a41..502e551 100644 --- a/.github/workflows/Auto-Release.yml +++ b/.github/workflows/Auto-Release.yml @@ -27,6 +27,8 @@ jobs: steps: - name: Checkout Code uses: actions/checkout@v5 + with: + persist-credentials: false - name: Auto-Release uses: PSModule/Auto-Release@v1 diff --git a/.github/workflows/Linter.yml b/.github/workflows/Linter.yml index 8291fcd..90050d4 100644 --- a/.github/workflows/Linter.yml +++ b/.github/workflows/Linter.yml @@ -21,6 +21,7 @@ jobs: - name: Checkout repo uses: actions/checkout@v5 with: + persist-credentials: false fetch-depth: 0 - name: Lint code base @@ -30,4 +31,7 @@ jobs: VALIDATE_JSON_PRETTIER: false VALIDATE_MARKDOWN_PRETTIER: false VALIDATE_YAML_PRETTIER: false + VALIDATE_BIOME_FORMAT: false + VALIDATE_BIOME_LINT: false + VALIDATE_GITHUB_ACTIONS_ZIZMOR: false FILTER_REGEX_EXCLUDE: '.*Set-PSModuleTest\.ps1$' From 846a33ff4fbb8c72427b336945886de89ff915c8 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 11 Oct 2025 20:41:45 +0200 Subject: [PATCH 12/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Initialize=20se?= =?UTF-8?q?ttingsFilePath=20as=20an=20empty=20string=20and=20remove=20redu?= =?UTF-8?q?ndant=20checks=20for=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/main.ps1 | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/scripts/main.ps1 b/scripts/main.ps1 index a997e13..64410f1 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -4,7 +4,7 @@ $path = [string]::IsNullOrEmpty($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 -$settingsFilePath = $null +[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 | @@ -13,12 +13,6 @@ if (-not [string]::IsNullOrEmpty($env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_Setti } catch { Write-Warning "Settings file not found at path: $($env:PSMODULE_INVOKE_SCRIPTANALYZER_INPUT_SettingsFilePath). Using default settings." } -} else { - $settingsFilePath = '' -} - -if ([string]::IsNullOrEmpty($settingsFilePath)) { - Write-Information 'No settings file specified or found. Using default PSScriptAnalyzer settings.' } [pscustomobject]@{ From d5d218ef08ff57084e1a8c3d14ba13b177806b84 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sat, 11 Oct 2025 20:50:54 +0200 Subject: [PATCH 13/13] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Simplify=20envi?= =?UTF-8?q?ronment=20variable=20names=20in=20Action-Test=20workflow=20and?= =?UTF-8?q?=20related=20tests=20for=20consistency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Action-Test.yml | 20 ++++++++++---------- tests/Get-AggregatedStatus.ps1 | 20 ++++++++++---------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index e10d913..8b48a56 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -157,16 +157,16 @@ jobs: if: always() runs-on: ubuntu-latest env: - ActionTestSrcSourceCodeOutcome: ${{ needs.ActionTestSrcSourceCode.outputs.Outcome }} - ActionTestSrcSourceCodeConclusion: ${{ needs.ActionTestSrcSourceCode.outputs.Conclusion }} - ActionTestSrcCustomOutcome: ${{ needs.ActionTestSrcCustom.outputs.Outcome }} - ActionTestSrcCustomConclusion: ${{ needs.ActionTestSrcCustom.outputs.Conclusion }} - ActionTestSrcWithManifestOutcome: ${{ needs.ActionTestSrcWithManifest.outputs.Outcome }} - ActionTestSrcWithManifestConclusion: ${{ needs.ActionTestSrcWithManifest.outputs.Conclusion }} - ActionTestSrcWithManifestDefaultOutcome: ${{ needs.ActionTestSrcWithManifestDefault.outputs.Outcome }} - ActionTestSrcWithManifestDefaultConclusion: ${{ needs.ActionTestSrcWithManifestDefault.outputs.Conclusion }} - ActionTestOutputsOutcome: ${{ needs.ActionTestOutputs.outputs.Outcome }} - ActionTestOutputsConclusion: ${{ needs.ActionTestOutputs.outputs.Conclusion }} + SourceCodeOutcome: ${{ needs.ActionTestSrcSourceCode.outputs.Outcome }} + SourceCodeConclusion: ${{ needs.ActionTestSrcSourceCode.outputs.Conclusion }} + CustomOutcome: ${{ needs.ActionTestSrcCustom.outputs.Outcome }} + CustomConclusion: ${{ needs.ActionTestSrcCustom.outputs.Conclusion }} + WithManifestOutcome: ${{ needs.ActionTestSrcWithManifest.outputs.Outcome }} + WithManifestConclusion: ${{ needs.ActionTestSrcWithManifest.outputs.Conclusion }} + WithManifestDefaultOutcome: ${{ needs.ActionTestSrcWithManifestDefault.outputs.Outcome }} + WithManifestDefaultConclusion: ${{ needs.ActionTestSrcWithManifestDefault.outputs.Conclusion }} + OutputsOutcome: ${{ needs.ActionTestOutputs.outputs.Outcome }} + OutputsConclusion: ${{ needs.ActionTestOutputs.outputs.Conclusion }} steps: - name: Checkout repo uses: actions/checkout@v5 diff --git a/tests/Get-AggregatedStatus.ps1 b/tests/Get-AggregatedStatus.ps1 index f9dd08b..0f12daf 100644 --- a/tests/Get-AggregatedStatus.ps1 +++ b/tests/Get-AggregatedStatus.ps1 @@ -40,10 +40,10 @@ $WithManifestDefaultOutcomeResult = $env:WithManifestDefaultOutcome -eq $WithMan $WithManifestDefaultExpectedConclusion = 'success' $WithManifestDefaultConclusionResult = $env:WithManifestDefaultConclusion -eq $WithManifestDefaultExpectedConclusion -$ActionTestOutputsExpectedOutcome = 'success' -$ActionTestOutputsOutcomeResult = $env:ActionTestOutputsOutcome -eq $ActionTestOutputsExpectedOutcome -$ActionTestOutputsExpectedConclusion = 'success' -$ActionTestOutputsConclusionResult = $env:ActionTestOutputsConclusion -eq $ActionTestOutputsExpectedConclusion +$OutputsExpectedOutcome = 'success' +$OutputsOutcomeResult = $env:OutputsOutcome -eq $OutputsExpectedOutcome +$OutputsExpectedConclusion = 'success' +$OutputsConclusionResult = $env:OutputsConclusion -eq $OutputsExpectedConclusion $jobs = @( [PSCustomObject]@{ @@ -84,12 +84,12 @@ $jobs = @( }, [PSCustomObject]@{ Name = 'Action-Test - [outputs]' - Outcome = $env:ActionTestOutputsOutcome - ExpectedOutcome = $ActionTestOutputsExpectedOutcome - PassedOutcome = $ActionTestOutputsOutcomeResult - Conclusion = $env:ActionTestOutputsConclusion - ExpectedConclusion = $ActionTestOutputsExpectedConclusion - PassedConclusion = $ActionTestOutputsConclusionResult + Outcome = $env:OutputsOutcome + ExpectedOutcome = $OutputsExpectedOutcome + PassedOutcome = $OutputsOutcomeResult + Conclusion = $env:OutputsConclusion + ExpectedConclusion = $OutputsExpectedConclusion + PassedConclusion = $OutputsConclusionResult } )