Closed TheCakeIsNaOH closed 6 months ago
NOTE: As a result of running the build using the changes in this PR, two new PowerShell Modules will be installed, PSScriptAnalyzer, and ConvertToSARIF.
@TheCakeIsNaOH would be great to get your thoughts on this PR as well. I have made some changes on top of the work that you originally did here.
Mainly around the installation of the PS Modules, and also switching to use Start-Job
as I found that any call to Invoke-ScriptAnalyzer
caused the terminal to hang when invoked through Cake, and you had to CTRL+C out of it.
@TheCakeIsNaOH thanks again for the start on this work! Really appreciate it!
Description Of Changes
This adds a task to run PSScriptAnalyzer. It utilizes the Cake.Powershell module to run a script that will get ps1/psm1 files that are not excluded and run them through the specified settings file.
Either a default formatting only run can be done, or custom run(s) can be specified. A custom base analysis path, setting file and set of folder exclusions can be specified for each run. For example, a custom run can be created to check that the Chocolatey powershell helpers use only the PSv2 cmdlets.
The default run is for formatting, it checks files against the build in formatting related rules. This run can be expanded in the future, once enough projects are up to a baseline of good scripting practices.
Motivation and Context
See #32
Testing
build.bat
. The build should complete successfully, and a new taskRun-PSScriptAnalyzer
should be completed, which adds two new files into thecode_drop\TestResults\PSScriptAnalyzer
folderbuild.bat --shouldRunAnalyze=false
. The build should succeed, but all the analyze steps should be skipped, and no files added into thecode_drop\TestResults\PSScriptAnalyzer
folderbuild.bat --shouldRunPSScriptAnalyzer=false
. The build should succeed, but all the analyze steps should be skipped, and no files added into thecode_drop\TestResults\PSScriptAnalyzer
folder, but other test results, for example, InspectCode, should be generated.Change Types Made
Related Issue
Fixes #32
Change Checklist