Skip to content

Commit

Permalink
Fix workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
johlju committed Mar 5, 2023
1 parent d808de2 commit 77a4fdd
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Build Module
shell: powershell
run: |
# Module is built so that examples can be scanned.
Write-Information -MessageData 'Module is being built so that examples can be scanned.' -InformationAction 'Continue'
.\build.ps1 -ResolveDependency -Tasks 'build'
- name: Run PSScriptAnalyzer
shell: powershell
Expand All @@ -46,19 +46,19 @@ jobs:
$pssaError = $filesToScan |
Invoke-ScriptAnalyzer -Settings './.vscode/analyzersettings.psd1'
Write-Information -MessageData 'Converting PSScriptAnalyzer result to SARIF.' -InformationAction 'Continue'
<#
Filter out rules.
$parseErrorTypes = @(
'TypeNotFound'
'RequiresModuleInvalid'
)
Write-Information -MessageData ('Filter out reported parse errors that is unable to be resolved in source files: {0}' -f ($parseErrorTypes -join ', ')) -InformationAction 'Continue'
$pssaError = $pssaError |
Where-Object -FilterScript {
$_.RuleName -notin $parseErrorTypes
}
TODO: The rules (e.g. "TypeNotFound") are not excluded correctly even if it
is excluded in the file 'analyzersettings.psd1'. This is a workaround
until it is properly excluded for source files, and instead only is
run for the built module script module file (SqlServerDsc.psm1).
#>
Write-Information -MessageData 'Converting PSScriptAnalyzer result to SARIF.' -InformationAction 'Continue'
$pssaError |
Where-Object -FilterScript { $_.RuleName -notin @('TypeNotFound', 'RequiresModuleInvalid') } |
ConvertTo-SARIF -FilePath 'results.sarif'
ConvertTo-SARIF -FilePath 'results.sarif'
Write-Information -MessageData 'Analyzing done.' -InformationAction 'Continue'
- name: Upload SARIF results
Expand Down
13 changes: 7 additions & 6 deletions .vscode/analyzersettings.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,14 @@
)

<#
TODO: This is not excluded correctly, see test QA/ScriptAnalyzer.Tests.ps1
or the GitHub Action workflow Code Analysis for more information.
The following types are not rules but parse errors reported by PSScriptAnalyzer
so they cannot be ecluded. They need to be filtered out from the result of
Invoke-ScriptAnalyzer.
TypeNotFound - Because classes in the project cannot be found unless built.
RequiresModuleInvalid - Because 'using module' in prefix.ps1 cannot be resolved as source file.
#>
ExcludeRules = @(
'TypeNotFound' # Because classes in the project cannot be found unless built.
'RequiresModuleInvalid' # Because 'using module' in prefix.ps1 cannot be resolved as source file.
)
ExcludeRules = @()

Rules = @{
PSUseConsistentWhitespace = @{
Expand Down
21 changes: 12 additions & 9 deletions tests/QA/ScriptAnalyzer.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,20 @@ Describe 'Script Analyzer Rules' {
It 'Should pass all PS Script Analyzer rules for file ''<RelativePath>''' -ForEach $testCases {
$pssaError = Invoke-ScriptAnalyzer -Path $ScriptPath -Settings $scriptAnalyzerSettingsPath

<#
Filter out rules.
$parseErrorTypes = @(
'TypeNotFound'
'RequiresModuleInvalid'
)

TODO: The rules (e.g. "TypeNotFound") are not excluded correctly even if it
is excluded in the file 'analyzersettings.psd1'. This is a workaround
until it is properly excluded for source files, and instead only is
run for the built module script module file (SqlServerDsc.psm1).
#>
$pssaError = $pssaError | Where-Object -FilterScript { $_.RuleName -notin @('TypeNotFound', 'RequiresModuleInvalid') }
# Filter out reported parse errors that is unable to be resolved in source files
$pssaError = $pssaError |
Where-Object -FilterScript {
$_.RuleName -notin $parseErrorTypes
}

$report = $pssaError |
Format-Table -AutoSize | Out-String -Width 200

$report = $pssaError | Format-Table -AutoSize | Out-String -Width 200
$pssaError | Should -HaveCount 0 -Because "all script analyzer rules should pass.`r`n`r`n $report`r`n"
}
}
Expand Down

0 comments on commit 77a4fdd

Please sign in to comment.