Skip to content
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

[ci] check PowerShell scripts with PSScriptAnalyzer (part 1) #6704

Merged
merged 3 commits into from
Oct 29, 2024

Conversation

StrikerRUS
Copy link
Collaborator

Linking full original PR: #6700.

This PR fixes all warnings about our own functions (PSUseApprovedVerbs, PSUseShouldProcessForStateChangingFunctions, PSUseSingularNouns).
Also this PR makes params in our own functions mandatory where needed.

List of available rules: https://github.com/PowerShell/PSScriptAnalyzer/blob/main/docs/Rules/README.md.

List of Approved Verbs for PowerShell Commands: https://learn.microsoft.com/en-us/powershell/scripting/developer/cmdlet/approved-verbs-for-windows-powershell-commands?view=powershell-7.4.

Copy link
Collaborator

@jameslamb jameslamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! The script changes look great to me... I agree with the choice of rules and and verbs. Thanks for the links in the description... I was not familiar with this concept of "approved verbs" in powershell before.

I just left one small suggestion on test.sh. Marking this "Approve", so you can merge without needing a new review from me if you agree with that suggestion.

.ci/test.sh Outdated
@@ -110,6 +110,9 @@ if [[ $TASK == "lint" ]]; then
'r-lintr>=3.1.2'
# shellcheck disable=SC1091
source activate "${CONDA_ENV}"
pwsh -command "Install-Module -Name PSScriptAnalyzer -Scope CurrentUser -SkipPublisherCheck"
echo "Linting PowerShell code"
pwsh -file "./.ci/lint-powershell.ps1" || exit 0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this doesn't require anything installed with conda (we're relying on the pwsh that comes pre-installed on the runner), I think we should move this up to before conda create. Two reasons:

  1. prevents the case where we wait for conda install to complete (which can sometimes take a few minutes) and then find out that the job is going to fail because of issues found by PSScriptAnalyzer.
  2. prevents where source activate "${CONDA ENV}" modifies the environment in a way that causes issues for pwsh (e.g. changes PATH / LD_LIBRARY_PATH and causes an incompatible mix of libraries to be loaded)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Totally makes sense. Will push changes right now.

@StrikerRUS StrikerRUS merged commit dc0ed53 into master Oct 29, 2024
48 checks passed
@StrikerRUS StrikerRUS deleted the ci/psanalizer-1 branch October 29, 2024 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants