ci: pin PSScriptAnalyzer version in the lint job#62
Conversation
The PSScriptAnalyzer Lint job installed PSScriptAnalyzer unpinned and called Invoke-ScriptAnalyzer without an explicit Import-Module, so it ignored the 1.24.0 pin in build.depend.psd1 (which only the build/test jobs honor via PSDepend). On a cache hit the install step was skipped entirely, letting the runner image's bundled copy load alongside the cached one and crash with "You cannot have more than one dynamic module in each dynamic assembly in this version of the runtime" (seen on main after #55, while the identical PR tree had passed minutes earlier). Read the pinned version from build.depend.psd1, install that exact version (verified present even on a cache hit), and import it explicitly with -RequiredVersion before Invoke-ScriptAnalyzer so exactly one assembly version loads. The cache key already hashes build.depend.psd1, so the installed version and cache stay coupled with a single source of truth. Verified in a pwsh 7.5 / ubuntu-24.04 container: with a polluted module path (1.25.0 pre-installed), the step still installs and loads exactly 1.24.0 and analyzes cleanly. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
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 (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe CI lint job now reads the pinned PSScriptAnalyzer version from ChangesCI Lint Job Module Management
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 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 the CI lint job use the same pinned PSScriptAnalyzer version as the rest of the build, reducing environment-dependent failures from runner-provided or cached module versions.
Changes:
- Removes cache-hit gating so the lint job always verifies the required PSScriptAnalyzer version.
- Reads the pinned version from
build.depend.psd1. - Explicitly imports that pinned version before running
Invoke-ScriptAnalyzer.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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 @.github/workflows/CI.yaml:
- Line 61: Add -ErrorAction Stop to the PowerShell module installation and
import calls so the workflow fails fast on non-terminating errors: update the
Install-Module invocation (Install-Module -Name 'PSScriptAnalyzer'
-RequiredVersion $requiredVersion ...) and the Import-Module invocation
(Import-Module -Name 'PSScriptAnalyzer' -RequiredVersion $requiredVersion -Force
...) to include -ErrorAction Stop, ensuring failures prevent subsequent
Invoke-ScriptAnalyzer from running with an incorrect module state/version.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
Add -ErrorAction 'Stop' to Install-Module and Import-Module in the lint job. In PowerShell 7 these emit non-terminating errors by default, so a failed install or import would not stop the step and Invoke-ScriptAnalyzer could run with a missing or wrong module version - the exact condition this job pins against. Addresses CodeRabbit review feedback on #62. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Summary
PSScriptAnalyzer Lintjob installed PSScriptAnalyzer unpinned and calledInvoke-ScriptAnalyzerwith no explicitImport-Module, so it ignored the1.24.0pin inbuild.depend.psd1(only the build/test jobs honor it, via PSDepend).mainafter style: re-sync test scaffolding to canonical template (post-#36) #55, while the identical PR tree had passed minutes earlier — confirming it was environmental, not a lint violation.build.depend.psd1, install that exact version (verified present even on a cache hit), andImport-Module -RequiredVersionit explicitly beforeInvoke-ScriptAnalyzerso exactly one assembly version loads. The cache key already hashesbuild.depend.psd1, so the installed version and cache stay coupled to a single source of truth.Test Plan
pwshblocks parse cleanlypwsh 7.5 / ubuntu-24.04container under the failure condition: with1.25.0pre-polluting the module path, the step still installs and loads exactly1.24.0and analyzes cleanly (0 errors)PSScriptAnalyzer Lintjob passes on this PRBreaking Changes
None. Behavior change is confined to the lint job's module install/import.
Notes
A separate follow-up (discussed but intentionally not included here) may unify the lint ruleset with the in-build analysis and revisit the now-likely-obsolete Linux/macOS PSScriptAnalyzer workaround in
build.psake.ps1.Summary by CodeRabbit