From a231feac91a6cac03b0a465cd255d3638dd3f5ff Mon Sep 17 00:00:00 2001 From: Jonathan Butler Date: Tue, 19 Nov 2024 16:44:44 -0500 Subject: [PATCH] Add psscriptanalyzer.yml to separate pester tests (validate.yml) from psscriptanalyzer tests. --- .github/workflows/psscriptanalzyer.yml | 61 +++++++++++++++++++++++ Hawk/tests/general/Test-PreCommitHook.ps1 | 1 + 2 files changed, 62 insertions(+) create mode 100644 .github/workflows/psscriptanalzyer.yml diff --git a/.github/workflows/psscriptanalzyer.yml b/.github/workflows/psscriptanalzyer.yml new file mode 100644 index 0000000..889e4c0 --- /dev/null +++ b/.github/workflows/psscriptanalzyer.yml @@ -0,0 +1,61 @@ +name: PSScriptAnalyzer +on: + pull_request: + paths: + - "**.ps1" + - "**.psm1" + - "**.psd1" + push: + branches: + - main + - Development + - "feature/144-implement-dual-validation-psscriptanalyzer-with-standardized-settings" + paths: + - "**.ps1" + - "**.psm1" + - "**.psd1" + +jobs: + analyze: + name: PSScriptAnalyzer + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + - name: Install PSScriptAnalyzer + shell: pwsh + run: | + Set-PSRepository PSGallery -InstallationPolicy Trusted + Install-Module PSScriptAnalyzer -Force + + - name: Run PSScriptAnalyzer + shell: pwsh + run: | + $settings = Join-Path $env:GITHUB_WORKSPACE '.github/psscriptanalyzer/PSScriptAnalyzerSettings.psd1' + $results = @() + + # Analyze all PowerShell files + Get-ChildItem -Path $env:GITHUB_WORKSPACE -Recurse -Include *.ps1,*.psm1,*.psd1 | + ForEach-Object { + $analysis = Invoke-ScriptAnalyzer -Path $_.FullName -Settings $settings + if ($analysis) { + $results += $analysis + } + } + + # Output results + if ($results) { + $results | Format-Table -AutoSize + Write-Output "::error::PSScriptAnalyzer found $($results.Count) issues" + exit 1 + } else { + Write-Output "No PSScriptAnalyzer issues found" + } + + - name: Upload PSScriptAnalyzer Results + if: failure() + uses: actions/upload-artifact@v3 + with: + name: psscriptanalyzer-results + path: psscriptanalyzer-results.txt diff --git a/Hawk/tests/general/Test-PreCommitHook.ps1 b/Hawk/tests/general/Test-PreCommitHook.ps1 index dc264a4..ea39e4b 100644 --- a/Hawk/tests/general/Test-PreCommitHook.ps1 +++ b/Hawk/tests/general/Test-PreCommitHook.ps1 @@ -5,6 +5,7 @@ # 3. Observe the PSScriptAnalyzer warnings/errors #region Good Code Examples - These will pass PSScriptAnalyzer +# add comement to test function Test-GoodFunction { [CmdletBinding()] param (