Skip to content

Commit 22a78ba

Browse files
committed
Merge branch 'hotfix/0.26.4'
* hotfix/0.26.4: (#130) Install PowerShell Module to Current User (#142) Skip PSSA analysis when no files to analyze
2 parents d8171a1 + 8dd903d commit 22a78ba

File tree

2 files changed

+54
-31
lines changed

2 files changed

+54
-31
lines changed

Chocolatey.Cake.Recipe/Content/install-module.ps1

+15-2
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,18 @@ if (Get-Module -ListAvailable -FullyQualifiedName $FullyQualifiedName) {
3030
}
3131
else {
3232
Write-Host "Install Module $ModuleName with version $RequiredVersion..."
33-
Install-Module -Name $ModuleName -RequiredVersion $RequiredVersion -Force
34-
}
33+
# Bootstrap PowerShell Get
34+
if (-not (Get-PackageProvider NuGet -ErrorAction Ignore)) {
35+
Write-Host "Installing NuGet package provider"
36+
Install-PackageProvider NuGet -MinimumVersion 2.8.5.201 -ForceBootstrap -Force -Scope CurrentUser
37+
}
38+
39+
if (-not (Get-InstalledModule PowerShellGet -MinimumVersion 2.0 -MaximumVersion 2.99 -ErrorAction Ignore)) {
40+
Install-Module PowerShellGet -MaximumVersion 2.99 -Force -AllowClobber -Scope CurrentUser
41+
Remove-Module PowerShellGet -Force
42+
Import-Module PowerShellGet -MinimumVersion 2.0 -Force
43+
Import-PackageProvider -Name PowerShellGet -MinimumVersion 2.0 -Force
44+
}
45+
46+
Install-Module -Name $ModuleName -RequiredVersion $RequiredVersion -Force -Scope CurrentUser
47+
}

Chocolatey.Cake.Recipe/Content/run-psscriptanalyzer.ps1

+39-29
Original file line numberDiff line numberDiff line change
@@ -73,48 +73,58 @@ $modules = Get-ChildItem -Path $AnalyzePath -Filter "*.psm1" -Recurse | ForEach-
7373
}
7474
}
7575

76-
Write-Output "Analyzing module files..."
76+
if ($null -ne $modules) {
77+
Write-Output "Analyzing module files..."
7778

78-
$records = Start-Job -ArgumentList $modules, $SettingsPath {
79-
Param(
80-
$modules,
81-
$SettingsPath
82-
)
83-
$modules | Invoke-ScriptAnalyzer -Settings $SettingsPath | Select-Object RuleName, ScriptPath, Line, Message
84-
} | Wait-Job | Receive-Job
79+
$records = Start-Job -ArgumentList $modules, $SettingsPath {
80+
Param(
81+
$modules,
82+
$SettingsPath
83+
)
84+
$modules | Invoke-ScriptAnalyzer -Settings $SettingsPath | Select-Object RuleName, ScriptPath, Line, Message
85+
} | Wait-Job | Receive-Job
8586

86-
if (-not ($null -EQ $records)) {
87-
Write-Output "Violations found in Module Files..."
88-
$records | Format-List | Out-String
87+
if (-not ($null -EQ $records)) {
88+
Write-Output "Violations found in Module Files..."
89+
$records | Format-List | Out-String
8990

90-
Write-Output $OutputPath
91+
Write-Output $OutputPath
9192

92-
Write-Output "Writing violations to output file..."
93-
$records | ConvertTo-SARIF -FilePath "$OutputPath\modules.sarif"
93+
Write-Output "Writing violations to output file..."
94+
$records | ConvertTo-SARIF -FilePath "$OutputPath\modules.sarif"
95+
}
96+
else {
97+
Write-Output "No rule violations found in Module Files."
98+
}
9499
}
95100
else {
96-
Write-Output "No rule violations found in Module Files."
101+
Write-Output "No Module Files to analyze"
97102
}
98103

99-
Write-Output "Analyzing script files..."
104+
if ($null -ne $scripts) {
105+
Write-Output "Analyzing script files..."
100106

101-
$records = Start-Job -ArgumentList $Scripts, $SettingsPath {
102-
Param(
103-
$Scripts,
104-
$SettingsPath
105-
)
106-
$Scripts | Invoke-ScriptAnalyzer -Settings $SettingsPath | Select-Object RuleName, ScriptPath, Line, Message
107-
} | Wait-Job | Receive-Job
107+
$records = Start-Job -ArgumentList $Scripts, $SettingsPath {
108+
Param(
109+
$Scripts,
110+
$SettingsPath
111+
)
112+
$Scripts | Invoke-ScriptAnalyzer -Settings $SettingsPath | Select-Object RuleName, ScriptPath, Line, Message
113+
} | Wait-Job | Receive-Job
108114

109-
if (-not ($null -EQ $records)) {
110-
Write-Output "Violations found in Script Files..."
111-
$records | Format-List | Out-String
115+
if (-not ($null -EQ $records)) {
116+
Write-Output "Violations found in Script Files..."
117+
$records | Format-List | Out-String
112118

113-
Write-Output "Writing violations to output file..."
114-
$records | ConvertTo-SARIF -FilePath "$OutputPath\scripts.sarif"
119+
Write-Output "Writing violations to output file..."
120+
$records | ConvertTo-SARIF -FilePath "$OutputPath\scripts.sarif"
121+
}
122+
else {
123+
Write-Output "No rule violations found in Script Files."
124+
}
115125
}
116126
else {
117-
Write-Output "No rule violations found in Script Files."
127+
Write-Output "No Script Files to analyze"
118128
}
119129

120130
Write-Output "Analyzing complete."

0 commit comments

Comments
 (0)