fix: enforce PSScriptAnalyzer in the build and unify the lint ruleset#64
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
💤 Files with no reviewable changes (1)
📝 WalkthroughWalkthroughCI ChangesPSScriptAnalyzer Enforcement Consolidation
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
This PR makes PowerShell script linting (PSScriptAnalyzer) consistently enforceable across both the psake build pipeline and the standalone CI lint job, using a single repository-owned ruleset.
Changes:
- Replaces PowerShellBuild’s non-enforcing
Analyzepsake task with a repo-definedAnalyzetask that correctly counts severities and fails the build at the configured threshold. - Configures in-build analysis to use the repo’s
PSScriptAnalyzerSettings.psd1(instead of PowerShellBuild’s bundled defaults) and re-enables analysis on non-Windows platforms. - Updates the CI lint job to use the same settings file for consistent rules between CI and in-build analysis.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| build.psake.ps1 | Sets ScriptAnalysis to use the repo ruleset and replaces the Analyze task to enforce failures by severity. |
| .github/workflows/CI.yaml | Switches the lint job to use ./PSScriptAnalyzerSettings.psd1 for the same ruleset as the build. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
0ae9803 to
38eee88
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@build.psake.ps1`:
- Line 143: The error counting line using $errorCount =
@($analysisResult).Where({ $_.Severity -eq 'Error' }).Count misses parse/syntax
failures because those have Severity 'ParseError'; update the predicate that
computes $errorCount (referencing $analysisResult and $errorCount) to treat
'ParseError' as an error too (e.g. check Severity is 'Error' or 'ParseError', or
use membership against @('Error','ParseError')) so parse errors are included in
the count.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 9a53c2b6-690c-4cad-b09f-5b9a4153a9d1
📒 Files selected for processing (2)
.github/workflows/CI.yamlbuild.psake.ps1
💤 Files with no reviewable changes (1)
- .github/workflows/CI.yaml
993a385 to
7d7445a
Compare
…t job PowerShellBuild's 'Analyze' task never fails the build: its Test-PSBuildScriptAnalysis filters results with `$_Severity` (an undefined variable) instead of `$_.Severity`, so error/warning counts are always zero. Present in every released version (through 0.8.0) and on main, so a version bump cannot fix it. Reported upstream: psake/PowerShellBuild#125. Add a custom 'Lint' task that runs Invoke-ScriptAnalyzer directly and fails at the configured FailBuildOnSeverityLevel ('Error'), counting ParseError (syntax-broken files) as errors too. The Test task depends on 'Lint' instead of PowerShellBuild's no-op 'Analyze' (which psake loads via -FromModule and won't let us redefine; it is left unused). This mirrors how other PowerShellBuild consumers define their own analysis task rather than relying on the module's no-op. Point ScriptAnalysis.SettingsPath at the repo's own PSScriptAnalyzerSettings.psd1 (PowerShellBuild defaulted to its bundled ruleset) and drop the obsolete Linux/macOS analysis-disable. Remove the standalone 'PSScriptAnalyzer Lint' CI job: now that analysis runs and enforces during the build on every platform, a separate job re-running PSScriptAnalyzer on the source tree is redundant. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
7d7445a to
305fb9e
Compare
…ver (#66) The integration-tests job hits a live, shared Plex server. Running its ubuntu and windows matrix legs at once (or across overlapping runs) causes state races - e.g. collection ItemCount assertions flaking when two jobs mutate the same server simultaneously (seen on PR #64). Add a job-level concurrency group to integration-tests with a constant group (not keyed by matrix.os or ref) so every integration job in the repo serializes, and cancel-in-progress: false so an in-progress suite is never cancelled - newer runs queue and wait. Scoped to this job only; unit tests and lint are deterministic and keep running in parallel.
Summary
Testtask pulls PowerShellBuild'sAnalyzevia-FromModule, and that task'sTest-PSBuildScriptAnalysisfilters results with$_Severity(an undefined variable) instead of$_.Severity— so its error/warning counts are always 0 and it never fails the build. This bug is in every released PowerShellBuild version (through 0.8.0, the latest) and onmain, so no version bump fixes it.Analyzetask.-FromModuledot-sources PowerShellBuild'spsakeFile(registering itsAnalyze), and psake won't let us redefine an existing task, so we remove its no-op from the psake context and define our own under the same name (depends onBuild, like the original). The new task counts$_.Severitycorrectly and throws at the configuredFailBuildOnSeverityLevel(Error).ScriptAnalysis.SettingsPathat the repo's ownPSScriptAnalyzerSettings.psd1(PowerShellBuild defaulted to its bundled ruleset).-Settings PSGalleryto the same settings file, so every analysis path shares one ruleset.Test Plan
build.psake.ps1parses; CI YAML + embedded pwsh parseAnalyzetask verified end-to-end on psake 4.9.1 (pinned CI version) and 5.0.4Errorthreshold)ErrorthresholdNotes
mainonce ci: pin PSScriptAnalyzer version in the lint job #62 merges.$_Severitybug is being reported upstream to PowerShellBuild.Breaking Changes
None expected. Analysis now genuinely runs on all platforms at the
Errorthreshold; current findings are all Warning/Information.Summary by CodeRabbit