diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b20ea77..d6d7e3f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,37 +19,11 @@ jobs: lint: name: Lint (PSScriptAnalyzer) - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262 # v4 - with: - persist-credentials: false - - - name: Install PSScriptAnalyzer - shell: pwsh - run: | - Set-PSRepository -Name PSGallery -InstallationPolicy Trusted - Install-Module PSScriptAnalyzer -Scope CurrentUser -Force -ErrorAction Stop - - - name: Run PSScriptAnalyzer - shell: pwsh - run: | - $settings = "$env:GITHUB_WORKSPACE/PSScriptAnalyzerSettings.psd1" - $lessonResults = Invoke-ScriptAnalyzer -Path "$env:GITHUB_WORKSPACE/lessons" -Settings $settings -Recurse - $testResults = Invoke-ScriptAnalyzer -Path "$env:GITHUB_WORKSPACE/tests" -Settings $settings -Recurse - - $allResults = @($lessonResults) + @($testResults) - - if ($allResults.Count -gt 0) { - $allResults | Format-Table -AutoSize - Write-Error "PSScriptAnalyzer found $($allResults.Count) issue(s). See table above." - exit 1 - } - else { - Write-Output "PSScriptAnalyzer: no issues found." - } + uses: DevOpsDerek/workflows/.github/workflows/lint-powershell.yml@30f86d7d8536364b0a31de4bc66214b39e8785bb + with: + psscriptanalyzer-version: 1.24.0 + working-directory: . + settings-path: PSScriptAnalyzerSettings.psd1 test: name: Test (Pester) diff --git a/README.md b/README.md index 1a7abf7..d0581a0 100644 --- a/README.md +++ b/README.md @@ -82,10 +82,12 @@ pwsh ./lint.ps1 ## CI and Documentation Automation CI keeps separate PSScriptAnalyzer and Pester jobs, with tests running after -lint succeeds. CI analyzes both `lessons/` and `tests/` using -`PSScriptAnalyzerSettings.psd1` and fails on any diagnostic; the local -`lint.ps1` helper fails only on errors. Pester 5 or later writes NUnit XML to -`test-results.xml`, uploaded as `pester-test-results` even when tests fail. +lint succeeds. CI uses the central PSScriptAnalyzer workflow, pinned to an exact +module version, and analyzes PowerShell sources under the repository root using +`PSScriptAnalyzerSettings.psd1`; it fails on Error and Warning diagnostics. +The local `lint.ps1` helper uses the same settings and diagnostic threshold for +`lessons/` and `tests/`. Pester 5 or later writes NUnit XML to `test-results.xml`, +uploaded as `pester-test-results` even when tests fail. Automation validation comes from [`DevOpsDerek/workflows` at commit `dac4b81c298cb3ea6821ea312efa5375f42d5ccb`](https://github.com/DevOpsDerek/workflows/tree/dac4b81c298cb3ea6821ea312efa5375f42d5ccb). diff --git a/lint.ps1 b/lint.ps1 index a1d2a21..569a671 100644 --- a/lint.ps1 +++ b/lint.ps1 @@ -14,7 +14,7 @@ $paths = @( (Join-Path -Path $projectRoot -ChildPath 'tests') ) -$results = Invoke-ScriptAnalyzer -Path $paths -Settings $settingsPath -Recurse +$results = Invoke-ScriptAnalyzer -Path $paths -Settings $settingsPath -Recurse -Severity Error, Warning if (-not $results) { Write-Output 'No ScriptAnalyzer issues found.' @@ -25,7 +25,6 @@ $results | Sort-Object ScriptName, Line, Column | Format-Table Severity, RuleName, ScriptName, Line, Message -AutoSize -$errorResults = $results | Where-Object Severity -eq 'Error' -if ($errorResults) { +if ($results) { exit 1 }