|
1 | | -name: Code analysis (source) |
2 | | - |
3 | | -on: |
4 | | - push: |
5 | | - branches: [ main ] |
6 | | - pull_request: |
7 | | - branches: [ main ] |
8 | | - workflow_dispatch: |
9 | | - |
10 | | -# cSpell: ignore codeql SARIF |
11 | | -jobs: |
12 | | - pssa: |
13 | | - name: PSScriptAnalyzer |
14 | | - runs-on: windows-latest |
15 | | - permissions: |
16 | | - contents: read # for actions/checkout to fetch code |
17 | | - security-events: write # for github/codeql-action/upload-sarif to upload SARIF results |
18 | | - #actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status |
19 | | - steps: |
20 | | - - name: Checkout code |
21 | | - uses: actions/checkout@v5 |
22 | | - with: |
23 | | - fetch-depth: 0 |
24 | | - - name: Install GitVersion |
25 | | - shell: powershell |
26 | | - run: | |
27 | | - dotnet tool install --global GitVersion.Tool --version 5.* |
28 | | - dotnet-gitversion |
29 | | - - name: Run GitVersion |
30 | | - shell: powershell |
31 | | - run: | |
32 | | - dotnet-gitversion | ConvertFrom-Json |
33 | | - - name: Resolve dependencies |
34 | | - shell: powershell |
35 | | - run: | |
36 | | - Write-Information -MessageData 'Resolving dependencies.' -InformationAction 'Continue' |
37 | | - .\build.ps1 -ResolveDependency -Tasks 'noop' |
38 | | - - name: Build Module |
39 | | - shell: powershell |
40 | | - run: | |
41 | | - Write-Information -MessageData 'Module is being built.' -InformationAction 'Continue' |
42 | | - .\build.ps1 -Tasks 'build' |
43 | | - - name: Run PSScriptAnalyzer |
44 | | - shell: powershell |
45 | | - run: | |
46 | | - Write-Information -MessageData 'Prepare the test pipeline.' -InformationAction 'Continue' |
47 | | - .\build.ps1 -Tasks 'noop' |
48 | | -
|
49 | | - Write-Information -MessageData 'Load SMO stubs into session.' -InformationAction 'Continue' |
50 | | - Add-Type -Path './tests/Unit/Stubs/SMO.cs' |
51 | | -
|
52 | | - Write-Information -MessageData 'Import module ConvertToSARIF into the session.' -InformationAction 'Continue' |
53 | | - Import-Module -Name 'ConvertToSARIF' -Force |
54 | | -
|
55 | | - Write-Information -MessageData 'Import module PSScriptAnalyzer into the session.' -InformationAction 'Continue' |
56 | | - Import-Module -Name 'PSScriptAnalyzer' -Force |
57 | | -
|
58 | | - $filesToScan = Get-ChildItem -Path './source/' -Recurse -Include @('*.psm1', '*.ps1') -File |
59 | | - Write-Information -MessageData ("Will scan the files:`n`r`t{0}." -f ($filesToScan.FullName -join "`n`r`t")) -InformationAction 'Continue' |
60 | | -
|
61 | | - Write-Information -MessageData 'Running PSScriptAnalyzer.' -InformationAction 'Continue' |
62 | | - $pssaError = $filesToScan | |
63 | | - Invoke-ScriptAnalyzer -Settings './.vscode/analyzersettings.psd1' |
64 | | -
|
65 | | - $parseErrorTypes = @( |
66 | | - 'TypeNotFound' |
67 | | - 'RequiresModuleInvalid' |
68 | | - ) |
69 | | - Write-Information -MessageData ('Filter out reported parse errors that is unable to be resolved in source files: {0}' -f ($parseErrorTypes -join ', ')) -InformationAction 'Continue' |
70 | | - $pssaError = $pssaError | |
71 | | - Where-Object -FilterScript { |
72 | | - $_.RuleName -notin $parseErrorTypes |
73 | | - } |
74 | | -
|
75 | | - Write-Information -MessageData 'Converting PSScriptAnalyzer result to SARIF.' -InformationAction 'Continue' |
76 | | - $pssaError | |
77 | | - ConvertTo-SARIF -FilePath 'results.sarif' |
78 | | -
|
79 | | - Write-Information -MessageData 'Analyzing done.' -InformationAction 'Continue' |
80 | | - - name: Upload SARIF results |
81 | | - uses: github/codeql-action/upload-sarif@v3 |
82 | | - with: |
83 | | - sarif_file: results.sarif |
| 1 | +name: Code analysis (source) |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + pull_request: |
| 7 | + branches: [ main ] |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +# cSpell: ignore codeql SARIF |
| 11 | +jobs: |
| 12 | + pssa: |
| 13 | + name: PSScriptAnalyzer |
| 14 | + runs-on: windows-latest |
| 15 | + permissions: |
| 16 | + contents: read # for actions/checkout to fetch code |
| 17 | + security-events: write # for github/codeql-action/upload-sarif to upload SARIF results |
| 18 | + #actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status |
| 19 | + steps: |
| 20 | + - name: Checkout code |
| 21 | + uses: actions/checkout@v5 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + - name: Install GitVersion |
| 25 | + shell: powershell |
| 26 | + run: | |
| 27 | + dotnet tool install --global GitVersion.Tool --version 5.* |
| 28 | + dotnet-gitversion |
| 29 | + - name: Run GitVersion |
| 30 | + shell: powershell |
| 31 | + run: | |
| 32 | + dotnet-gitversion | ConvertFrom-Json |
| 33 | + - name: Resolve dependencies |
| 34 | + shell: powershell |
| 35 | + run: | |
| 36 | + Write-Information -MessageData 'Resolving dependencies.' -InformationAction 'Continue' |
| 37 | + .\build.ps1 -ResolveDependency -Tasks 'noop' |
| 38 | + - name: Build Module |
| 39 | + shell: powershell |
| 40 | + run: | |
| 41 | + Write-Information -MessageData 'Module is being built.' -InformationAction 'Continue' |
| 42 | + .\build.ps1 -Tasks 'build' |
| 43 | + - name: Run PSScriptAnalyzer |
| 44 | + shell: powershell |
| 45 | + run: | |
| 46 | + Write-Information -MessageData 'Prepare the test pipeline.' -InformationAction 'Continue' |
| 47 | + .\build.ps1 -Tasks 'noop' |
| 48 | +
|
| 49 | + Write-Information -MessageData 'Load SMO stubs into session.' -InformationAction 'Continue' |
| 50 | + Add-Type -Path './tests/Unit/Stubs/SMO.cs' |
| 51 | +
|
| 52 | + Write-Information -MessageData 'Import module ConvertToSARIF into the session.' -InformationAction 'Continue' |
| 53 | + Import-Module -Name 'ConvertToSARIF' -Force |
| 54 | +
|
| 55 | + Write-Information -MessageData 'Import module PSScriptAnalyzer into the session.' -InformationAction 'Continue' |
| 56 | + Import-Module -Name 'PSScriptAnalyzer' -Force |
| 57 | +
|
| 58 | + $filesToScan = Get-ChildItem -Path './source/' -Recurse -Include @('*.psm1', '*.ps1') -File |
| 59 | + Write-Information -MessageData ("Will scan the files:`n`r`t{0}." -f ($filesToScan.FullName -join "`n`r`t")) -InformationAction 'Continue' |
| 60 | +
|
| 61 | + Write-Information -MessageData 'Running PSScriptAnalyzer.' -InformationAction 'Continue' |
| 62 | + $pssaError = $filesToScan | |
| 63 | + Invoke-ScriptAnalyzer -Settings './.vscode/analyzersettings.psd1' |
| 64 | +
|
| 65 | + $parseErrorTypes = @( |
| 66 | + 'TypeNotFound' |
| 67 | + 'RequiresModuleInvalid' |
| 68 | + ) |
| 69 | + Write-Information -MessageData ('Filter out reported parse errors that is unable to be resolved in source files: {0}' -f ($parseErrorTypes -join ', ')) -InformationAction 'Continue' |
| 70 | + $pssaError = $pssaError | |
| 71 | + Where-Object -FilterScript { |
| 72 | + $_.RuleName -notin $parseErrorTypes |
| 73 | + } |
| 74 | +
|
| 75 | + Write-Information -MessageData 'Converting PSScriptAnalyzer result to SARIF.' -InformationAction 'Continue' |
| 76 | + $pssaError | |
| 77 | + ConvertTo-SARIF -FilePath 'results.sarif' |
| 78 | +
|
| 79 | + Write-Information -MessageData 'Analyzing done.' -InformationAction 'Continue' |
| 80 | + - name: Upload SARIF results |
| 81 | + uses: github/codeql-action/upload-sarif@v3 |
| 82 | + with: |
| 83 | + sarif_file: results.sarif |
0 commit comments