-
Notifications
You must be signed in to change notification settings - Fork 393
Add -EnableExit switch to Invoke-ScriptAnalyzer for exit and return exit code for CI purposes #842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still coming up to speed on the code base, but shouldn't there be an additional test for this new behavior?
@JamesWTruher Thanks for reminding (and motivating) me to write an automated test. At first I thought this might be difficult due to the cmdlet exiting the shell but at the end it was quite easy due to PowerShell being so awesome. |
It "Returns exit code equivalent to number of warnings" { | ||
$process = Start-Process powershell -ArgumentList '-WindowStyle Hidden -Command Import-Module PSScriptAnalyzer; Invoke-ScriptAnalyzer -ScriptDefinition gci -EnableExit' -PassThru -Wait | ||
$process.ExitCode | Should Be 1 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What you have is fine, but would this also work?
powershell -command 'import-module psscriptanalyzer; invoke-scriptanalyzer -enableexit -scriptdef gci'
$LASTEXITCODE | Should be 1
Eventually, I would like to see these be portable on other platforms, and the -WindowStyle
parameter isn't portable. Eventually, we also need to calculate the name of powershell
(since it can be powershell or pwsh, but that can be ignored for now)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that is possible. I have changed it to that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with the recent change with regard to -EnableExit
and -Fix
parameters the readme has a merge conflict. Would you address this?
…nalyzer into enableExit Merge conflict on syntax line, easy to resolve. # Conflicts: # README.md
OK. I resolved it. What do you think about the problem that the repo shows the ReadMe of the |
Do you happen to know why that was chosen? I need to talk to somebody in the office about it. It doesn't seem necessary or even preferred. I'd like to bring it into sync with how we do PSCore, using master as the main branch and labels for releases. |
@JamesWTruher I don't know why it was chosen like that (remember that PSSA originally came from the community and not MS) but I guess the person was inspired by the |
To close #840
Behaviour is similar to the equivalent switch in
Invoke-Pester
, i.e. the shell exits with an exit code equal to the number of error records.