Skip to content

Commit 2c5e71a

Browse files
authored
Add workflow for running ScriptAnalyzer (#236464)
1 parent dcf5b7e commit 2c5e71a

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

.github/workflows/scriptAnalyzer.yaml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: PSScriptAnalyzer
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
paths:
8+
- "**/*.ps1"
9+
push:
10+
paths:
11+
- "**/*.ps1"
12+
13+
permissions:
14+
contents: read # Needed to check out the code
15+
pull-requests: read # Needed to read pull request details
16+
17+
jobs:
18+
analyze:
19+
runs-on: windows-latest
20+
steps:
21+
- name: Checkout code
22+
uses: actions/checkout@v3
23+
- name: Install PSScriptAnalyzer
24+
run: |
25+
Install-Module -Name PSScriptAnalyzer -Force -SkipPublisherCheck -Scope CurrentUser
26+
- name: Run PSScriptAnalyzer
27+
run: |
28+
# Run PSScriptAnalyzer on all PowerShell scripts
29+
$results = Get-ChildItem -Recurse -Filter *.ps1 | Invoke-ScriptAnalyzer
30+
if ($results) {
31+
Write-Output $results | Format-List -GroupBy ScriptName
32+
}
33+
34+
# If errors are found, exit with a non-zero exit code to fail the job
35+
if ($results.where({$_.Severity-eq 'Error'})) {
36+
Write-Host "Found script issues (errors)."
37+
exit 1 # Exit with a non-zero status to fail the job
38+
} else {
39+
Write-Host "No blocking detections."
40+
}

Tools/YamlCreate.ps1

-2
Original file line numberDiff line numberDiff line change
@@ -1635,8 +1635,6 @@ Function Read-InstallerMetadataValue {
16351635
# If a key does not exist, it sets the value to a special character to be removed / commented later
16361636
# Returns the result as a new object
16371637
Function Restore-YamlKeyOrder {
1638-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'InputObject', Justification = 'The variable is used inside a conditional but ScriptAnalyser does not recognize the scope')]
1639-
[Diagnostics.CodeAnalysis.SuppressMessageAttribute('PSReviewUnusedParameter', 'NoComments', Justification = 'The variable is used inside a conditional but ScriptAnalyser does not recognize the scope')]
16401638
Param
16411639
(
16421640
[Parameter(Mandatory = $true, Position = 0)]

0 commit comments

Comments
 (0)