microsoft/hve-core

Public

mirrored from https://github.com/microsoft/hve-coreAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
c3af708c39a4db1cd35d2ffd0d15db2bbe6dd0da

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

.github/workflows/ps-script-analyzer.yml

72lines · modecode

1name: PSScriptAnalyzer
2
3on:
4 workflow_call:
5 inputs:
6 soft-fail:
7 description: 'Whether to continue on PSScriptAnalyzer violations'
8 required: false
9 type: boolean
10 default: false
11 changed-files-only:
12 description: 'Only analyze changed PowerShell files'
13 required: false
14 type: boolean
15 default: true
16
17permissions:
18 contents: read
19
20jobs:
21 psscriptanalyzer:
22 name: PowerShell Lint
23 runs-on: ubuntu-latest
24 permissions:
25 contents: read
26 steps:
27 - name: Harden Runner
28 uses: step-security/harden-runner@95d9a5deda9de15063e7595e9719c11c38c90ae2 # v2.10.2
29 with:
30 egress-policy: audit
31
32 - name: Checkout code
33 uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v4.2.2
34 with:
35 persist-credentials: false
36 fetch-depth: 0
37
38 - name: Run PSScriptAnalyzer
39 id: analyze
40 shell: pwsh
41 run: |
42 New-Item -ItemType Directory -Force -Path logs | Out-Null
43 $params = @{}
44 if ('${{ inputs.changed-files-only }}' -eq 'true') {
45 $params['ChangedFilesOnly'] = $true
46 }
47
48 & scripts/linting/Invoke-PSScriptAnalyzer.ps1 @params
49 if ($LASTEXITCODE -ne 0) {
50 "PSSCRIPTANALYZER_FAILED=true" | Out-File -FilePath $env:GITHUB_ENV -Append
51 }
52 continue-on-error: ${{ inputs.soft-fail }}
53
54 - name: Upload results
55 if: always()
56 uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v4.4.3
57 with:
58 name: psscriptanalyzer-results
59 path: |
60 logs/psscriptanalyzer-results.json
61 logs/psscriptanalyzer-summary.json
62 retention-days: 30
63 if-no-files-found: ignore
64
65 - name: Check results
66 if: "!inputs.soft-fail"
67 shell: pwsh
68 run: |
69 if ($env:PSSCRIPTANALYZER_FAILED -eq 'true') {
70 Write-Error "PSScriptAnalyzer found violations"
71 exit 1
72 }
73