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 e31f2dd commit d808de2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
27 changes: 16 additions & 11 deletions .github/workflows/code-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ jobs:
- name: Run PSScriptAnalyzer
shell: powershell
run: |
# Only get the analyzer rule modules.
# New-Item -Path './output/RequiredModules' -ItemType Directory -Force | Out-Null
# Save-Module -Name 'DscResource.AnalyzerRules' -Path './output/RequiredModules' -Force
# Save-Module -Name 'Indented.ScriptAnalyzerRules' -Path './output/RequiredModules' -Force
Write-Information -MessageData 'Prepare the test pipeline.' -InformationAction 'Continue'
.\build.ps1 -Tasks 'noop'
Expand All @@ -48,12 +43,22 @@ jobs:
Write-Information -MessageData ("Will scan the files:`n`r`t{0}." -f ($filesToScan.FullName -join "`n`r`t")) -InformationAction 'Continue'
Write-Information -MessageData 'Running PSScriptAnalyzer.' -InformationAction 'Continue'
$filesToScan |
Invoke-ScriptAnalyzer -Settings './.vscode/analyzersettings.psd1' -ExcludeRule @(
'TypeNotFound' # Because classes in the project cannot be found unless built.
'RequiresModuleInvalid' # Because 'using module' in prefix.ps1 cannot be resolved as source file.
) |
ConvertTo-SARIF -FilePath 'results.sarif'
$pssaError = $filesToScan |
Invoke-ScriptAnalyzer -Settings './.vscode/analyzersettings.psd1'
Write-Information -MessageData 'Converting PSScriptAnalyzer result to SARIF.' -InformationAction 'Continue'
<#
Filter out rules.
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 |
Where-Object -FilterScript { $_.RuleName -notin @('TypeNotFound', 'RequiresModuleInvalid') } |
ConvertTo-SARIF -FilePath 'results.sarif'
Write-Information -MessageData 'Analyzing done.' -InformationAction 'Continue'
- name: Upload SARIF results
Expand Down
5 changes: 4 additions & 1 deletion .vscode/analyzersettings.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@
'UseSyntacticallyCorrectExamples'
)

# TODO: This is not excluded correctly, see test QA/ScriptAnalyzer.Tests.ps1 for more information.
<#
TODO: This is not excluded correctly, see test QA/ScriptAnalyzer.Tests.ps1
or the GitHub Action workflow Code Analysis for more information.
#>
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.
Expand Down
2 changes: 1 addition & 1 deletion tests/QA/ScriptAnalyzer.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ Describe 'Script Analyzer Rules' {
$pssaError = Invoke-ScriptAnalyzer -Path $ScriptPath -Settings $scriptAnalyzerSettingsPath

<#
Filter out rule TypeNotFound.
Filter out rules.
TODO: The rules (e.g. "TypeNotFound") are not excluded correctly even if it
is excluded in the file 'analyzersettings.psd1'. This is a workaround
Expand Down

0 comments on commit d808de2

Please sign in to comment.