Repository navigation
80 lines (71 loc) · 3.19 KB
/
Copy pathci.yml
File metadata and controls
80 lines (71 loc) · 3.19 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
name: CI
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
jobs:
analyze:
name: PSScriptAnalyzer
runs-on: windows-latest
timeout-minutes: 15
steps:
# Every action is pinned to a full commit SHA. The comment names the tag it was taken from.
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Install PSScriptAnalyzer
shell: pwsh
run: |
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
Install-Module -Name PSScriptAnalyzer -RequiredVersion 1.25.0 -Scope CurrentUser -Force
# Per file, because a whole-tree run printed an internal NullReference in the audit.
# Tests\ is skipped: Pester mock bodies cannot see $script: variables, so the tests use one $global: table on purpose.
- name: Run PSScriptAnalyzer
shell: pwsh
run: |
Import-Module PSScriptAnalyzer -RequiredVersion 1.25.0
$files = Get-ChildItem -Recurse -File -Include *.ps1, *.psm1, *.psd1 |
Where-Object { $_.FullName -notlike '*\Tests\*' -and $_.FullName -notlike '*\.git\*' }
$results = foreach ($file in $files) {
Invoke-ScriptAnalyzer -Path $file.FullName -Settings ./PSScriptAnalyzerSettings.psd1
}
Write-Host "Analyzed $($files.Count) file(s)."
if ($results) {
$results | Format-Table -AutoSize ScriptName, Line, RuleName, Severity, Message | Out-String -Width 250 | Write-Host
throw "PSScriptAnalyzer reported $(@($results).Count) finding(s)."
}
test:
name: Pester (${{ matrix.shell }})
runs-on: windows-latest
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
# pwsh is PowerShell 7. powershell is Windows PowerShell 5.1, which is what Intune runs.
shell: [pwsh, powershell]
defaults:
run:
shell: ${{ matrix.shell }}
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Install Pester
run: |
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
# -SkipPublisherCheck: Windows PowerShell 5.1 ships Pester 3.4 signed by Microsoft
Install-Module -Name Pester -RequiredVersion 5.9.1 -Scope CurrentUser -Force -SkipPublisherCheck
- name: Parse every script
run: |
$errors = foreach ($file in Get-ChildItem -Recurse -File -Include *.ps1, *.psm1, *.psd1 | Where-Object { $_.FullName -notlike '*\.git\*' }) {
$tokens = $null; $parseErrors = $null
[System.Management.Automation.Language.Parser]::ParseFile($file.FullName, [ref]$tokens, [ref]$parseErrors) | Out-Null
foreach ($e in $parseErrors) { "$($file.Name):$($e.Extent.StartLineNumber) $($e.Message)" }
}
if ($errors) { $errors | ForEach-Object { Write-Host $_ }; throw "Parse errors found." }
- name: Run Pester
run: |
Import-Module Pester -RequiredVersion 5.9.1
$config = New-PesterConfiguration
$config.Run.Path = './Tests'
$config.Run.Exit = $true
$config.Output.Verbosity = 'Normal'
Invoke-Pester -Configuration $config