Skip to content

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

Merged
StrikerRUS merged 3 commits intomasterfrom
ci/psanalizer-1
Oct 29, 2024
Merged

[ci] check PowerShell scripts with PSScriptAnalyzer (part 1)#6704
StrikerRUS merged 3 commits intomasterfrom
ci/psanalizer-1

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
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.

@github-actions
Copy link
Contributor

This pull request has been automatically locked since there has not been any recent activity since it was closed.
To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 30, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants