Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 5 additions & 31 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
5 changes: 2 additions & 3 deletions lint.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
Expand All @@ -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
}
Loading