From d808de202063016ec2a85e8b41a9eed7d7393842 Mon Sep 17 00:00:00 2001 From: Johan Ljunggren Date: Sun, 5 Mar 2023 10:12:49 +0100 Subject: [PATCH] Fix workflow --- .github/workflows/code-analysis.yml | 27 ++++++++++++++++----------- .vscode/analyzersettings.psd1 | 5 ++++- tests/QA/ScriptAnalyzer.Tests.ps1 | 2 +- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/.github/workflows/code-analysis.yml b/.github/workflows/code-analysis.yml index b34c0d972..cc44006f1 100644 --- a/.github/workflows/code-analysis.yml +++ b/.github/workflows/code-analysis.yml @@ -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' @@ -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 diff --git a/.vscode/analyzersettings.psd1 b/.vscode/analyzersettings.psd1 index 0b56fe60d..30932a84d 100644 --- a/.vscode/analyzersettings.psd1 +++ b/.vscode/analyzersettings.psd1 @@ -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. diff --git a/tests/QA/ScriptAnalyzer.Tests.ps1 b/tests/QA/ScriptAnalyzer.Tests.ps1 index 6fbe746e6..a982ee251 100644 --- a/tests/QA/ScriptAnalyzer.Tests.ps1 +++ b/tests/QA/ScriptAnalyzer.Tests.ps1 @@ -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