From aaf62a20c3261f5c86c3575ffffed224b160c869 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 17:50:14 +0100 Subject: [PATCH 01/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20unused?= =?UTF-8?q?=20outputs=20and=20update=20Invoke-Pester=20to=20v3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- action.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/action.yml b/action.yml index 29b5579..e8bfe3d 100644 --- a/action.yml +++ b/action.yml @@ -19,11 +19,6 @@ inputs: required: false default: ${{ github.workspace }}/.github/linters/.powershell-psscriptanalyzer.psd1 -outputs: - passed: - description: If the tests passed. - value: ${{ steps.test.outputs.Passed }} - runs: using: composite steps: @@ -38,7 +33,7 @@ runs: Script: ${{ github.action_path }}/scripts/main.ps1 - name: Invoke-Pester - uses: PSModule/Invoke-Pester@v2 + uses: PSModule/Invoke-Pester@v3 id: test env: Settings: ${{ fromJson(steps.paths.outputs.result).Settings }} From 446940deb428891756e2b3327b23fe2371f9df0a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 18:04:20 +0100 Subject: [PATCH 02/32] =?UTF-8?q?=F0=9F=8C=9F=20[Major]:=20Consolidate=20A?= =?UTF-8?q?ction-Test=20workflows=20into=20a=20single=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Action-Test-Src-Default-Custom.yml | 24 --------- .github/workflows/Action-Test-Src-Default.yml | 23 --------- .../Action-Test-Src-WithManifest.yml | 23 --------- .github/workflows/Action-Test-outputs.yml | 23 --------- .github/workflows/Action-Test.yml | 51 +++++++++++++++++++ .github/workflows/ActionTestWorkflow.yml | 13 ++--- 6 files changed, 54 insertions(+), 103 deletions(-) delete mode 100644 .github/workflows/Action-Test-Src-Default-Custom.yml delete mode 100644 .github/workflows/Action-Test-Src-Default.yml delete mode 100644 .github/workflows/Action-Test-Src-WithManifest.yml delete mode 100644 .github/workflows/Action-Test-outputs.yml create mode 100644 .github/workflows/Action-Test.yml diff --git a/.github/workflows/Action-Test-Src-Default-Custom.yml b/.github/workflows/Action-Test-Src-Default-Custom.yml deleted file mode 100644 index e89fa3b..0000000 --- a/.github/workflows/Action-Test-Src-Default-Custom.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Action-Test [Src-Default-Custom] - -run-name: "Action-Test [Src-Default-Custom] - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}" - -on: - workflow_dispatch: - pull_request: - schedule: - - cron: '0 0 * * *' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -permissions: {} - -jobs: - ActionTestCustom: - uses: ./.github/workflows/ActionTestWorkflow.yml - with: - TestType: Src-Default-Custom - Path: tests/srcTestRepo/src - Settings: Custom - SettingsFilePath: tests/srcTestRepo/tests/Custom.Settings.psd1 diff --git a/.github/workflows/Action-Test-Src-Default.yml b/.github/workflows/Action-Test-Src-Default.yml deleted file mode 100644 index 7896cc0..0000000 --- a/.github/workflows/Action-Test-Src-Default.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Action-Test [Src-Default] - -run-name: "Action-Test [Src-Default] - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}" - -on: - workflow_dispatch: - pull_request: - schedule: - - cron: '0 0 * * *' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -permissions: {} - -jobs: - ActionTest: - uses: ./.github/workflows/ActionTestWorkflow.yml - with: - TestType: Src-Default - Path: tests/srcTestRepo/src - Settings: SourceCode diff --git a/.github/workflows/Action-Test-Src-WithManifest.yml b/.github/workflows/Action-Test-Src-WithManifest.yml deleted file mode 100644 index f2fb1ff..0000000 --- a/.github/workflows/Action-Test-Src-WithManifest.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Action-Test [Src-WithManifest] - -run-name: "Action-Test [Src-WithManifest] - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}" - -on: - workflow_dispatch: - pull_request: - schedule: - - cron: '0 0 * * *' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -permissions: {} - -jobs: - ActionTest: - uses: ./.github/workflows/ActionTestWorkflow.yml - with: - TestType: Src-WithManifest - Path: tests/srcWithManifestTestRepo/src - Settings: SourceCode diff --git a/.github/workflows/Action-Test-outputs.yml b/.github/workflows/Action-Test-outputs.yml deleted file mode 100644 index 38094ad..0000000 --- a/.github/workflows/Action-Test-outputs.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Action-Test [outputs] - -run-name: "Action-Test [outputs] - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}" - -on: - workflow_dispatch: - pull_request: - schedule: - - cron: '0 0 * * *' - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -permissions: {} - -jobs: - ActionTest: - uses: ./.github/workflows/ActionTestWorkflow.yml - with: - TestType: outputs - Path: tests/outputTestRepo/outputs/modules/PSModuleTest - Settings: Module diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml new file mode 100644 index 0000000..7162bbb --- /dev/null +++ b/.github/workflows/Action-Test.yml @@ -0,0 +1,51 @@ +name: Action-Test + +run-name: "Action-Test - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}" + +on: + workflow_dispatch: + pull_request: + schedule: + - cron: '0 0 * * *' + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +permissions: + contents: read + pull-requests: read + +jobs: + ActionTestSrcSourceCode: + name: Action-Test - [Src-SourceCode] + uses: ./.github/workflows/ActionTestWorkflow.yml + with: + TestType: Src-SourceCode + Path: tests/srcTestRepo/src + Settings: SourceCode + + ActionTestSrcCustom: + name: Action-Test - [Src-Custom] + uses: ./.github/workflows/ActionTestWorkflow.yml + with: + TestType: Src-Custom + Path: tests/srcTestRepo/src + Settings: Custom + SettingsFilePath: tests/srcTestRepo/tests/Custom.Settings.psd1 + + ActionTestSrcWithManifest: + name: Action-Test - [Src-WithManifest] + uses: ./.github/workflows/ActionTestWorkflow.yml + with: + TestType: Src-WithManifest + Path: tests/srcWithManifestTestRepo/src + Settings: SourceCode + + ActionTestOutputs: + name: Action-Test - [outputs] + uses: ./.github/workflows/ActionTestWorkflow.yml + with: + TestType: outputs + Path: tests/outputTestRepo/outputs/modules/PSModuleTest + Settings: Module diff --git a/.github/workflows/ActionTestWorkflow.yml b/.github/workflows/ActionTestWorkflow.yml index b8f12df..b68c647 100644 --- a/.github/workflows/ActionTestWorkflow.yml +++ b/.github/workflows/ActionTestWorkflow.yml @@ -22,15 +22,12 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] - name: Action-Test [outputs] - [${{ matrix.os }}] + name: '${{ inputs.Path }} - ${{ inputs.TestType }} [${{ matrix.os }}]' runs-on: ${{ matrix.os }} steps: - name: Checkout repo uses: actions/checkout@v4 - - name: Initialize environment - uses: PSModule/Initialize-PSModule@main - - name: Action-Test uses: ./ id: action-test @@ -41,10 +38,6 @@ jobs: - name: Status shell: pwsh - env: - PASSED: ${{ steps.action-test.outputs.passed }} run: | - Write-Host "Passed: [$env:PASSED]" - if ($env:PASSED -ne 'true') { - exit 1 - } + Write-Host "Outcome: ${{ steps.action-test.outcome }}" + Write-Host "Conclusion: ${{ steps.action-test.conclusion }}" From 27fc670d212215844e8c584134ce32cf484d7958 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 18:05:49 +0100 Subject: [PATCH 03/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Simplify=20job?= =?UTF-8?q?=20name=20in=20ActionTestWorkflow=20to=20use=20OS=20only?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ActionTestWorkflow.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ActionTestWorkflow.yml b/.github/workflows/ActionTestWorkflow.yml index b68c647..f47faad 100644 --- a/.github/workflows/ActionTestWorkflow.yml +++ b/.github/workflows/ActionTestWorkflow.yml @@ -22,7 +22,7 @@ jobs: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] - name: '${{ inputs.Path }} - ${{ inputs.TestType }} [${{ matrix.os }}]' + name: ${{ matrix.os }} runs-on: ${{ matrix.os }} steps: - name: Checkout repo From b11037f1bb298ea1b849c0c0c340dcf4a1f98b21 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 18:24:16 +0100 Subject: [PATCH 04/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Simplify=20PSSc?= =?UTF-8?q?riptAnalyzer=20test=20description=20and=20remove=20unnecessary?= =?UTF-8?q?=20suppression=20attribute?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 2 +- .../src/functions/public/SomethingElse/Set-PSModuleTest.ps1 | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index d048114..d3fd933 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -65,7 +65,7 @@ BeforeDiscovery { } } -Describe "PSScriptAnalyzer tests using settings file [$relativeSettingsFilePath]" { +Describe "PSScriptAnalyzer" { BeforeAll { $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose:$false Write-Warning "Found [$($testResults.Count)] issues" diff --git a/tests/srcWithManifestTestRepo/src/functions/public/SomethingElse/Set-PSModuleTest.ps1 b/tests/srcWithManifestTestRepo/src/functions/public/SomethingElse/Set-PSModuleTest.ps1 index a87ac11..86a4ff7 100644 --- a/tests/srcWithManifestTestRepo/src/functions/public/SomethingElse/Set-PSModuleTest.ps1 +++ b/tests/srcWithManifestTestRepo/src/functions/public/SomethingElse/Set-PSModuleTest.ps1 @@ -8,10 +8,6 @@ "Hello, World!" #> - [Diagnostics.CodeAnalysis.SuppressMessageAttribute( - 'PSUseShouldProcessForStateChangingFunctions', '', Scope = 'Function', - Justification = 'Reason for suppressing' - )] [CmdletBinding()] param ( # Name of the person to greet. From ae2041cdf895f991bc7ad2b8885f668ee92f4243 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 18:32:34 +0100 Subject: [PATCH 05/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Enhance=20loggi?= =?UTF-8?q?ng=20for=20Invoke-ScriptAnalyzer=20to=20improve=20issue=20track?= =?UTF-8?q?ing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index d3fd933..d9503b9 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -67,8 +67,10 @@ BeforeDiscovery { Describe "PSScriptAnalyzer" { BeforeAll { - $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose:$false - Write-Warning "Found [$($testResults.Count)] issues" + LogGroup "Invoke-ScriptAnalyzer -Path [$Path] -Settings [$relativeSettingsFilePath]" { + $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose + Write-Warning "Found [$($testResults.Count)] issues" + } } foreach ($Severety in $Severeties) { From dd08ad8d6edb04e6a23c8f5b3f01db947a41ae77 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 18:39:18 +0100 Subject: [PATCH 06/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20loggin?= =?UTF-8?q?g=20in=20PSScriptAnalyzer=20tests=20to=20include=20full=20setti?= =?UTF-8?q?ngs=20file=20path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index d9503b9..bd8a5b6 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -60,14 +60,13 @@ BeforeDiscovery { } ) } - Write-Warning "Discovered [$($rules.Count)] rules" - $relativeSettingsFilePath = $SettingsFilePath.Replace($PSScriptRoot, '').Trim('\').Trim('/') } } Describe "PSScriptAnalyzer" { BeforeAll { - LogGroup "Invoke-ScriptAnalyzer -Path [$Path] -Settings [$relativeSettingsFilePath]" { + $relativeSettingsFilePath = $SettingsFilePath.Replace($PSScriptRoot, '').Trim('\').Trim('/') + LogGroup "Invoke-ScriptAnalyzer -Path [$Path] -Settings [$SettingsFilePath]" { $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose Write-Warning "Found [$($testResults.Count)] issues" } From 4adc55c9f5c6fb662a902fae2872155a59ecd615 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 18:39:21 +0100 Subject: [PATCH 07/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20loggin?= =?UTF-8?q?g=20in=20PSScriptAnalyzer=20tests=20to=20use=20relative=20setti?= =?UTF-8?q?ngs=20file=20path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index bd8a5b6..66a8809 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -66,7 +66,7 @@ BeforeDiscovery { Describe "PSScriptAnalyzer" { BeforeAll { $relativeSettingsFilePath = $SettingsFilePath.Replace($PSScriptRoot, '').Trim('\').Trim('/') - LogGroup "Invoke-ScriptAnalyzer -Path [$Path] -Settings [$SettingsFilePath]" { + LogGroup "Invoke-ScriptAnalyzer -Path [$Path] -Settings [$relativeSettingsFilePath]" { $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose Write-Warning "Found [$($testResults.Count)] issues" } From 519199f5229e27e78734b422ddadb58d72023591 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 18:44:45 +0100 Subject: [PATCH 08/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20relati?= =?UTF-8?q?ve=20settings=20file=20path=20in=20PSScriptAnalyzer=20tests=20f?= =?UTF-8?q?or=20improved=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index 66a8809..08f0492 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -63,9 +63,10 @@ BeforeDiscovery { } } -Describe "PSScriptAnalyzer" { +Describe 'PSScriptAnalyzer' { BeforeAll { - $relativeSettingsFilePath = $SettingsFilePath.Replace($PSScriptRoot, '').Trim('\').Trim('/') + $relativeSettingsFilePath = $SettingsFilePath.Replace($PSScriptRoot, 'Action/').Trim('\').Trim('/') + $relativeSettingsFilePath = $SettingsFilePath.Replace($env:GITHUB_WORKSPACE, 'Workspace/').Trim('\').Trim('/') LogGroup "Invoke-ScriptAnalyzer -Path [$Path] -Settings [$relativeSettingsFilePath]" { $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose Write-Warning "Found [$($testResults.Count)] issues" From 1ec90581a43b23258a00f5654beb91da333e2118 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 18:46:43 +0100 Subject: [PATCH 09/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Add=20logging?= =?UTF-8?q?=20for=20test=20results=20in=20PSScriptAnalyzer=20tests=20to=20?= =?UTF-8?q?enhance=20visibility?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index 08f0492..fe563f3 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -71,6 +71,9 @@ Describe 'PSScriptAnalyzer' { $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose Write-Warning "Found [$($testResults.Count)] issues" } + LogGroup "TestResults" { + $testResults + } } foreach ($Severety in $Severeties) { From d71a8e9f1e0da52bb3fbe5c6612a37e8b5920509 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 18:55:40 +0100 Subject: [PATCH 10/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20rela?= =?UTF-8?q?tive=20settings=20file=20path=20handling=20in=20PSScriptAnalyze?= =?UTF-8?q?r=20tests=20for=20improved=20clarity=20and=20logging?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PSScriptAnalyzer.Tests.ps1 | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index fe563f3..7921795 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -65,13 +65,23 @@ BeforeDiscovery { Describe 'PSScriptAnalyzer' { BeforeAll { - $relativeSettingsFilePath = $SettingsFilePath.Replace($PSScriptRoot, 'Action/').Trim('\').Trim('/') - $relativeSettingsFilePath = $SettingsFilePath.Replace($env:GITHUB_WORKSPACE, 'Workspace/').Trim('\').Trim('/') + $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 + } + [pscustomobject]@{ + relativeSettingsFilePath = $relativeSettingsFilePath + SettingsFilePath = $SettingsFilePath + PSScriptRoot = $PSScriptRoot + GITHUB_WORKSPACE = $env:GITHUB_WORKSPACE + } LogGroup "Invoke-ScriptAnalyzer -Path [$Path] -Settings [$relativeSettingsFilePath]" { $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose - Write-Warning "Found [$($testResults.Count)] issues" } - LogGroup "TestResults" { + LogGroup "TestResults [$($testResults.Count)]" { $testResults } } From 68e91767c27550b4ba9fc85a18da8f882e488cbd Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 18:59:13 +0100 Subject: [PATCH 11/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Format=20test?= =?UTF-8?q?=20results=20output=20in=20PSScriptAnalyzer=20tests=20for=20imp?= =?UTF-8?q?roved=20readability?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index 7921795..9b0470d 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -82,7 +82,7 @@ Describe 'PSScriptAnalyzer' { $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose } LogGroup "TestResults [$($testResults.Count)]" { - $testResults + $testResults | Format-Table -AutoSize } } From 29eac9cf60fc0e30a02693c5a434b4cb63210f9d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 19:17:59 +0100 Subject: [PATCH 12/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20test?= =?UTF-8?q?=20results=20output=20formatting=20in=20PSScriptAnalyzer=20test?= =?UTF-8?q?s=20for=20enhanced=20verbosity=20and=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index 9b0470d..388bbda 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -82,7 +82,11 @@ Describe 'PSScriptAnalyzer' { $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose } LogGroup "TestResults [$($testResults.Count)]" { - $testResults | Format-Table -AutoSize + $testResults | ForEach-Object { + $_ | Format-List | Out-String -Stream | ForEach-Object { + Write-Verbose $_ -Verbose + } + } } } From c7258396a4e12a28f2d28161dd56b69839a89d83 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 19:43:48 +0100 Subject: [PATCH 13/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Enhance=20test?= =?UTF-8?q?=20case=20definition=20in=20PSScriptAnalyzer=20tests=20for=20im?= =?UTF-8?q?proved=20clarity=20and=20functionality?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index 388bbda..4449919 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -93,7 +93,7 @@ Describe 'PSScriptAnalyzer' { foreach ($Severety in $Severeties) { Context "Severity: $Severety" { foreach ($rule in $rules | Where-Object -Property Severity -EQ $Severety) { - It "$($rule.CommonName) ($($rule.RuleName))" -Skip:$rule.Skip { + It "$($rule.CommonName) ($($rule.RuleName))" -Skip:$rule.Skip -ForEach $rule { $issues = [Collections.Generic.List[string]]::new() $testResults | Where-Object -Property RuleName -EQ $rule.RuleName | ForEach-Object { $relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/') From 116252cbcbb27aa655d4a32ead553bf19a6e98c4 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 19:57:05 +0100 Subject: [PATCH 14/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20PSSc?= =?UTF-8?q?riptAnalyzer=20test=20structure=20for=20improved=20readability?= =?UTF-8?q?=20and=20organization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PSScriptAnalyzer.Tests.ps1 | 49 +++++++++---------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index 4449919..6d24b3a 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -61,39 +61,36 @@ 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 - } - [pscustomobject]@{ - relativeSettingsFilePath = $relativeSettingsFilePath - SettingsFilePath = $SettingsFilePath - PSScriptRoot = $PSScriptRoot - GITHUB_WORKSPACE = $env:GITHUB_WORKSPACE - } - LogGroup "Invoke-ScriptAnalyzer -Path [$Path] -Settings [$relativeSettingsFilePath]" { - $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose - } - LogGroup "TestResults [$($testResults.Count)]" { - $testResults | ForEach-Object { - $_ | Format-List | Out-String -Stream | ForEach-Object { - Write-Verbose $_ -Verbose - } + $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 + } + [pscustomobject]@{ + relativeSettingsFilePath = $relativeSettingsFilePath + SettingsFilePath = $SettingsFilePath + PSScriptRoot = $PSScriptRoot + GITHUB_WORKSPACE = $env:GITHUB_WORKSPACE + } + LogGroup "Invoke-ScriptAnalyzer -Path [$Path] -Settings [$relativeSettingsFilePath]" { + $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose + } + LogGroup "TestResults [$($testResults.Count)]" { + $testResults | ForEach-Object { + $_ | Format-List | Out-String -Stream | ForEach-Object { + Write-Verbose $_ -Verbose } } } +} +Describe 'PSScriptAnalyzer' { foreach ($Severety in $Severeties) { Context "Severity: $Severety" { foreach ($rule in $rules | Where-Object -Property Severity -EQ $Severety) { - It "$($rule.CommonName) ($($rule.RuleName))" -Skip:$rule.Skip -ForEach $rule { + It "$($rule.CommonName) ($($rule.RuleName))" -Skip:$rule.Skip { $issues = [Collections.Generic.List[string]]::new() $testResults | Where-Object -Property RuleName -EQ $rule.RuleName | ForEach-Object { $relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/') From c60f31416609aac52a453c8b5fb4dd9b6f64c1c5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 20:09:23 +0100 Subject: [PATCH 15/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20PSSc?= =?UTF-8?q?riptAnalyzer=20test=20setup=20for=20improved=20variable=20scopi?= =?UTF-8?q?ng=20and=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PSScriptAnalyzer.Tests.ps1 | 51 ++++++++++--------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index 6d24b3a..4ae49a3 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -61,38 +61,41 @@ BeforeDiscovery { ) } } - $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 - } - [pscustomobject]@{ - relativeSettingsFilePath = $relativeSettingsFilePath - SettingsFilePath = $SettingsFilePath - PSScriptRoot = $PSScriptRoot - GITHUB_WORKSPACE = $env:GITHUB_WORKSPACE - } - LogGroup "Invoke-ScriptAnalyzer -Path [$Path] -Settings [$relativeSettingsFilePath]" { - $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose - } - LogGroup "TestResults [$($testResults.Count)]" { - $testResults | ForEach-Object { - $_ | Format-List | Out-String -Stream | ForEach-Object { - Write-Verbose $_ -Verbose +} + +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 + } + [pscustomobject]@{ + relativeSettingsFilePath = $relativeSettingsFilePath + SettingsFilePath = $SettingsFilePath + PSScriptRoot = $PSScriptRoot + GITHUB_WORKSPACE = $env:GITHUB_WORKSPACE + } + LogGroup "Invoke-ScriptAnalyzer -Path [$Path] -Settings [$relativeSettingsFilePath]" { + $script:testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose + } + LogGroup "TestResults [$($script:testResults.Count)]" { + $script:testResults | ForEach-Object { + $_ | Format-List | Out-String -Stream | ForEach-Object { + Write-Verbose $_ -Verbose + } } } } -} -Describe 'PSScriptAnalyzer' { foreach ($Severety in $Severeties) { Context "Severity: $Severety" { foreach ($rule in $rules | Where-Object -Property Severity -EQ $Severety) { - It "$($rule.CommonName) ($($rule.RuleName))" -Skip:$rule.Skip { + It "$($rule.CommonName) ($($rule.RuleName))" -Skip:$rule.Skip -ForEach @( $rule.RuleName) { $issues = [Collections.Generic.List[string]]::new() - $testResults | Where-Object -Property RuleName -EQ $rule.RuleName | ForEach-Object { + $script:testResults | Where-Object -Property RuleName -EQ $_ | ForEach-Object { $relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/') $issues.Add(([Environment]::NewLine + " - $relativePath`:L$($_.Line):C$($_.Column)")) } From 92b4b686ac0a45fa9175d2d28ac0a93bf5bfdd0d Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 20:15:42 +0100 Subject: [PATCH 16/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20PSSc?= =?UTF-8?q?riptAnalyzer=20test=20cases=20for=20improved=20rule=20handling?= =?UTF-8?q?=20and=20clarity?= 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 4ae49a3..f00b95f 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -93,9 +93,9 @@ Describe 'PSScriptAnalyzer' { foreach ($Severety in $Severeties) { Context "Severity: $Severety" { foreach ($rule in $rules | Where-Object -Property Severity -EQ $Severety) { - It "$($rule.CommonName) ($($rule.RuleName))" -Skip:$rule.Skip -ForEach @( $rule.RuleName) { + It "$($rule.CommonName) ($($rule.RuleName))" -Skip:$rule.Skip -ForEach @{ Rule = $rule } { $issues = [Collections.Generic.List[string]]::new() - $script:testResults | Where-Object -Property RuleName -EQ $_ | ForEach-Object { + $script:testResults | Where-Object -Property RuleName -EQ $Rule.RuleName | ForEach-Object { $relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/') $issues.Add(([Environment]::NewLine + " - $relativePath`:L$($_.Line):C$($_.Column)")) } From c76fdf7ba53898e8fd7b767add0876bda16088b3 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 20:21:02 +0100 Subject: [PATCH 17/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20PSSc?= =?UTF-8?q?riptAnalyzer=20test=20results=20handling=20for=20improved=20var?= =?UTF-8?q?iable=20scope=20and=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index f00b95f..97882ac 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -78,11 +78,12 @@ Describe 'PSScriptAnalyzer' { PSScriptRoot = $PSScriptRoot GITHUB_WORKSPACE = $env:GITHUB_WORKSPACE } + $Path = Resolve-Path -Path $Path | Select-Object -ExpandProperty Path LogGroup "Invoke-ScriptAnalyzer -Path [$Path] -Settings [$relativeSettingsFilePath]" { - $script:testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose + $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose } - LogGroup "TestResults [$($script:testResults.Count)]" { - $script:testResults | ForEach-Object { + LogGroup "TestResults [$($testResults.Count)]" { + $testResults | ForEach-Object { $_ | Format-List | Out-String -Stream | ForEach-Object { Write-Verbose $_ -Verbose } @@ -95,7 +96,7 @@ Describe 'PSScriptAnalyzer' { foreach ($rule in $rules | Where-Object -Property Severity -EQ $Severety) { It "$($rule.CommonName) ($($rule.RuleName))" -Skip:$rule.Skip -ForEach @{ Rule = $rule } { $issues = [Collections.Generic.List[string]]::new() - $script:testResults | Where-Object -Property RuleName -EQ $Rule.RuleName | ForEach-Object { + $testResults | Where-Object { $_.RuleName -eq $Rule.RuleName } | ForEach-Object { $relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/') $issues.Add(([Environment]::NewLine + " - $relativePath`:L$($_.Line):C$($_.Column)")) } From fdbc52e1b18f208040b9fd399db806192ba7070a Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 20:23:14 +0100 Subject: [PATCH 18/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20PSScri?= =?UTF-8?q?ptAnalyzer=20test=20logging=20for=20improved=20path=20resolutio?= =?UTF-8?q?n=20and=20clarity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index 97882ac..c8276be 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -72,14 +72,23 @@ Describe 'PSScriptAnalyzer' { } else { $SettingsFilePath } + $Path = Resolve-Path -Path $Path | Select-Object -ExpandProperty Path + $relativePath = if ($Path.StartsWith($PSScriptRoot)) { + $Path.Replace($PSScriptRoot, 'Action:').Trim('\').Trim('/') + } elseif ($Path.StartsWith($env:GITHUB_WORKSPACE)) { + $Path.Replace($env:GITHUB_WORKSPACE, 'Workspace:').Trim('\').Trim('/') + } else { + $Path + } + [pscustomobject]@{ relativeSettingsFilePath = $relativeSettingsFilePath SettingsFilePath = $SettingsFilePath PSScriptRoot = $PSScriptRoot GITHUB_WORKSPACE = $env:GITHUB_WORKSPACE } - $Path = Resolve-Path -Path $Path | Select-Object -ExpandProperty Path - LogGroup "Invoke-ScriptAnalyzer -Path [$Path] -Settings [$relativeSettingsFilePath]" { + + LogGroup "Invoke-ScriptAnalyzer -Path [$relativePath] -Settings [$relativeSettingsFilePath]" { $testResults = Invoke-ScriptAnalyzer -Path $Path -Settings $SettingsFilePath -Recurse -Verbose } LogGroup "TestResults [$($testResults.Count)]" { @@ -97,7 +106,6 @@ Describe 'PSScriptAnalyzer' { It "$($rule.CommonName) ($($rule.RuleName))" -Skip:$rule.Skip -ForEach @{ Rule = $rule } { $issues = [Collections.Generic.List[string]]::new() $testResults | Where-Object { $_.RuleName -eq $Rule.RuleName } | ForEach-Object { - $relativePath = $_.ScriptPath.Replace($Path, '').Trim('\').Trim('/') $issues.Add(([Environment]::NewLine + " - $relativePath`:L$($_.Line):C$($_.Column)")) } $issues -join '' | Should -BeNullOrEmpty -Because $rule.Description From aaa2e3bc39a8cc35724e098b3f6aa3a61c44a44b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 20:26:46 +0100 Subject: [PATCH 19/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Set=20PSStyle.O?= =?UTF-8?q?utputRendering=20to=20'Host'=20for=20improved=20output=20format?= =?UTF-8?q?ting=20in=20PSScriptAnalyzer=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index c8276be..c4ce829 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -65,6 +65,7 @@ BeforeDiscovery { Describe 'PSScriptAnalyzer' { BeforeAll { + $PSStyle.OutputRendering = 'Host' $relativeSettingsFilePath = if ($SettingsFilePath.StartsWith($PSScriptRoot)) { $SettingsFilePath.Replace($PSScriptRoot, 'Action:').Trim('\').Trim('/') } elseif ($SettingsFilePath.StartsWith($env:GITHUB_WORKSPACE)) { From f8fef5329f63c38f3313539d9aa6d9292124e396 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 20:37:56 +0100 Subject: [PATCH 20/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Enhance=20GitHu?= =?UTF-8?q?b=20Actions=20workflows=20with=20aggregated=20job=20status=20re?= =?UTF-8?q?porting=20and=20improved=20error=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Action-Test.yml | 115 ++++++++++++++++++ .github/workflows/ActionTestWorkflow.yml | 4 + .../PSScriptAnalyzer.Tests.ps1 | 5 +- 3 files changed, 123 insertions(+), 1 deletion(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 7162bbb..da1b449 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -49,3 +49,118 @@ jobs: TestType: outputs Path: tests/outputTestRepo/outputs/modules/PSModuleTest Settings: Module + + + CatchJob: + name: "Catch Job - Aggregate Status" + needs: + - ActionTestSrcSourceCode + - ActionTestSrcCustom + - ActionTestSrcWithManifest + - ActionTestOutputs + if: always() + runs-on: ubuntu-latest + steps: + - name: Display Aggregated Results as a Table + uses: PSModule/Github-Script@v1 + with: + Script: | + Install-PSResource -Name Markdown -Repository PSGallery -TrustRepository + + # Build an array of objects for each job + $ActionTestSrcSourceCodeOutcome = ${{ needs.ActionTestSrcSourceCode.outputs.Outcome }} + $ActionTestSrcSourceCodeExpectedOutcome = "success" + $ActionTestSrcSourceCodeOutcomeResult = $ActionTestSrcSourceCodeOutcome -eq $ActionTestSrcSourceCodeExpectedOutcome + $ActionTestSrcSourceCodeConclusion = ${{ needs.ActionTestSrcSourceCode.outputs.Conclusion }} + $ActionTestSrcSourceCodeExpectedConclusion = "success" + $ActionTestSrcSourceCodeConclusionResult = $ActionTestSrcSourceCodeConclusion -eq $ActionTestSrcSourceCodeExpectedConclusion + + $ActionTestSrcCustomOutcome = ${{ needs.ActionTestSrcCustom.outputs.Outcome }} + $ActionTestSrcCustomExpectedOutcome = "success" + $ActionTestSrcCustomOutcomeResult = $ActionTestSrcCustomOutcome -eq $ActionTestSrcCustomExpectedOutcome + $ActionTestSrcCustomConclusion = ${{ needs.ActionTestSrcCustom.outputs.Conclusion }} + $ActionTestSrcCustomExpectedConclusion = "success" + $ActionTestSrcCustomConclusionResult = $ActionTestSrcCustomConclusion -eq $ActionTestSrcCustomExpectedConclusion + + $ActionTestSrcWithManifestOutcome = ${{ needs.ActionTestSrcWithManifest.outputs.Outcome }} + $ActionTestSrcWithManifestExpectedOutcome = "failure" + $ActionTestSrcWithManifestOutcomeResult = $ActionTestSrcWithManifestOutcome -eq $ActionTestSrcWithManifestExpectedOutcome + $ActionTestSrcWithManifestConclusion = ${{ needs.ActionTestSrcWithManifest.outputs.Conclusion }} + $ActionTestSrcWithManifestExpectedConclusion = "success" + $ActionTestSrcWithManifestConclusionResult = $ActionTestSrcWithManifestConclusion -eq $ActionTestSrcWithManifestExpectedConclusion + + $ActionTestOutputsOutcome = ${{ needs.ActionTestOutputs.outputs.Outcome }} + $ActionTestOutputsExpectedOutcome = "success" + $ActionTestOutputsOutcomeResult = $ActionTestOutputsOutcome -eq $ActionTestOutputsExpectedOutcome + $ActionTestOutputsConclusion = ${{ needs.ActionTestOutputs.outputs.Conclusion }} + $ActionTestOutputsExpectedConclusion = "success" + $ActionTestOutputsConclusionResult = $ActionTestOutputsConclusion -eq $ActionTestOutputsExpectedConclusion + + $jobs = @( + [PSCustomObject]@{ + Name = "Action-Test - [Src-SourceCode]" + Outcome = $ActionTestSrcSourceCodeOutcome + ExpectedOutcome = $ActionTestSrcSourceCodeExpectedOutcome + PassedOutcome = $ActionTestSrcSourceCodeOutcomeResult + Conclusion = $ActionTestSrcSourceCodeConclusion + ExpectedConclusion = $ActionTestSrcSourceCodeExpectedConclusion + PassedConclusion = $ActionTestSrcSourceCodeConclusionResult + }, + [PSCustomObject]@{ + Name = "Action-Test - [Src-Custom]" + Outcome = $ActionTestSrcCustomOutcome + ExpectedOutcome = $ActionTestSrcCustomExpectedOutcome + PassedOutcome = $ActionTestSrcCustomOutcomeResult + Conclusion = $ActionTestSrcCustomConclusion + ExpectedConclusion = $ActionTestSrcCustomExpectedConclusion + PassedConclusion = $ActionTestSrcCustomConclusionResult + }, + [PSCustomObject]@{ + Name = "Action-Test - [Src-WithManifest]" + Outcome = $ActionTestSrcWithManifestOutcome + ExpectedOutcome = $ActionTestSrcWithManifestExpectedOutcome + PassedOutcome = $ActionTestSrcWithManifestOutcomeResult + Conclusion = $ActionTestSrcWithManifestConclusion + ExpectedConclusion = $ActionTestSrcWithManifestExpectedConclusion + PassedConclusion = $ActionTestSrcWithManifestConclusionResult + }, + [PSCustomObject]@{ + Name = "Action-Test - [outputs]" + Outcome = $ActionTestOutputsOutcome + ExpectedOutcome = $ActionTestOutputsExpectedOutcome + PassedOutcome = $ActionTestOutputsOutcomeResult + Conclusion = $ActionTestOutputsConclusion + ExpectedConclusion = $ActionTestOutputsExpectedConclusion + PassedConclusion = $ActionTestOutputsConclusionResult + } + ) + + # Display the table in the workflow logs + $jobs | Format-List + + $passed = $true + $jobs | ForEach-Object { + if (-not $_.PassedOutcome) { + Write-Error "Job $($_.Name) failed with Outcome $($_.Outcome) and Expected Outcome $($_.ExpectedOutcome)" + $passed = $false + } + + if (-not $_.PassedConclusion) { + Write-Error "Job $($_.Name) failed with Conclusion $($_.Conclusion) and Expected Conclusion $($_.ExpectedConclusion)" + $passed = $false + } + } + + $icon = if ($passed) { '✅' } else { '❌' } + $status = Heading 1 "$icon - GitHub Actions Status" { + Table { + $jobs + } + } + + Set-GitHubStepSummary -Summary $status + + if (-not $passed) { + Write-GithubError "One or more jobs failed" + exit 1 + } diff --git a/.github/workflows/ActionTestWorkflow.yml b/.github/workflows/ActionTestWorkflow.yml index f47faad..3fc0485 100644 --- a/.github/workflows/ActionTestWorkflow.yml +++ b/.github/workflows/ActionTestWorkflow.yml @@ -24,12 +24,16 @@ jobs: os: [ubuntu-latest, macos-latest, windows-latest] name: ${{ matrix.os }} runs-on: ${{ matrix.os }} + outputs: + outcome: ${{ steps.action-test.outcome }} + conclusion: ${{ steps.action-test.conclusion }} steps: - name: Checkout repo uses: actions/checkout@v4 - name: Action-Test uses: ./ + continue-on-error: true id: action-test with: Path: ${{ inputs.Path }} diff --git a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 index c4ce829..7ec133d 100644 --- a/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 +++ b/scripts/tests/PSScriptAnalyzer/PSScriptAnalyzer.Tests.ps1 @@ -65,7 +65,6 @@ BeforeDiscovery { Describe 'PSScriptAnalyzer' { BeforeAll { - $PSStyle.OutputRendering = 'Host' $relativeSettingsFilePath = if ($SettingsFilePath.StartsWith($PSScriptRoot)) { $SettingsFilePath.Replace($PSScriptRoot, 'Action:').Trim('\').Trim('/') } elseif ($SettingsFilePath.StartsWith($env:GITHUB_WORKSPACE)) { @@ -115,3 +114,7 @@ Describe 'PSScriptAnalyzer' { } } } + +AfterAll { + $PSStyle.OutputRendering = 'Host' +} From 522fd9570c6d7ebc356ea0ef6ec09b54e3f47de5 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 20:50:48 +0100 Subject: [PATCH 21/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Normalize=20out?= =?UTF-8?q?put=20variable=20names=20in=20GitHub=20Actions=20workflow=20for?= =?UTF-8?q?=20consistency?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Action-Test.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index da1b449..3584424 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -68,31 +68,31 @@ jobs: Install-PSResource -Name Markdown -Repository PSGallery -TrustRepository # Build an array of objects for each job - $ActionTestSrcSourceCodeOutcome = ${{ needs.ActionTestSrcSourceCode.outputs.Outcome }} + $ActionTestSrcSourceCodeOutcome = ${{ needs.ActionTestSrcSourceCode.outputs.outcome }} $ActionTestSrcSourceCodeExpectedOutcome = "success" $ActionTestSrcSourceCodeOutcomeResult = $ActionTestSrcSourceCodeOutcome -eq $ActionTestSrcSourceCodeExpectedOutcome - $ActionTestSrcSourceCodeConclusion = ${{ needs.ActionTestSrcSourceCode.outputs.Conclusion }} + $ActionTestSrcSourceCodeConclusion = ${{ needs.ActionTestSrcSourceCode.outputs.conclusion }} $ActionTestSrcSourceCodeExpectedConclusion = "success" $ActionTestSrcSourceCodeConclusionResult = $ActionTestSrcSourceCodeConclusion -eq $ActionTestSrcSourceCodeExpectedConclusion - $ActionTestSrcCustomOutcome = ${{ needs.ActionTestSrcCustom.outputs.Outcome }} + $ActionTestSrcCustomOutcome = ${{ needs.ActionTestSrcCustom.outputs.outcome }} $ActionTestSrcCustomExpectedOutcome = "success" $ActionTestSrcCustomOutcomeResult = $ActionTestSrcCustomOutcome -eq $ActionTestSrcCustomExpectedOutcome - $ActionTestSrcCustomConclusion = ${{ needs.ActionTestSrcCustom.outputs.Conclusion }} + $ActionTestSrcCustomConclusion = ${{ needs.ActionTestSrcCustom.outputs.conclusion }} $ActionTestSrcCustomExpectedConclusion = "success" $ActionTestSrcCustomConclusionResult = $ActionTestSrcCustomConclusion -eq $ActionTestSrcCustomExpectedConclusion - $ActionTestSrcWithManifestOutcome = ${{ needs.ActionTestSrcWithManifest.outputs.Outcome }} + $ActionTestSrcWithManifestOutcome = ${{ needs.ActionTestSrcWithManifest.outputs.outcome }} $ActionTestSrcWithManifestExpectedOutcome = "failure" $ActionTestSrcWithManifestOutcomeResult = $ActionTestSrcWithManifestOutcome -eq $ActionTestSrcWithManifestExpectedOutcome - $ActionTestSrcWithManifestConclusion = ${{ needs.ActionTestSrcWithManifest.outputs.Conclusion }} + $ActionTestSrcWithManifestConclusion = ${{ needs.ActionTestSrcWithManifest.outputs.conclusion }} $ActionTestSrcWithManifestExpectedConclusion = "success" $ActionTestSrcWithManifestConclusionResult = $ActionTestSrcWithManifestConclusion -eq $ActionTestSrcWithManifestExpectedConclusion - $ActionTestOutputsOutcome = ${{ needs.ActionTestOutputs.outputs.Outcome }} + $ActionTestOutputsOutcome = ${{ needs.ActionTestOutputs.outputs.outcome }} $ActionTestOutputsExpectedOutcome = "success" $ActionTestOutputsOutcomeResult = $ActionTestOutputsOutcome -eq $ActionTestOutputsExpectedOutcome - $ActionTestOutputsConclusion = ${{ needs.ActionTestOutputs.outputs.Conclusion }} + $ActionTestOutputsConclusion = ${{ needs.ActionTestOutputs.outputs.conclusion }} $ActionTestOutputsExpectedConclusion = "success" $ActionTestOutputsConclusionResult = $ActionTestOutputsConclusion -eq $ActionTestOutputsExpectedConclusion From d9c023b31080b6ae4782498d88aed23dbf2a2a43 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 20:51:51 +0100 Subject: [PATCH 22/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20GitHub?= =?UTF-8?q?=20Actions=20workflow=20to=20use=20string=20interpolation=20for?= =?UTF-8?q?=20output=20variable=20assignments?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Action-Test.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 3584424..8cbd27f 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -68,31 +68,31 @@ jobs: Install-PSResource -Name Markdown -Repository PSGallery -TrustRepository # Build an array of objects for each job - $ActionTestSrcSourceCodeOutcome = ${{ needs.ActionTestSrcSourceCode.outputs.outcome }} + $ActionTestSrcSourceCodeOutcome = '${{ needs.ActionTestSrcSourceCode.outputs.outcome }}' $ActionTestSrcSourceCodeExpectedOutcome = "success" $ActionTestSrcSourceCodeOutcomeResult = $ActionTestSrcSourceCodeOutcome -eq $ActionTestSrcSourceCodeExpectedOutcome - $ActionTestSrcSourceCodeConclusion = ${{ needs.ActionTestSrcSourceCode.outputs.conclusion }} + $ActionTestSrcSourceCodeConclusion = '${{ needs.ActionTestSrcSourceCode.outputs.conclusion }}' $ActionTestSrcSourceCodeExpectedConclusion = "success" $ActionTestSrcSourceCodeConclusionResult = $ActionTestSrcSourceCodeConclusion -eq $ActionTestSrcSourceCodeExpectedConclusion - $ActionTestSrcCustomOutcome = ${{ needs.ActionTestSrcCustom.outputs.outcome }} + $ActionTestSrcCustomOutcome = '${{ needs.ActionTestSrcCustom.outputs.outcome }}' $ActionTestSrcCustomExpectedOutcome = "success" $ActionTestSrcCustomOutcomeResult = $ActionTestSrcCustomOutcome -eq $ActionTestSrcCustomExpectedOutcome - $ActionTestSrcCustomConclusion = ${{ needs.ActionTestSrcCustom.outputs.conclusion }} + $ActionTestSrcCustomConclusion = '${{ needs.ActionTestSrcCustom.outputs.conclusion }}' $ActionTestSrcCustomExpectedConclusion = "success" $ActionTestSrcCustomConclusionResult = $ActionTestSrcCustomConclusion -eq $ActionTestSrcCustomExpectedConclusion - $ActionTestSrcWithManifestOutcome = ${{ needs.ActionTestSrcWithManifest.outputs.outcome }} + $ActionTestSrcWithManifestOutcome = '${{ needs.ActionTestSrcWithManifest.outputs.outcome }}' $ActionTestSrcWithManifestExpectedOutcome = "failure" $ActionTestSrcWithManifestOutcomeResult = $ActionTestSrcWithManifestOutcome -eq $ActionTestSrcWithManifestExpectedOutcome - $ActionTestSrcWithManifestConclusion = ${{ needs.ActionTestSrcWithManifest.outputs.conclusion }} + $ActionTestSrcWithManifestConclusion = '${{ needs.ActionTestSrcWithManifest.outputs.conclusion }}' $ActionTestSrcWithManifestExpectedConclusion = "success" $ActionTestSrcWithManifestConclusionResult = $ActionTestSrcWithManifestConclusion -eq $ActionTestSrcWithManifestExpectedConclusion - $ActionTestOutputsOutcome = ${{ needs.ActionTestOutputs.outputs.outcome }} + $ActionTestOutputsOutcome = '${{ needs.ActionTestOutputs.outputs.outcome }}' $ActionTestOutputsExpectedOutcome = "success" $ActionTestOutputsOutcomeResult = $ActionTestOutputsOutcome -eq $ActionTestOutputsExpectedOutcome - $ActionTestOutputsConclusion = ${{ needs.ActionTestOutputs.outputs.conclusion }} + $ActionTestOutputsConclusion = '${{ needs.ActionTestOutputs.outputs.conclusion }}' $ActionTestOutputsExpectedConclusion = "success" $ActionTestOutputsConclusionResult = $ActionTestOutputsConclusion -eq $ActionTestOutputsExpectedConclusion From 7bb76888d181c331033c514965b8e31afe82c89b Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 21:01:09 +0100 Subject: [PATCH 23/32] Normalize output variable names in GitHub Actions workflows for consistency --- .github/workflows/Action-Test.yml | 16 ++++++++-------- .github/workflows/ActionTestWorkflow.yml | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 8cbd27f..da1b449 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -68,31 +68,31 @@ jobs: Install-PSResource -Name Markdown -Repository PSGallery -TrustRepository # Build an array of objects for each job - $ActionTestSrcSourceCodeOutcome = '${{ needs.ActionTestSrcSourceCode.outputs.outcome }}' + $ActionTestSrcSourceCodeOutcome = ${{ needs.ActionTestSrcSourceCode.outputs.Outcome }} $ActionTestSrcSourceCodeExpectedOutcome = "success" $ActionTestSrcSourceCodeOutcomeResult = $ActionTestSrcSourceCodeOutcome -eq $ActionTestSrcSourceCodeExpectedOutcome - $ActionTestSrcSourceCodeConclusion = '${{ needs.ActionTestSrcSourceCode.outputs.conclusion }}' + $ActionTestSrcSourceCodeConclusion = ${{ needs.ActionTestSrcSourceCode.outputs.Conclusion }} $ActionTestSrcSourceCodeExpectedConclusion = "success" $ActionTestSrcSourceCodeConclusionResult = $ActionTestSrcSourceCodeConclusion -eq $ActionTestSrcSourceCodeExpectedConclusion - $ActionTestSrcCustomOutcome = '${{ needs.ActionTestSrcCustom.outputs.outcome }}' + $ActionTestSrcCustomOutcome = ${{ needs.ActionTestSrcCustom.outputs.Outcome }} $ActionTestSrcCustomExpectedOutcome = "success" $ActionTestSrcCustomOutcomeResult = $ActionTestSrcCustomOutcome -eq $ActionTestSrcCustomExpectedOutcome - $ActionTestSrcCustomConclusion = '${{ needs.ActionTestSrcCustom.outputs.conclusion }}' + $ActionTestSrcCustomConclusion = ${{ needs.ActionTestSrcCustom.outputs.Conclusion }} $ActionTestSrcCustomExpectedConclusion = "success" $ActionTestSrcCustomConclusionResult = $ActionTestSrcCustomConclusion -eq $ActionTestSrcCustomExpectedConclusion - $ActionTestSrcWithManifestOutcome = '${{ needs.ActionTestSrcWithManifest.outputs.outcome }}' + $ActionTestSrcWithManifestOutcome = ${{ needs.ActionTestSrcWithManifest.outputs.Outcome }} $ActionTestSrcWithManifestExpectedOutcome = "failure" $ActionTestSrcWithManifestOutcomeResult = $ActionTestSrcWithManifestOutcome -eq $ActionTestSrcWithManifestExpectedOutcome - $ActionTestSrcWithManifestConclusion = '${{ needs.ActionTestSrcWithManifest.outputs.conclusion }}' + $ActionTestSrcWithManifestConclusion = ${{ needs.ActionTestSrcWithManifest.outputs.Conclusion }} $ActionTestSrcWithManifestExpectedConclusion = "success" $ActionTestSrcWithManifestConclusionResult = $ActionTestSrcWithManifestConclusion -eq $ActionTestSrcWithManifestExpectedConclusion - $ActionTestOutputsOutcome = '${{ needs.ActionTestOutputs.outputs.outcome }}' + $ActionTestOutputsOutcome = ${{ needs.ActionTestOutputs.outputs.Outcome }} $ActionTestOutputsExpectedOutcome = "success" $ActionTestOutputsOutcomeResult = $ActionTestOutputsOutcome -eq $ActionTestOutputsExpectedOutcome - $ActionTestOutputsConclusion = '${{ needs.ActionTestOutputs.outputs.conclusion }}' + $ActionTestOutputsConclusion = ${{ needs.ActionTestOutputs.outputs.Conclusion }} $ActionTestOutputsExpectedConclusion = "success" $ActionTestOutputsConclusionResult = $ActionTestOutputsConclusion -eq $ActionTestOutputsExpectedConclusion diff --git a/.github/workflows/ActionTestWorkflow.yml b/.github/workflows/ActionTestWorkflow.yml index 3fc0485..25c044b 100644 --- a/.github/workflows/ActionTestWorkflow.yml +++ b/.github/workflows/ActionTestWorkflow.yml @@ -25,8 +25,8 @@ jobs: name: ${{ matrix.os }} runs-on: ${{ matrix.os }} outputs: - outcome: ${{ steps.action-test.outcome }} - conclusion: ${{ steps.action-test.conclusion }} + Outcome: ${{ steps.action-test.outcome }} + Conclusion: ${{ steps.action-test.conclusion }} steps: - name: Checkout repo uses: actions/checkout@v4 From 3b8c715b41ba1be40198c9b0ebe1128f37c53cd6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 21:07:11 +0100 Subject: [PATCH 24/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20GitH?= =?UTF-8?q?ub=20Actions=20workflow=20to=20use=20environment=20variables=20?= =?UTF-8?q?for=20output=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Action-Test.yml | 49 ++++++++++++++++--------------- 1 file changed, 25 insertions(+), 24 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index da1b449..e918968 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -63,73 +63,74 @@ jobs: steps: - name: Display Aggregated Results as a Table uses: PSModule/Github-Script@v1 + 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 }} + ActionTestOutputsOutcome: ${{ needs.ActionTestOutputs.outputs.Outcome }} + ActionTestOutputsConclusion: ${{ needs.ActionTestOutputs.outputs.Conclusion }} with: Script: | Install-PSResource -Name Markdown -Repository PSGallery -TrustRepository # Build an array of objects for each job - $ActionTestSrcSourceCodeOutcome = ${{ needs.ActionTestSrcSourceCode.outputs.Outcome }} $ActionTestSrcSourceCodeExpectedOutcome = "success" - $ActionTestSrcSourceCodeOutcomeResult = $ActionTestSrcSourceCodeOutcome -eq $ActionTestSrcSourceCodeExpectedOutcome - $ActionTestSrcSourceCodeConclusion = ${{ needs.ActionTestSrcSourceCode.outputs.Conclusion }} + $ActionTestSrcSourceCodeOutcomeResult = $env:ActionTestSrcSourceCodeOutcome -eq $ActionTestSrcSourceCodeExpectedOutcome $ActionTestSrcSourceCodeExpectedConclusion = "success" - $ActionTestSrcSourceCodeConclusionResult = $ActionTestSrcSourceCodeConclusion -eq $ActionTestSrcSourceCodeExpectedConclusion + $ActionTestSrcSourceCodeConclusionResult = $env:ActionTestSrcSourceCodeConclusion -eq $ActionTestSrcSourceCodeExpectedConclusion - $ActionTestSrcCustomOutcome = ${{ needs.ActionTestSrcCustom.outputs.Outcome }} $ActionTestSrcCustomExpectedOutcome = "success" - $ActionTestSrcCustomOutcomeResult = $ActionTestSrcCustomOutcome -eq $ActionTestSrcCustomExpectedOutcome - $ActionTestSrcCustomConclusion = ${{ needs.ActionTestSrcCustom.outputs.Conclusion }} + $ActionTestSrcCustomOutcomeResult = $env:ActionTestSrcCustomOutcome -eq $ActionTestSrcCustomExpectedOutcome $ActionTestSrcCustomExpectedConclusion = "success" - $ActionTestSrcCustomConclusionResult = $ActionTestSrcCustomConclusion -eq $ActionTestSrcCustomExpectedConclusion + $ActionTestSrcCustomConclusionResult = $env:ActionTestSrcCustomConclusion -eq $ActionTestSrcCustomExpectedConclusion - $ActionTestSrcWithManifestOutcome = ${{ needs.ActionTestSrcWithManifest.outputs.Outcome }} $ActionTestSrcWithManifestExpectedOutcome = "failure" - $ActionTestSrcWithManifestOutcomeResult = $ActionTestSrcWithManifestOutcome -eq $ActionTestSrcWithManifestExpectedOutcome - $ActionTestSrcWithManifestConclusion = ${{ needs.ActionTestSrcWithManifest.outputs.Conclusion }} + $ActionTestSrcWithManifestOutcomeResult = $env:ActionTestSrcWithManifestOutcome -eq $ActionTestSrcWithManifestExpectedOutcome $ActionTestSrcWithManifestExpectedConclusion = "success" - $ActionTestSrcWithManifestConclusionResult = $ActionTestSrcWithManifestConclusion -eq $ActionTestSrcWithManifestExpectedConclusion + $ActionTestSrcWithManifestConclusionResult = $env:ActionTestSrcWithManifestConclusion -eq $ActionTestSrcWithManifestExpectedConclusion - $ActionTestOutputsOutcome = ${{ needs.ActionTestOutputs.outputs.Outcome }} $ActionTestOutputsExpectedOutcome = "success" - $ActionTestOutputsOutcomeResult = $ActionTestOutputsOutcome -eq $ActionTestOutputsExpectedOutcome - $ActionTestOutputsConclusion = ${{ needs.ActionTestOutputs.outputs.Conclusion }} + $ActionTestOutputsOutcomeResult = $env:ActionTestOutputsOutcome -eq $ActionTestOutputsExpectedOutcome $ActionTestOutputsExpectedConclusion = "success" - $ActionTestOutputsConclusionResult = $ActionTestOutputsConclusion -eq $ActionTestOutputsExpectedConclusion + $ActionTestOutputsConclusionResult = $env:ActionTestOutputsConclusion -eq $ActionTestOutputsExpectedConclusion $jobs = @( [PSCustomObject]@{ Name = "Action-Test - [Src-SourceCode]" - Outcome = $ActionTestSrcSourceCodeOutcome + Outcome = $env:ActionTestSrcSourceCodeOutcome ExpectedOutcome = $ActionTestSrcSourceCodeExpectedOutcome PassedOutcome = $ActionTestSrcSourceCodeOutcomeResult - Conclusion = $ActionTestSrcSourceCodeConclusion + Conclusion = $env:ActionTestSrcSourceCodeConclusion ExpectedConclusion = $ActionTestSrcSourceCodeExpectedConclusion PassedConclusion = $ActionTestSrcSourceCodeConclusionResult }, [PSCustomObject]@{ Name = "Action-Test - [Src-Custom]" - Outcome = $ActionTestSrcCustomOutcome + Outcome = $env:ActionTestSrcCustomOutcome ExpectedOutcome = $ActionTestSrcCustomExpectedOutcome PassedOutcome = $ActionTestSrcCustomOutcomeResult - Conclusion = $ActionTestSrcCustomConclusion + Conclusion = $env:ActionTestSrcCustomConclusion ExpectedConclusion = $ActionTestSrcCustomExpectedConclusion PassedConclusion = $ActionTestSrcCustomConclusionResult }, [PSCustomObject]@{ Name = "Action-Test - [Src-WithManifest]" - Outcome = $ActionTestSrcWithManifestOutcome + Outcome = $env:ActionTestSrcWithManifestOutcome ExpectedOutcome = $ActionTestSrcWithManifestExpectedOutcome PassedOutcome = $ActionTestSrcWithManifestOutcomeResult - Conclusion = $ActionTestSrcWithManifestConclusion + Conclusion = $env:ActionTestSrcWithManifestConclusion ExpectedConclusion = $ActionTestSrcWithManifestExpectedConclusion PassedConclusion = $ActionTestSrcWithManifestConclusionResult }, [PSCustomObject]@{ Name = "Action-Test - [outputs]" - Outcome = $ActionTestOutputsOutcome + Outcome = $env:ActionTestOutputsOutcome ExpectedOutcome = $ActionTestOutputsExpectedOutcome PassedOutcome = $ActionTestOutputsOutcomeResult - Conclusion = $ActionTestOutputsConclusion + Conclusion = $env:ActionTestOutputsConclusion ExpectedConclusion = $ActionTestOutputsExpectedConclusion PassedConclusion = $ActionTestOutputsConclusionResult } From c07c4c325258ce7c51e64688401bb21b5fe4b9e6 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 21:10:22 +0100 Subject: [PATCH 25/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Refactor=20GitH?= =?UTF-8?q?ub=20Actions=20workflow=20to=20simplify=20job=20status=20aggreg?= =?UTF-8?q?ation=20and=20add=20a=20new=20script=20for=20result=20processin?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/Action-Test.yml | 115 ++++-------------------------- tests/Get-AggregatedStatus.ps1 | 91 +++++++++++++++++++++++ 2 files changed, 103 insertions(+), 103 deletions(-) create mode 100644 tests/Get-AggregatedStatus.ps1 diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index e918968..6491861 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -52,7 +52,7 @@ jobs: CatchJob: - name: "Catch Job - Aggregate Status" + name: Aggregate Status needs: - ActionTestSrcSourceCode - ActionTestSrcCustom @@ -60,108 +60,17 @@ jobs: - ActionTestOutputs 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 }} + ActionTestOutputsOutcome: ${{ needs.ActionTestOutputs.outputs.Outcome }} + ActionTestOutputsConclusion: ${{ needs.ActionTestOutputs.outputs.Conclusion }} steps: - - name: Display Aggregated Results as a Table + - name: Aggregated Status uses: PSModule/Github-Script@v1 - 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 }} - ActionTestOutputsOutcome: ${{ needs.ActionTestOutputs.outputs.Outcome }} - ActionTestOutputsConclusion: ${{ needs.ActionTestOutputs.outputs.Conclusion }} with: - Script: | - Install-PSResource -Name Markdown -Repository PSGallery -TrustRepository - - # Build an array of objects for each job - $ActionTestSrcSourceCodeExpectedOutcome = "success" - $ActionTestSrcSourceCodeOutcomeResult = $env:ActionTestSrcSourceCodeOutcome -eq $ActionTestSrcSourceCodeExpectedOutcome - $ActionTestSrcSourceCodeExpectedConclusion = "success" - $ActionTestSrcSourceCodeConclusionResult = $env:ActionTestSrcSourceCodeConclusion -eq $ActionTestSrcSourceCodeExpectedConclusion - - $ActionTestSrcCustomExpectedOutcome = "success" - $ActionTestSrcCustomOutcomeResult = $env:ActionTestSrcCustomOutcome -eq $ActionTestSrcCustomExpectedOutcome - $ActionTestSrcCustomExpectedConclusion = "success" - $ActionTestSrcCustomConclusionResult = $env:ActionTestSrcCustomConclusion -eq $ActionTestSrcCustomExpectedConclusion - - $ActionTestSrcWithManifestExpectedOutcome = "failure" - $ActionTestSrcWithManifestOutcomeResult = $env:ActionTestSrcWithManifestOutcome -eq $ActionTestSrcWithManifestExpectedOutcome - $ActionTestSrcWithManifestExpectedConclusion = "success" - $ActionTestSrcWithManifestConclusionResult = $env:ActionTestSrcWithManifestConclusion -eq $ActionTestSrcWithManifestExpectedConclusion - - $ActionTestOutputsExpectedOutcome = "success" - $ActionTestOutputsOutcomeResult = $env:ActionTestOutputsOutcome -eq $ActionTestOutputsExpectedOutcome - $ActionTestOutputsExpectedConclusion = "success" - $ActionTestOutputsConclusionResult = $env:ActionTestOutputsConclusion -eq $ActionTestOutputsExpectedConclusion - - $jobs = @( - [PSCustomObject]@{ - Name = "Action-Test - [Src-SourceCode]" - Outcome = $env:ActionTestSrcSourceCodeOutcome - ExpectedOutcome = $ActionTestSrcSourceCodeExpectedOutcome - PassedOutcome = $ActionTestSrcSourceCodeOutcomeResult - Conclusion = $env:ActionTestSrcSourceCodeConclusion - ExpectedConclusion = $ActionTestSrcSourceCodeExpectedConclusion - PassedConclusion = $ActionTestSrcSourceCodeConclusionResult - }, - [PSCustomObject]@{ - Name = "Action-Test - [Src-Custom]" - Outcome = $env:ActionTestSrcCustomOutcome - ExpectedOutcome = $ActionTestSrcCustomExpectedOutcome - PassedOutcome = $ActionTestSrcCustomOutcomeResult - Conclusion = $env:ActionTestSrcCustomConclusion - ExpectedConclusion = $ActionTestSrcCustomExpectedConclusion - PassedConclusion = $ActionTestSrcCustomConclusionResult - }, - [PSCustomObject]@{ - Name = "Action-Test - [Src-WithManifest]" - Outcome = $env:ActionTestSrcWithManifestOutcome - ExpectedOutcome = $ActionTestSrcWithManifestExpectedOutcome - PassedOutcome = $ActionTestSrcWithManifestOutcomeResult - Conclusion = $env:ActionTestSrcWithManifestConclusion - ExpectedConclusion = $ActionTestSrcWithManifestExpectedConclusion - PassedConclusion = $ActionTestSrcWithManifestConclusionResult - }, - [PSCustomObject]@{ - Name = "Action-Test - [outputs]" - Outcome = $env:ActionTestOutputsOutcome - ExpectedOutcome = $ActionTestOutputsExpectedOutcome - PassedOutcome = $ActionTestOutputsOutcomeResult - Conclusion = $env:ActionTestOutputsConclusion - ExpectedConclusion = $ActionTestOutputsExpectedConclusion - PassedConclusion = $ActionTestOutputsConclusionResult - } - ) - - # Display the table in the workflow logs - $jobs | Format-List - - $passed = $true - $jobs | ForEach-Object { - if (-not $_.PassedOutcome) { - Write-Error "Job $($_.Name) failed with Outcome $($_.Outcome) and Expected Outcome $($_.ExpectedOutcome)" - $passed = $false - } - - if (-not $_.PassedConclusion) { - Write-Error "Job $($_.Name) failed with Conclusion $($_.Conclusion) and Expected Conclusion $($_.ExpectedConclusion)" - $passed = $false - } - } - - $icon = if ($passed) { '✅' } else { '❌' } - $status = Heading 1 "$icon - GitHub Actions Status" { - Table { - $jobs - } - } - - Set-GitHubStepSummary -Summary $status - - if (-not $passed) { - Write-GithubError "One or more jobs failed" - exit 1 - } + Script: ./tests/Get-AggregatedStatus.ps1 diff --git a/tests/Get-AggregatedStatus.ps1 b/tests/Get-AggregatedStatus.ps1 new file mode 100644 index 0000000..95f2f11 --- /dev/null +++ b/tests/Get-AggregatedStatus.ps1 @@ -0,0 +1,91 @@ +Install-PSResource -Name Markdown -Repository PSGallery -TrustRepository + +# Build an array of objects for each job +$ActionTestSrcSourceCodeExpectedOutcome = 'success' +$ActionTestSrcSourceCodeOutcomeResult = $env:ActionTestSrcSourceCodeOutcome -eq $ActionTestSrcSourceCodeExpectedOutcome +$ActionTestSrcSourceCodeExpectedConclusion = 'success' +$ActionTestSrcSourceCodeConclusionResult = $env:ActionTestSrcSourceCodeConclusion -eq $ActionTestSrcSourceCodeExpectedConclusion + +$ActionTestSrcCustomExpectedOutcome = 'success' +$ActionTestSrcCustomOutcomeResult = $env:ActionTestSrcCustomOutcome -eq $ActionTestSrcCustomExpectedOutcome +$ActionTestSrcCustomExpectedConclusion = 'success' +$ActionTestSrcCustomConclusionResult = $env:ActionTestSrcCustomConclusion -eq $ActionTestSrcCustomExpectedConclusion + +$ActionTestSrcWithManifestExpectedOutcome = 'failure' +$ActionTestSrcWithManifestOutcomeResult = $env:ActionTestSrcWithManifestOutcome -eq $ActionTestSrcWithManifestExpectedOutcome +$ActionTestSrcWithManifestExpectedConclusion = 'success' +$ActionTestSrcWithManifestConclusionResult = $env:ActionTestSrcWithManifestConclusion -eq $ActionTestSrcWithManifestExpectedConclusion + +$ActionTestOutputsExpectedOutcome = 'success' +$ActionTestOutputsOutcomeResult = $env:ActionTestOutputsOutcome -eq $ActionTestOutputsExpectedOutcome +$ActionTestOutputsExpectedConclusion = 'success' +$ActionTestOutputsConclusionResult = $env:ActionTestOutputsConclusion -eq $ActionTestOutputsExpectedConclusion + +$jobs = @( + [PSCustomObject]@{ + Name = 'Action-Test - [Src-SourceCode]' + Outcome = $env:ActionTestSrcSourceCodeOutcome + ExpectedOutcome = $ActionTestSrcSourceCodeExpectedOutcome + PassedOutcome = $ActionTestSrcSourceCodeOutcomeResult + Conclusion = $env:ActionTestSrcSourceCodeConclusion + ExpectedConclusion = $ActionTestSrcSourceCodeExpectedConclusion + PassedConclusion = $ActionTestSrcSourceCodeConclusionResult + }, + [PSCustomObject]@{ + Name = 'Action-Test - [Src-Custom]' + Outcome = $env:ActionTestSrcCustomOutcome + ExpectedOutcome = $ActionTestSrcCustomExpectedOutcome + PassedOutcome = $ActionTestSrcCustomOutcomeResult + Conclusion = $env:ActionTestSrcCustomConclusion + ExpectedConclusion = $ActionTestSrcCustomExpectedConclusion + PassedConclusion = $ActionTestSrcCustomConclusionResult + }, + [PSCustomObject]@{ + Name = 'Action-Test - [Src-WithManifest]' + Outcome = $env:ActionTestSrcWithManifestOutcome + ExpectedOutcome = $ActionTestSrcWithManifestExpectedOutcome + PassedOutcome = $ActionTestSrcWithManifestOutcomeResult + Conclusion = $env:ActionTestSrcWithManifestConclusion + ExpectedConclusion = $ActionTestSrcWithManifestExpectedConclusion + PassedConclusion = $ActionTestSrcWithManifestConclusionResult + }, + [PSCustomObject]@{ + Name = 'Action-Test - [outputs]' + Outcome = $env:ActionTestOutputsOutcome + ExpectedOutcome = $ActionTestOutputsExpectedOutcome + PassedOutcome = $ActionTestOutputsOutcomeResult + Conclusion = $env:ActionTestOutputsConclusion + ExpectedConclusion = $ActionTestOutputsExpectedConclusion + PassedConclusion = $ActionTestOutputsConclusionResult + } +) + +# Display the table in the workflow logs +$jobs | Format-List + +$passed = $true +$jobs | ForEach-Object { + if (-not $_.PassedOutcome) { + Write-Error "Job $($_.Name) failed with Outcome $($_.Outcome) and Expected Outcome $($_.ExpectedOutcome)" + $passed = $false + } + + if (-not $_.PassedConclusion) { + Write-Error "Job $($_.Name) failed with Conclusion $($_.Conclusion) and Expected Conclusion $($_.ExpectedConclusion)" + $passed = $false + } +} + +$icon = if ($passed) { '✅' } else { '❌' } +$status = Heading 1 "$icon - GitHub Actions Status" { + Table { + $jobs + } +} + +Set-GitHubStepSummary -Summary $status + +if (-not $passed) { + Write-GitHubError 'One or more jobs failed' + exit 1 +} From 502c9d221dc15be89202a1e7db2bef5237f7d80f Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 21:18:48 +0100 Subject: [PATCH 26/32] Remove redundant job status checks and streamline output handling in Get-AggregatedStatus.ps1 --- .github/workflows/Action-Test.yml | 196 ++++++++++++++++++++++++++---- tests/Get-AggregatedStatus.ps1 | 92 +------------- 2 files changed, 175 insertions(+), 113 deletions(-) diff --git a/.github/workflows/Action-Test.yml b/.github/workflows/Action-Test.yml index 6491861..d39594a 100644 --- a/.github/workflows/Action-Test.yml +++ b/.github/workflows/Action-Test.yml @@ -19,37 +19,97 @@ permissions: jobs: ActionTestSrcSourceCode: name: Action-Test - [Src-SourceCode] - uses: ./.github/workflows/ActionTestWorkflow.yml - with: - TestType: Src-SourceCode - Path: tests/srcTestRepo/src - Settings: SourceCode + runs-on: ubuntu-latest + outputs: + Outcome: ${{ steps.action-test.outcome }} + Conclusion: ${{ steps.action-test.conclusion }} + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Action-Test + uses: ./ + id: action-test + with: + Path: tests/srcTestRepo/src + Settings: SourceCode + + - name: Status + shell: pwsh + run: | + Write-Host "Outcome: ${{ steps.action-test.outcome }}" + Write-Host "Conclusion: ${{ steps.action-test.conclusion }}" ActionTestSrcCustom: name: Action-Test - [Src-Custom] - uses: ./.github/workflows/ActionTestWorkflow.yml - with: - TestType: Src-Custom - Path: tests/srcTestRepo/src - Settings: Custom - SettingsFilePath: tests/srcTestRepo/tests/Custom.Settings.psd1 + runs-on: ubuntu-latest + outputs: + Outcome: ${{ steps.action-test.outcome }} + Conclusion: ${{ steps.action-test.conclusion }} + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Action-Test + uses: ./ + id: action-test + with: + Path: tests/srcTestRepo/src + Settings: Custom + SettingsFilePath: tests/srcTestRepo/tests/Custom.Settings.psd1 + + - name: Status + shell: pwsh + run: | + Write-Host "Outcome: ${{ steps.action-test.outcome }}" + Write-Host "Conclusion: ${{ steps.action-test.conclusion }}" ActionTestSrcWithManifest: name: Action-Test - [Src-WithManifest] - uses: ./.github/workflows/ActionTestWorkflow.yml - with: - TestType: Src-WithManifest - Path: tests/srcWithManifestTestRepo/src - Settings: SourceCode + runs-on: ubuntu-latest + outputs: + Outcome: ${{ steps.action-test.outcome }} + Conclusion: ${{ steps.action-test.conclusion }} + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Action-Test + uses: ./ + continue-on-error: true + id: action-test + with: + Path: tests/srcWithManifestTestRepo/src + Settings: SourceCode + + - name: Status + shell: pwsh + run: | + Write-Host "Outcome: ${{ steps.action-test.outcome }}" + Write-Host "Conclusion: ${{ steps.action-test.conclusion }}" ActionTestOutputs: name: Action-Test - [outputs] - uses: ./.github/workflows/ActionTestWorkflow.yml - with: - TestType: outputs - Path: tests/outputTestRepo/outputs/modules/PSModuleTest - Settings: Module + runs-on: ubuntu-latest + outputs: + Outcome: ${{ steps.action-test.outcome }} + Conclusion: ${{ steps.action-test.conclusion }} + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Action-Test + uses: ./ + id: action-test + with: + Path: tests/outputTestRepo/outputs/modules/PSModuleTest + Settings: Module + - name: Status + shell: pwsh + run: | + Write-Host "Outcome: ${{ steps.action-test.outcome }}" + Write-Host "Conclusion: ${{ steps.action-test.conclusion }}" CatchJob: name: Aggregate Status @@ -73,4 +133,96 @@ jobs: - name: Aggregated Status uses: PSModule/Github-Script@v1 with: - Script: ./tests/Get-AggregatedStatus.ps1 + Script: | + Install-PSResource -Name Markdown -Repository PSGallery -TrustRepository + + # Build an array of objects for each job + $ActionTestSrcSourceCodeExpectedOutcome = 'success' + $ActionTestSrcSourceCodeOutcomeResult = $env:ActionTestSrcSourceCodeOutcome -eq $ActionTestSrcSourceCodeExpectedOutcome + $ActionTestSrcSourceCodeExpectedConclusion = 'success' + $ActionTestSrcSourceCodeConclusionResult = $env:ActionTestSrcSourceCodeConclusion -eq $ActionTestSrcSourceCodeExpectedConclusion + + $ActionTestSrcCustomExpectedOutcome = 'success' + $ActionTestSrcCustomOutcomeResult = $env:ActionTestSrcCustomOutcome -eq $ActionTestSrcCustomExpectedOutcome + $ActionTestSrcCustomExpectedConclusion = 'success' + $ActionTestSrcCustomConclusionResult = $env:ActionTestSrcCustomConclusion -eq $ActionTestSrcCustomExpectedConclusion + + $ActionTestSrcWithManifestExpectedOutcome = 'failure' + $ActionTestSrcWithManifestOutcomeResult = $env:ActionTestSrcWithManifestOutcome -eq $ActionTestSrcWithManifestExpectedOutcome + $ActionTestSrcWithManifestExpectedConclusion = 'success' + $ActionTestSrcWithManifestConclusionResult = $env:ActionTestSrcWithManifestConclusion -eq $ActionTestSrcWithManifestExpectedConclusion + + $ActionTestOutputsExpectedOutcome = 'success' + $ActionTestOutputsOutcomeResult = $env:ActionTestOutputsOutcome -eq $ActionTestOutputsExpectedOutcome + $ActionTestOutputsExpectedConclusion = 'success' + $ActionTestOutputsConclusionResult = $env:ActionTestOutputsConclusion -eq $ActionTestOutputsExpectedConclusion + + $jobs = @( + [PSCustomObject]@{ + Name = 'Action-Test - [Src-SourceCode]' + Outcome = $env:ActionTestSrcSourceCodeOutcome + ExpectedOutcome = $ActionTestSrcSourceCodeExpectedOutcome + PassedOutcome = $ActionTestSrcSourceCodeOutcomeResult + Conclusion = $env:ActionTestSrcSourceCodeConclusion + ExpectedConclusion = $ActionTestSrcSourceCodeExpectedConclusion + PassedConclusion = $ActionTestSrcSourceCodeConclusionResult + }, + [PSCustomObject]@{ + Name = 'Action-Test - [Src-Custom]' + Outcome = $env:ActionTestSrcCustomOutcome + ExpectedOutcome = $ActionTestSrcCustomExpectedOutcome + PassedOutcome = $ActionTestSrcCustomOutcomeResult + Conclusion = $env:ActionTestSrcCustomConclusion + ExpectedConclusion = $ActionTestSrcCustomExpectedConclusion + PassedConclusion = $ActionTestSrcCustomConclusionResult + }, + [PSCustomObject]@{ + Name = 'Action-Test - [Src-WithManifest]' + Outcome = $env:ActionTestSrcWithManifestOutcome + ExpectedOutcome = $ActionTestSrcWithManifestExpectedOutcome + PassedOutcome = $ActionTestSrcWithManifestOutcomeResult + Conclusion = $env:ActionTestSrcWithManifestConclusion + ExpectedConclusion = $ActionTestSrcWithManifestExpectedConclusion + PassedConclusion = $ActionTestSrcWithManifestConclusionResult + }, + [PSCustomObject]@{ + Name = 'Action-Test - [outputs]' + Outcome = $env:ActionTestOutputsOutcome + ExpectedOutcome = $ActionTestOutputsExpectedOutcome + PassedOutcome = $ActionTestOutputsOutcomeResult + Conclusion = $env:ActionTestOutputsConclusion + ExpectedConclusion = $ActionTestOutputsExpectedConclusion + PassedConclusion = $ActionTestOutputsConclusionResult + } + ) + + # Display the table in the workflow logs + $jobs | Format-List + + $passed = $true + $jobs | ForEach-Object { + if (-not $_.PassedOutcome) { + Write-Error "Job $($_.Name) failed with Outcome $($_.Outcome) and Expected Outcome $($_.ExpectedOutcome)" + $passed = $false + } + + if (-not $_.PassedConclusion) { + Write-Error "Job $($_.Name) failed with Conclusion $($_.Conclusion) and Expected Conclusion $($_.ExpectedConclusion)" + $passed = $false + } + } + + $icon = if ($passed) { '✅' } else { '❌' } + $status = Heading 1 "$icon - GitHub Actions Status" { + Table { + $jobs + } + } + + Set-GitHubStepSummary -Summary $status + + if (-not $passed) { + Write-GitHubError 'One or more jobs failed' + exit 1 + } + diff --git a/tests/Get-AggregatedStatus.ps1 b/tests/Get-AggregatedStatus.ps1 index 95f2f11..5f28270 100644 --- a/tests/Get-AggregatedStatus.ps1 +++ b/tests/Get-AggregatedStatus.ps1 @@ -1,91 +1 @@ -Install-PSResource -Name Markdown -Repository PSGallery -TrustRepository - -# Build an array of objects for each job -$ActionTestSrcSourceCodeExpectedOutcome = 'success' -$ActionTestSrcSourceCodeOutcomeResult = $env:ActionTestSrcSourceCodeOutcome -eq $ActionTestSrcSourceCodeExpectedOutcome -$ActionTestSrcSourceCodeExpectedConclusion = 'success' -$ActionTestSrcSourceCodeConclusionResult = $env:ActionTestSrcSourceCodeConclusion -eq $ActionTestSrcSourceCodeExpectedConclusion - -$ActionTestSrcCustomExpectedOutcome = 'success' -$ActionTestSrcCustomOutcomeResult = $env:ActionTestSrcCustomOutcome -eq $ActionTestSrcCustomExpectedOutcome -$ActionTestSrcCustomExpectedConclusion = 'success' -$ActionTestSrcCustomConclusionResult = $env:ActionTestSrcCustomConclusion -eq $ActionTestSrcCustomExpectedConclusion - -$ActionTestSrcWithManifestExpectedOutcome = 'failure' -$ActionTestSrcWithManifestOutcomeResult = $env:ActionTestSrcWithManifestOutcome -eq $ActionTestSrcWithManifestExpectedOutcome -$ActionTestSrcWithManifestExpectedConclusion = 'success' -$ActionTestSrcWithManifestConclusionResult = $env:ActionTestSrcWithManifestConclusion -eq $ActionTestSrcWithManifestExpectedConclusion - -$ActionTestOutputsExpectedOutcome = 'success' -$ActionTestOutputsOutcomeResult = $env:ActionTestOutputsOutcome -eq $ActionTestOutputsExpectedOutcome -$ActionTestOutputsExpectedConclusion = 'success' -$ActionTestOutputsConclusionResult = $env:ActionTestOutputsConclusion -eq $ActionTestOutputsExpectedConclusion - -$jobs = @( - [PSCustomObject]@{ - Name = 'Action-Test - [Src-SourceCode]' - Outcome = $env:ActionTestSrcSourceCodeOutcome - ExpectedOutcome = $ActionTestSrcSourceCodeExpectedOutcome - PassedOutcome = $ActionTestSrcSourceCodeOutcomeResult - Conclusion = $env:ActionTestSrcSourceCodeConclusion - ExpectedConclusion = $ActionTestSrcSourceCodeExpectedConclusion - PassedConclusion = $ActionTestSrcSourceCodeConclusionResult - }, - [PSCustomObject]@{ - Name = 'Action-Test - [Src-Custom]' - Outcome = $env:ActionTestSrcCustomOutcome - ExpectedOutcome = $ActionTestSrcCustomExpectedOutcome - PassedOutcome = $ActionTestSrcCustomOutcomeResult - Conclusion = $env:ActionTestSrcCustomConclusion - ExpectedConclusion = $ActionTestSrcCustomExpectedConclusion - PassedConclusion = $ActionTestSrcCustomConclusionResult - }, - [PSCustomObject]@{ - Name = 'Action-Test - [Src-WithManifest]' - Outcome = $env:ActionTestSrcWithManifestOutcome - ExpectedOutcome = $ActionTestSrcWithManifestExpectedOutcome - PassedOutcome = $ActionTestSrcWithManifestOutcomeResult - Conclusion = $env:ActionTestSrcWithManifestConclusion - ExpectedConclusion = $ActionTestSrcWithManifestExpectedConclusion - PassedConclusion = $ActionTestSrcWithManifestConclusionResult - }, - [PSCustomObject]@{ - Name = 'Action-Test - [outputs]' - Outcome = $env:ActionTestOutputsOutcome - ExpectedOutcome = $ActionTestOutputsExpectedOutcome - PassedOutcome = $ActionTestOutputsOutcomeResult - Conclusion = $env:ActionTestOutputsConclusion - ExpectedConclusion = $ActionTestOutputsExpectedConclusion - PassedConclusion = $ActionTestOutputsConclusionResult - } -) - -# Display the table in the workflow logs -$jobs | Format-List - -$passed = $true -$jobs | ForEach-Object { - if (-not $_.PassedOutcome) { - Write-Error "Job $($_.Name) failed with Outcome $($_.Outcome) and Expected Outcome $($_.ExpectedOutcome)" - $passed = $false - } - - if (-not $_.PassedConclusion) { - Write-Error "Job $($_.Name) failed with Conclusion $($_.Conclusion) and Expected Conclusion $($_.ExpectedConclusion)" - $passed = $false - } -} - -$icon = if ($passed) { '✅' } else { '❌' } -$status = Heading 1 "$icon - GitHub Actions Status" { - Table { - $jobs - } -} - -Set-GitHubStepSummary -Summary $status - -if (-not $passed) { - Write-GitHubError 'One or more jobs failed' - exit 1 -} + \ No newline at end of file From dddc1439e39f152e50fcf41c31c416aa7e5b047c Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 21:26:16 +0100 Subject: [PATCH 27/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Remove=20deprec?= =?UTF-8?q?ated=20ActionTest=20workflow=20to=20streamline=20GitHub=20Actio?= =?UTF-8?q?ns=20configuration?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/ActionTestWorkflow.yml | 47 ------------------------ 1 file changed, 47 deletions(-) delete mode 100644 .github/workflows/ActionTestWorkflow.yml diff --git a/.github/workflows/ActionTestWorkflow.yml b/.github/workflows/ActionTestWorkflow.yml deleted file mode 100644 index 25c044b..0000000 --- a/.github/workflows/ActionTestWorkflow.yml +++ /dev/null @@ -1,47 +0,0 @@ -on: - workflow_call: - inputs: - TestType: - type: string - required: true - Path: - type: string - required: true - Settings: - type: string - required: false - SettingsFilePath: - type: string - required: false - -permissions: {} - -jobs: - ActionTest: - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest, macos-latest, windows-latest] - name: ${{ matrix.os }} - runs-on: ${{ matrix.os }} - outputs: - Outcome: ${{ steps.action-test.outcome }} - Conclusion: ${{ steps.action-test.conclusion }} - steps: - - name: Checkout repo - uses: actions/checkout@v4 - - - name: Action-Test - uses: ./ - continue-on-error: true - id: action-test - with: - Path: ${{ inputs.Path }} - Settings: ${{ inputs.Settings }} - SettingsFilePath: ${{ inputs.SettingsFilePath }} - - - name: Status - shell: pwsh - run: | - Write-Host "Outcome: ${{ steps.action-test.outcome }}" - Write-Host "Conclusion: ${{ steps.action-test.conclusion }}" From f72c97737bf1b95bb34a8ed9380788d7f417bf36 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 21:30:37 +0100 Subject: [PATCH 28/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20linter?= =?UTF-8?q?=20configuration=20to=20exclude=20Action-Test=20workflow=20and?= =?UTF-8?q?=20specific=20test=20files=20from=20analysis?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/linters/.jscpd.json | 3 ++- .github/workflows/Linter.yml | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/linters/.jscpd.json b/.github/linters/.jscpd.json index 23970e8..45fb955 100644 --- a/.github/linters/.jscpd.json +++ b/.github/linters/.jscpd.json @@ -4,7 +4,8 @@ "consoleFull" ], "ignore": [ - "**/tests/**" + "**/tests/**", + "**.github/workflows/Action-Test.yml" ], "absolute": true } diff --git a/.github/workflows/Linter.yml b/.github/workflows/Linter.yml index 1f677cb..2a5205f 100644 --- a/.github/workflows/Linter.yml +++ b/.github/workflows/Linter.yml @@ -30,3 +30,4 @@ jobs: VALIDATE_JSON_PRETTIER: false VALIDATE_MARKDOWN_PRETTIER: false VALIDATE_YAML_PRETTIER: false + FILTER_REGEX_EXCLUDE: 'tests/srcWithManifestTestRepo/src/functions/public/SomethingElse/Set-PSModuleTest\.ps1$' From a8f4a6d237f2d37e32057eb8518063add42526f9 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 21:35:26 +0100 Subject: [PATCH 29/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20linter?= =?UTF-8?q?=20configuration=20to=20correct=20file=20path=20and=20adjust=20?= =?UTF-8?q?filter=20regex=20for=20exclusion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/linters/.jscpd.json | 2 +- .github/workflows/Linter.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/linters/.jscpd.json b/.github/linters/.jscpd.json index 45fb955..88330de 100644 --- a/.github/linters/.jscpd.json +++ b/.github/linters/.jscpd.json @@ -5,7 +5,7 @@ ], "ignore": [ "**/tests/**", - "**.github/workflows/Action-Test.yml" + "**/.github/workflows/Action-Test.yml" ], "absolute": true } diff --git a/.github/workflows/Linter.yml b/.github/workflows/Linter.yml index 2a5205f..192ab27 100644 --- a/.github/workflows/Linter.yml +++ b/.github/workflows/Linter.yml @@ -30,4 +30,4 @@ jobs: VALIDATE_JSON_PRETTIER: false VALIDATE_MARKDOWN_PRETTIER: false VALIDATE_YAML_PRETTIER: false - FILTER_REGEX_EXCLUDE: 'tests/srcWithManifestTestRepo/src/functions/public/SomethingElse/Set-PSModuleTest\.ps1$' + FILTER_REGEX_EXCLUDE: '.*Set-PSModuleTest\.ps1$' From 05c04831b712988654b18a2165a5f4addb0f8386 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 21:51:01 +0100 Subject: [PATCH 30/32] Update README.md to clarify action outputs and improve workflow documentation --- README.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 8ee34ce..953b82d 100644 --- a/README.md +++ b/README.md @@ -23,9 +23,7 @@ customize rule selection, severity filtering, and custom rule inclusion. ## Outputs -| Output | Description | Value | -|----------|--------------------------------|------------------------------------| -| `passed` | Indicates if the tests passed. | `${{ steps.test.outputs.Passed }}` | +N/A ## How It Works @@ -56,11 +54,12 @@ customize rule selection, severity filtering, and custom rule inclusion. To be clear; the action follows the settings file to determine which rules to skip. 4. **View the Results** - The action outputs the results of the tests. If the tests pass, the action - will return a `passed` output with a value of `true`. If the tests fail, the - action will return a `passed` output with a value of `false`. + The action outputs the results of the tests to goth logs and step summary. If the tests pass, the actions `outcome` will be `success`. + If the tests fail, the actions outcome will be `failure`. To make the workflow continue even if the tests fail, you can set the + `continue-on-error` option to `true`. Use this built-in feature to stop the workflow from failing so that you can aggregate the status of tests + across multiple jobs. - The action also outputs the results of the tests to the console. + An example of how this is done can be seen in the [Action-Test workflow](.github/workflows/Action-Test.yml) file. ## Example Workflow From 458a0b12be164470af4a53f2d22c450ed2064871 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 21:51:19 +0100 Subject: [PATCH 31/32] Update Invoke-ScriptAnalyzer action to version 2 in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 953b82d..5f654fc 100644 --- a/README.md +++ b/README.md @@ -78,7 +78,7 @@ jobs: uses: actions/checkout@v2 - name: Invoke PSScriptAnalyzer - uses: PSModule/Invoke-ScriptAnalyzer@v1 + uses: PSModule/Invoke-ScriptAnalyzer@v2 with: Path: ${{ github.workspace }} Settings: SourceCode From 68bf0f1b1b8cb572883c5726633617e68c68af10 Mon Sep 17 00:00:00 2001 From: Marius Storhaug Date: Sun, 23 Feb 2025 21:57:47 +0100 Subject: [PATCH 32/32] =?UTF-8?q?=F0=9F=A9=B9=20[Patch]:=20Update=20README?= =?UTF-8?q?.md=20and=20action.yml=20to=20mark=20'Path'=20input=20as=20opti?= =?UTF-8?q?onal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- action.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5f654fc..e4e9292 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ customize rule selection, severity filtering, and custom rule inclusion. | Input | Description | Required | Default | |---------------------|----------------------------------------------------------------|----------|-----------------------------------------------------------------------------| -| **Path** | The path to the code to test. | Yes | `${{ github.workspace }}` | +| **Path** | The path to the code to test. | No | `${{ github.workspace }}` | | **Settings** | The type of tests to run: `Module`, `SourceCode`, or `Custom`. | No | `Custom` | | **SettingsFilePath**| If `Custom` is selected, the path to the settings file. | No | `${{ github.workspace }}/.github/linters/.powershell-psscriptanalyzer.psd1` | diff --git a/action.yml b/action.yml index e8bfe3d..2714a8b 100644 --- a/action.yml +++ b/action.yml @@ -8,7 +8,7 @@ branding: inputs: Path: description: The path to the code to test. - required: true + required: false default: ${{ github.workspace }} Settings: description: The type of tests to run. Can be either 'Module', 'SourceCode' or 'Custom'.