forked from AllwaysHyPe/IntuneStack
-
Notifications
You must be signed in to change notification settings - Fork 0
97 lines (81 loc) · 3.45 KB
/
Copy pathpr-validation.yml
File metadata and controls
97 lines (81 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
name: PR Validation
on:
pull_request:
branches: [ main, development ]
paths:
- "**/*.ps1"
- "**/*.psm1"
- "**/*.psd1"
permissions:
contents: read
checks: write
pull-requests: read
jobs:
pr-validation:
name: Quality Gate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install modules
shell: pwsh
run: |
$ProgressPreference = 'SilentlyContinue'
Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser
Install-Module -Name Pester -Force -Scope CurrentUser -MinimumVersion 5.0 -AllowClobber
- name: Get changed PowerShell files
id: changed-files
uses: tj-actions/changed-files@v40
with:
files: |
**/*.ps1
**/*.psm1
**/*.psd1
- name: PSScriptAnalyzer
if: steps.changed-files.outputs.any_changed == 'true'
shell: pwsh
run: |
$changedFiles = @(${{ steps.changed-files.outputs.all_changed_files }})
$errorCount = 0
$warningCount = 0
foreach ($file in $changedFiles) {
if (-not (Test-Path $file)) { continue }
$results = Invoke-ScriptAnalyzer -Path $file -Settings "./config/PSScriptAnalyzerSettings.psd1"
if ($results) {
$errorCount += ($results | Where-Object Severity -eq 'Error').Count
$warningCount += ($results | Where-Object Severity -eq 'Warning').Count
foreach ($result in $results) {
$level = switch ($result.Severity) {
'Error' { 'error' }
'Warning' { 'warning' }
'Information' { 'notice' }
}
Write-Output "::$level file=$file,line=$($result.Line),col=$($result.Column)::$($result.RuleName): $($result.Message)"
}
}
}
Write-Output "Files changed: $($changedFiles.Count) | Errors: $errorCount | Warnings: $warningCount"
if ($errorCount -gt 0) {
Write-Output "PSScriptAnalyzer errors found. Fix before merging."
exit 1
}
- name: Pester
shell: pwsh
run: |
$config = New-PesterConfiguration
$config.Run.Path = "./tests"
$config.TestResult.Enabled = $true
$config.TestResult.OutputPath = "./test-results.xml"
$config.TestResult.OutputFormat = "NUnitXml"
$config.Output.Verbosity = "Detailed"
$results = Invoke-Pester -Configuration $config
if ($results.FailedCount -gt 0) { exit 1 }
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: pester-results
path: test-results.xml
retention-days: 7
if-no-files-found: ignore