Repository navigation
195 lines (179 loc) · 9.36 KB
/
Copy pathmodule.yml
File metadata and controls
195 lines (179 loc) · 9.36 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
name: Module
# Tests the kit as a module and packs it for the Gallery (kept with the run, not
# published): the whole harness on a push to a release/ or version/ branch, the
# module sections (-Section MODULE) on everything else.
on:
push:
branches: ['release/**', 'version/**']
pull_request:
paths:
- 'Build/**'
- '.github/workflows/module.yml'
release:
types: [published]
workflow_dispatch:
inputs:
tag:
description: Release tag to build (e.g. v4.0). Empty builds the branch it's run on.
required: false
permissions:
contents: read
env:
# As in tests.yml: the harness's console-event checks must run here.
PK_HARNESS_NO_SKIP: '1'
# As in tests.yml: a harness with no new assertion for this long is dumped
# and killed by its own watchdog.
PK_HARNESS_WATCHDOG_MINUTES: '2'
# Empty for a version's branch: the whole harness.
SECTIONS: ${{ github.event_name != 'push' && 'MODULE' || '' }}
jobs:
# Windows PowerShell 5.1. test-pwsh is the same on PowerShell 7: keep the two
# in step.
test:
name: Module
runs-on: windows-latest
timeout-minutes: 25
steps:
- uses: actions/checkout@v7
with:
ref: ${{ inputs.tag || github.event.release.tag_name || '' }}
- name: Run the harness on the module
timeout-minutes: 16
shell: powershell
env:
PK_HARNESS_DUMP_DIR: ${{ runner.temp }}\pk-harness-dumps
run: |
$harness = @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', '.\ParallelKit.Harness.ps1', '-AsModule')
if ($env:SECTIONS) { $harness += @('-Section', $env:SECTIONS) }
& powershell.exe @harness
exit $LASTEXITCODE
# As in tests.yml: the dumps of section AH cases that hung, and of the
# harness itself if its watchdog found it hung, if any.
- name: Upload the dumps of cases that hung
if: failure() || cancelled()
uses: actions/upload-artifact@v7
with:
name: module-dumps-5.1
path: ${{ runner.temp }}\pk-harness-dumps
if-no-files-found: ignore
retention-days: 7
# PowerShell 7. Keep in step with test.
test-pwsh:
name: Module (PowerShell 7)
runs-on: windows-latest
timeout-minutes: 25
steps:
- uses: actions/checkout@v7
with:
ref: ${{ inputs.tag || github.event.release.tag_name || '' }}
- name: Run the harness on the module under pwsh
timeout-minutes: 16
shell: pwsh
env:
PK_HARNESS_DUMP_DIR: ${{ runner.temp }}\pk-harness-dumps
run: |
$harness = @('-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', '.\ParallelKit.Harness.ps1', '-AsModule')
if ($env:SECTIONS) { $harness += @('-Section', $env:SECTIONS) }
& pwsh @harness
exit $LASTEXITCODE
- name: Upload the dumps of cases that hung
if: failure() || cancelled()
uses: actions/upload-artifact@v7
with:
name: module-dumps-pwsh
path: ${{ runner.temp }}\pk-harness-dumps
if-no-files-found: ignore
retention-days: 7
package:
name: Module package
needs: [test, test-pwsh]
runs-on: windows-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v7
with:
ref: ${{ inputs.tag || github.event.release.tag_name || '' }}
- name: Check the tag against the kit's version
if: inputs.tag || github.event_name == 'release'
shell: pwsh
env:
TAG: ${{ inputs.tag || github.event.release.tag_name }}
run: |
$version = [regex]::Match((Get-Content -Raw .\ParallelKit.ps1), '(?m)^# Version (\d+\.\d+(?:\.\d+)?)\b').Groups[1].Value
if ($env:TAG -ne "v$version") { throw "The tag is '$($env:TAG)', but ParallelKit.ps1 says version '$version'. Tag the commit whose version it is." }
- name: Build under Windows PowerShell
shell: powershell
run: |
& powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\Build\New-ParallelKitModule.ps1 -OutputDirectory .\out-5.1\ParallelKit
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
Test-ModuleManifest -Path .\out-5.1\ParallelKit\ParallelKit.psd1 -ErrorAction Stop | Format-List Name, Version, Guid, CompatiblePSEditions
- name: Build under PowerShell 7, and compare
shell: pwsh
run: |
& pwsh -NoProfile -ExecutionPolicy Bypass -File .\Build\New-ParallelKitModule.ps1 -OutputDirectory .\out\ParallelKit
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
Test-ModuleManifest -Path .\out\ParallelKit\ParallelKit.psd1 -ErrorAction Stop | Format-List Name, Version, Guid, CompatiblePSEditions
foreach ($file in 'ParallelKit.psm1', 'ParallelKit.psd1') {
$hashes = @('out', 'out-5.1' | ForEach-Object { (Get-FileHash ".\$_\ParallelKit\$file").Hash })
if ($hashes[0] -ne $hashes[1]) { throw "$file differs between the build under 5.1 ($($hashes[1])) and under 7 ($($hashes[0])). The same ParallelKit.ps1 must always give the same module." }
}
- name: Check it with PSScriptAnalyzer
shell: pwsh
run: |
if (-not (Get-Module -ListAvailable PSScriptAnalyzer)) { Install-PSResource PSScriptAnalyzer -Version 1.25.0 -Repository PSGallery -TrustRepository -Scope CurrentUser -ErrorAction Stop }
# It sometimes fails inside with "Object reference not set", losing
# results, or hangs. So: a process of its own, a time limit, and only
# a run with no such error counts.
$analyze = Join-Path $env:RUNNER_TEMP 'analyze.ps1'
$found = Join-Path $env:RUNNER_TEMP 'analyzer.json'
@'
param([string]$Path, [string]$Out)
Import-Module PSScriptAnalyzer -ErrorAction Stop
$problems = $null
$results = @(Invoke-ScriptAnalyzer -Path $Path -Recurse -ErrorAction SilentlyContinue -ErrorVariable problems)
if ($problems) { Write-Output ("PSScriptAnalyzer itself failed: " + $problems[0]); exit 2 }
Write-Output ("PSScriptAnalyzer " + (Get-Module PSScriptAnalyzer).Version + ": " + $results.Count + " results")
ConvertTo-Json -InputObject @($results | ForEach-Object { @{ Severity = [string]$_.Severity; RuleName = $_.RuleName; Line = $_.Line; Message = $_.Message } }) | Set-Content -LiteralPath $Out
exit 0
'@ | Set-Content -LiteralPath $analyze
$done = $false
foreach ($try in 1..5) {
$run = Start-Process -FilePath (Get-Process -Id $PID).Path -ArgumentList @('-NoProfile', '-File', "`"$analyze`"", '-Path', '.\out\ParallelKit', '-Out', "`"$found`"") -NoNewWindow -PassThru
if (-not $run.WaitForExit(120000)) { Write-Output "Try ${try}: still running after 2 minutes, stopped."; $run.Kill($true); continue }
if ($run.ExitCode -eq 0) { $done = $true; break }
}
if (-not $done) { throw "PSScriptAnalyzer didn't complete in 5 tries. Run this job again." }
$results = @(Get-Content -Raw -LiteralPath $found | ConvertFrom-Json)
$results | Group-Object Severity, RuleName | Format-Table Count, Name -AutoSize
$errors = @($results | Where-Object { $_.Severity -in 'Error', 'ParseError' })
if ($errors.Count -gt 0) {
$errors | Format-Table RuleName, Line, Message -Wrap
throw "PSScriptAnalyzer reports $($errors.Count) error(s), listed above. The Gallery wants those fixed before a module is published."
}
- name: Pack it
shell: pwsh
run: |
# Compress-PSResource came with PSResourceGet 1.1.0.
$have = Get-Module -ListAvailable Microsoft.PowerShell.PSResourceGet | Sort-Object Version -Descending | Select-Object -First 1
if ($null -eq $have -or $have.Version -lt [version]'1.1.0') {
Install-PSResource Microsoft.PowerShell.PSResourceGet -Version 1.2.0 -Repository PSGallery -TrustRepository -Scope CurrentUser -ErrorAction Stop
# A fresh process, so the version just installed is the one loaded.
$have = Get-Module -ListAvailable Microsoft.PowerShell.PSResourceGet | Sort-Object Version -Descending | Select-Object -First 1
}
$null = New-Item -ItemType Directory -Force -Path .\package
& pwsh -NoProfile -Command "Import-Module Microsoft.PowerShell.PSResourceGet -RequiredVersion $($have.Version) -ErrorAction Stop; Compress-PSResource -Path .\out\ParallelKit -DestinationPath .\package -ErrorAction Stop"
if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
$packages = @(Get-ChildItem .\package\*.nupkg)
if ($packages.Count -ne 1) { throw "Expected one package in .\package, found $($packages.Count)." }
# The module's files are the same for every build; the package around
# them isn't, so both are listed.
$lines = @(Get-FileHash $packages[0].FullName, .\out\ParallelKit\ParallelKit.psm1, .\out\ParallelKit\ParallelKit.psd1 | ForEach-Object { $_.Hash + ' ' + (Split-Path -Leaf $_.Path) })
$lines | Set-Content .\package\SHA256SUMS.txt
(@('### Module package', '', '```') + $lines + @('```')) | Add-Content $env:GITHUB_STEP_SUMMARY
$lines
- name: Keep the package
uses: actions/upload-artifact@v7
with:
name: ParallelKit-module
path: package/
if-no-files-found: error