Skip to content

Commit

Permalink
Merge branch 'hotfix/0.26.4'
Browse files Browse the repository at this point in the history
* hotfix/0.26.4:
  (#130) Install PowerShell Module to Current User
  (#142) Skip PSSA analysis when no files to analyze
  • Loading branch information
gep13 committed Apr 11, 2024
2 parents d8171a1 + 8dd903d commit 22a78ba
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 31 deletions.
17 changes: 15 additions & 2 deletions Chocolatey.Cake.Recipe/Content/install-module.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,18 @@ if (Get-Module -ListAvailable -FullyQualifiedName $FullyQualifiedName) {
}
else {
Write-Host "Install Module $ModuleName with version $RequiredVersion..."
Install-Module -Name $ModuleName -RequiredVersion $RequiredVersion -Force
}
# Bootstrap PowerShell Get
if (-not (Get-PackageProvider NuGet -ErrorAction Ignore)) {
Write-Host "Installing NuGet package provider"
Install-PackageProvider NuGet -MinimumVersion 2.8.5.201 -ForceBootstrap -Force -Scope CurrentUser
}

if (-not (Get-InstalledModule PowerShellGet -MinimumVersion 2.0 -MaximumVersion 2.99 -ErrorAction Ignore)) {
Install-Module PowerShellGet -MaximumVersion 2.99 -Force -AllowClobber -Scope CurrentUser
Remove-Module PowerShellGet -Force
Import-Module PowerShellGet -MinimumVersion 2.0 -Force
Import-PackageProvider -Name PowerShellGet -MinimumVersion 2.0 -Force
}

Install-Module -Name $ModuleName -RequiredVersion $RequiredVersion -Force -Scope CurrentUser
}
68 changes: 39 additions & 29 deletions Chocolatey.Cake.Recipe/Content/run-psscriptanalyzer.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -73,48 +73,58 @@ $modules = Get-ChildItem -Path $AnalyzePath -Filter "*.psm1" -Recurse | ForEach-
}
}

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

$records = Start-Job -ArgumentList $modules, $SettingsPath {
Param(
$modules,
$SettingsPath
)
$modules | Invoke-ScriptAnalyzer -Settings $SettingsPath | Select-Object RuleName, ScriptPath, Line, Message
} | Wait-Job | Receive-Job
$records = Start-Job -ArgumentList $modules, $SettingsPath {
Param(
$modules,
$SettingsPath
)
$modules | Invoke-ScriptAnalyzer -Settings $SettingsPath | Select-Object RuleName, ScriptPath, Line, Message
} | Wait-Job | Receive-Job

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

Write-Output $OutputPath
Write-Output $OutputPath

Write-Output "Writing violations to output file..."
$records | ConvertTo-SARIF -FilePath "$OutputPath\modules.sarif"
Write-Output "Writing violations to output file..."
$records | ConvertTo-SARIF -FilePath "$OutputPath\modules.sarif"
}
else {
Write-Output "No rule violations found in Module Files."
}
}
else {
Write-Output "No rule violations found in Module Files."
Write-Output "No Module Files to analyze"
}

Write-Output "Analyzing script files..."
if ($null -ne $scripts) {
Write-Output "Analyzing script files..."

$records = Start-Job -ArgumentList $Scripts, $SettingsPath {
Param(
$Scripts,
$SettingsPath
)
$Scripts | Invoke-ScriptAnalyzer -Settings $SettingsPath | Select-Object RuleName, ScriptPath, Line, Message
} | Wait-Job | Receive-Job
$records = Start-Job -ArgumentList $Scripts, $SettingsPath {
Param(
$Scripts,
$SettingsPath
)
$Scripts | Invoke-ScriptAnalyzer -Settings $SettingsPath | Select-Object RuleName, ScriptPath, Line, Message
} | Wait-Job | Receive-Job

if (-not ($null -EQ $records)) {
Write-Output "Violations found in Script Files..."
$records | Format-List | Out-String
if (-not ($null -EQ $records)) {
Write-Output "Violations found in Script Files..."
$records | Format-List | Out-String

Write-Output "Writing violations to output file..."
$records | ConvertTo-SARIF -FilePath "$OutputPath\scripts.sarif"
Write-Output "Writing violations to output file..."
$records | ConvertTo-SARIF -FilePath "$OutputPath\scripts.sarif"
}
else {
Write-Output "No rule violations found in Script Files."
}
}
else {
Write-Output "No rule violations found in Script Files."
Write-Output "No Script Files to analyze"
}

Write-Output "Analyzing complete."

0 comments on commit 22a78ba

Please sign in to comment.