-
Notifications
You must be signed in to change notification settings - Fork 6
71 lines (65 loc) · 2.39 KB
/
ci.yml
File metadata and controls
71 lines (65 loc) · 2.39 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
name: CI
on:
push:
branches: [master]
pull_request:
jobs:
lint-and-validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install PSScriptAnalyzer
shell: pwsh
run: |
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module -Name PSScriptAnalyzer -Force -Scope CurrentUser
- name: Lint PowerShell scripts
shell: pwsh
run: |
$files = Get-ChildItem -Path . -Recurse -Filter *.ps1
$results = $files | ForEach-Object {
Invoke-ScriptAnalyzer -Path $_.FullName -Settings ./PSScriptAnalyzerSettings.psd1
}
if ($results) {
$results | Format-Table -AutoSize | Out-String | Write-Host
$errors = @($results | Where-Object Severity -eq 'Error')
if ($errors.Count -gt 0) {
Write-Host "::error::PSScriptAnalyzer found $($errors.Count) error(s)"
exit 1
}
Write-Host "PSScriptAnalyzer: $($results.Count) non-error finding(s)"
} else {
Write-Host "PSScriptAnalyzer: no issues"
}
- name: Parse PowerShell syntax
shell: pwsh
run: |
$hadError = $false
Get-ChildItem -Path . -Recurse -Filter *.ps1 | ForEach-Object {
$parseErrors = $null
[System.Management.Automation.Language.Parser]::ParseFile(
$_.FullName, [ref]$null, [ref]$parseErrors
) | Out-Null
if ($parseErrors -and $parseErrors.Count -gt 0) {
Write-Host "::error file=$($_.FullName)::Parse errors:"
$parseErrors | ForEach-Object { Write-Host " $_" }
$hadError = $true
} else {
Write-Host "OK: $($_.FullName)"
}
}
if ($hadError) { exit 1 }
- name: Validate .wsb XML
shell: pwsh
run: |
$hadError = $false
Get-ChildItem -Path . -Recurse -Filter *.wsb | ForEach-Object {
try {
[xml](Get-Content $_.FullName -Raw) | Out-Null
Write-Host "OK: $($_.FullName)"
} catch {
Write-Host "::error file=$($_.FullName)::XML invalid: $_"
$hadError = $true
}
}
if ($hadError) { exit 1 }