Skip to content

Commit 58e246a

Browse files
authored
Merge pull request #1166 from michaeltlombardi/maint/main/speed-builds
(MAINT) Minimally Parallelize pester tests
2 parents cad4c63 + 405ed02 commit 58e246a

File tree

3 files changed

+205
-60
lines changed

3 files changed

+205
-60
lines changed

.github/workflows/rust.new.yml

Lines changed: 123 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,133 @@ on:
1414
env:
1515
CARGO_TERM_COLOR: always
1616

17+
defaults:
18+
run:
19+
shell: pwsh
20+
1721
jobs:
18-
build-linux-new:
22+
linux-build:
1923
runs-on: ubuntu-latest
2024
steps:
21-
- uses: actions/checkout@v5
22-
- name: Install prerequisites
23-
shell: pwsh
24-
run: ./build.new.ps1 -SkipBuild -Clippy -Verbose
25-
- name: Build
26-
shell: pwsh
27-
run: ./build.new.ps1 -Clippy -Verbose
28-
- name: Run tests
29-
shell: pwsh
30-
run: ./build.new.ps1 -Test -Verbose
31-
32-
build-windows-new:
33-
runs-on: windows-latest
25+
- uses: actions/checkout@v5
26+
- name: Install prerequisites
27+
run: ./build.new.ps1 -SkipBuild -Clippy -Verbose
28+
- name: Build
29+
run: ./build.new.ps1 -Clippy -Verbose
30+
- name: Run rust tests
31+
run: ./build.new.ps1 -SkipBuild -Test -ExcludePesterTests -Verbose
32+
- name: Prepare build artifact
33+
run: tar -cvf bin.tar bin/
34+
- name: Upload build artifact
35+
uses: actions/upload-artifact@v4
36+
with:
37+
name: linux-bin
38+
path: bin.tar
39+
linux-pester:
40+
needs: linux-build
41+
strategy:
42+
matrix:
43+
group: [dsc, adapters, extensions, resources]
44+
runs-on: ubuntu-latest
3445
steps:
35-
- uses: actions/checkout@v5
36-
- name: Install prerequisites
37-
shell: pwsh
38-
run: ./build.new.ps1 -SkipBuild -Clippy -Verbose
39-
- name: Build
40-
shell: pwsh
41-
run: ./build.new.ps1 -Clippy -Verbose
42-
- name: Run tests
43-
shell: pwsh
44-
run: ./build.new.ps1 -Test -Verbose
46+
- uses: actions/checkout@v5
47+
- name: Download build artifact
48+
uses: actions/download-artifact@v4
49+
with:
50+
name: linux-bin
51+
- name: Expand build artifact
52+
run: tar -xvf bin.tar
53+
- name: Test ${{matrix.group}}
54+
run: |-
55+
$params = @{
56+
SkipBuild = $true
57+
Test = $true
58+
ExcludeRustTests = $true
59+
Verbose = $true
60+
}
61+
./build.new.ps1 @params -PesterTestGroup ${{matrix.group}}
4562
46-
build-macos-new:
63+
macos-build:
64+
runs-on: macos-latest
65+
steps:
66+
- uses: actions/checkout@v5
67+
- name: Install prerequisites
68+
run: ./build.new.ps1 -SkipBuild -Clippy -Verbose
69+
- name: Build
70+
run: ./build.new.ps1 -Clippy -Verbose
71+
- name: Run rust tests
72+
run: ./build.new.ps1 -SkipBuild -Test -ExcludePesterTests -Verbose
73+
- name: Prepare build artifact
74+
run: tar -cvf bin.tar bin/
75+
- name: Upload build artifact
76+
uses: actions/upload-artifact@v4
77+
with:
78+
name: macos-bin
79+
path: bin.tar
80+
macos-pester:
81+
needs: macos-build
82+
strategy:
83+
matrix:
84+
group: [dsc, adapters, extensions, resources]
4785
runs-on: macos-latest
4886
steps:
49-
- uses: actions/checkout@v5
50-
- name: Install prerequisites
51-
shell: pwsh
52-
run: ./build.new.ps1 -SkipBuild -Clippy -Verbose
53-
- name: Build
54-
shell: pwsh
55-
run: ./build.new.ps1 -Clippy -Verbose
56-
- name: Run tests
57-
shell: pwsh
58-
run: ./build.new.ps1 -Test -Verbose
87+
- uses: actions/checkout@v5
88+
- name: Download build artifact
89+
uses: actions/download-artifact@v4
90+
with:
91+
name: macos-bin
92+
- name: Expand build artifact
93+
run: tar -xvf bin.tar
94+
- name: Test ${{matrix.group}}
95+
run: |-
96+
$params = @{
97+
SkipBuild = $true
98+
Test = $true
99+
ExcludeRustTests = $true
100+
Verbose = $true
101+
}
102+
./build.new.ps1 @params -PesterTestGroup ${{matrix.group}}
103+
104+
# Windows
105+
windows-build:
106+
runs-on: windows-latest
107+
steps:
108+
- uses: actions/checkout@v5
109+
- name: Install prerequisites
110+
run: ./build.new.ps1 -SkipBuild -Clippy -Verbose
111+
- name: Build
112+
run: ./build.new.ps1 -Clippy -Verbose
113+
- name: Run rust tests
114+
run: ./build.new.ps1 -SkipBuild -Test -ExcludePesterTests -Verbose
115+
- name: List bin folder files
116+
run: Get-ChildItem bin
117+
- name: Prepare build artifact
118+
run: tar -cvf bin.tar bin
119+
- name: Upload build artifact
120+
uses: actions/upload-artifact@v4
121+
with:
122+
name: windows-bin
123+
path: bin.tar
124+
windows-pester:
125+
needs: windows-build
126+
strategy:
127+
matrix:
128+
group: [dsc, adapters, extensions, resources]
129+
runs-on: windows-latest
130+
steps:
131+
- uses: actions/checkout@v5
132+
- name: Download build artifact
133+
uses: actions/download-artifact@v4
134+
with:
135+
name: windows-bin
136+
- name: Expand build artifact
137+
run: tar -xvf bin.tar
138+
- name: Test ${{matrix.group}}
139+
run: |-
140+
$params = @{
141+
SkipBuild = $true
142+
Test = $true
143+
ExcludeRustTests = $true
144+
Verbose = $true
145+
}
146+
./build.new.ps1 @params -PesterTestGroup ${{matrix.group}}

build.helpers.psm1

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,9 @@ function Test-RustProject {
12741274
function Test-ProjectWithPester {
12751275
[cmdletbinding()]
12761276
param(
1277+
[DscProjectDefinition[]]$Project,
1278+
[ValidateSet("dsc", "adapters", "extensions", "grammars", "resources")]
1279+
[string[]]$Group,
12771280
[switch]$UsingADO
12781281
)
12791282

@@ -1297,10 +1300,35 @@ function Test-ProjectWithPester {
12971300

12981301
Write-Verbose "Updated Pester module location:`n`t$((Get-Module -Name Pester -ListAvailable).Path)"
12991302
}
1303+
$pesterParams = @{
1304+
Output = 'Detailed'
1305+
ErrorAction = 'Stop'
1306+
}
1307+
if ($Project) {
1308+
$pesterParams.ExcludePath = $Project.RelativePath | Where-Object -FilterScript {
1309+
$_.Name -notin $Project.Name
1310+
}
1311+
}
1312+
if ($Group) {
1313+
$pesterParams.Path = $Group
1314+
}
13001315
}
13011316

13021317
process {
1303-
Invoke-Pester -Output Detailed -ErrorAction Stop
1318+
if ($Group -and $Project) {
1319+
Write-Verbose (@(
1320+
"Invoking pester for groups and projects:"
1321+
"Groups: [$($Group -join ', ')]"
1322+
"Projects: [$($Project.Name -join ', ')]"
1323+
) -join "`n`t")
1324+
} elseif ($Group) {
1325+
Write-Verbose "Invoking pester for groups: [$($Group -join ', ')]"
1326+
} elseif ($Project) {
1327+
Write-Verbose "Invoking pester for projects: [$($Project.Name -join ', ')]"
1328+
} else {
1329+
Write-Verbose "Invoking pester for all groups and projects"
1330+
}
1331+
Invoke-Pester @pesterParams
13041332
}
13051333
}
13061334
#endregion Test project functions

build.new.ps1

Lines changed: 53 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ param(
8383
)]
8484
$PackageType,
8585
[switch]$Test,
86+
[string[]]$Project,
87+
[switch]$ExcludeRustTests,
88+
[switch]$ExcludePesterTests,
89+
[ValidateSet("dsc", "adapters", "extensions", "grammars", "resources")]
90+
[string[]]$PesterTestGroup,
8691
[switch]$GetPackageVersion,
8792
[switch]$SkipLinkCheck,
8893
[switch]$UseX64MakeAppx,
@@ -110,7 +115,14 @@ begin {
110115
if ($usingADO -or $UseCFSAuth) {
111116
$UseCFS = $true
112117
}
118+
# Import the build data
113119
$BuildData = Import-DscBuildData
120+
# Filter projects if needed.
121+
if ($Project.Count -ge 1) {
122+
$BuildData.Projects = $BuildData.Projects | Where-Object -FilterScript {
123+
$_.Name -in $Project
124+
}
125+
}
114126
$VerboseParam = @{}
115127
if ($VerbosePreference -eq 'Continue' -and -not $Quiet) {
116128
$VerboseParam.Verbose = $true
@@ -177,27 +189,29 @@ process {
177189
Write-BuildProgress @progressParams -Status 'Ensuring Rust is up-to-date'
178190
Update-Rust @VerboseParam
179191
}
180-
192+
181193
if (!$usingADO) {
182194
Write-BuildProgress @progressParams -Status 'Setting RustUp to default channel'
183195
$rustup, $channel = Get-RustUp @VerboseParam
184196
& $rustup default stable
185197
}
186-
198+
187199
if ($Clippy) {
188200
Write-BuildProgress @progressParams -Status 'Ensuring Clippy is available and updated'
189201
Install-Clippy -UseCFS:$UseCFS -Architecture $Architecture @VerboseParam
190202
}
203+
204+
if (-not ($SkipBuild -and $Test -and $ExcludeRustTests)) {
205+
# Install Node if needed
206+
Write-BuildProgress @progressParams -Status 'Ensuring Node.JS is available'
207+
Install-NodeJS @VerboseParam
191208

192-
# Install Node if needed
193-
Write-BuildProgress @progressParams -Status 'Ensuring Node.JS is available'
194-
Install-NodeJS @VerboseParam
195-
196-
# Ensure tree-sitter is installed
197-
Write-BuildProgress @progressParams -Status 'Ensuring tree-sitter is available'
198-
Install-TreeSitter -UseCFS:$UseCFS @VerboseParam
209+
# Ensure tree-sitter is installed
210+
Write-BuildProgress @progressParams -Status 'Ensuring tree-sitter is available'
211+
Install-TreeSitter -UseCFS:$UseCFS @VerboseParam
212+
}
199213
}
200-
214+
201215
if (!$SkipBuild -and !$SkipLinkCheck -and $IsWindows) {
202216
Write-BuildProgress @progressParams -Status "Ensuring Windows C++ build tools are available"
203217
Install-WindowsCPlusPlusBuildTools @VerboseParam
@@ -220,29 +234,44 @@ process {
220234
Write-BuildProgress @progressParams -Status "Copying build artifacts"
221235
Copy-BuildArtifact @buildParams -ExecutableFile $BuildData.PackageFiles.Executable @VerboseParam
222236
}
223-
224-
if (!$Clippy -and !$SkipBuild) {
237+
238+
# Ensure PATH includes the output artifacts after building and before testing.
239+
if ((!$Clippy -and !$SkipBuild) -or $Test) {
225240
$progressParams.Activity = 'Updating environment variables'
226241
Write-BuildProgress @progressParams
227242
Update-PathEnvironment -Architecture $Architecture -Release:$Release @VerboseParam
228243
}
229-
244+
230245
if ($Test) {
231246
$progressParams.Activity = 'Testing projects'
232247
Write-BuildProgress @progressParams
233-
Write-BuildProgress @progressParams -Status "Installing PowerShell test prerequisites"
234-
Install-PowerShellTestPrerequisite @VerboseParam -UsingAdo:$usingADO
235-
$testParams = @{
236-
Project = $BuildData.Projects
237-
Architecture = $Architecture
238-
Release = $Release
248+
249+
if (-not $ExcludeRustTests) {
250+
$rustTestParams = @{
251+
Project = $BuildData.Projects
252+
Architecture = $Architecture
253+
Release = $Release
254+
}
255+
Write-BuildProgress @progressParams -Status "Testing Rust projects"
256+
Test-RustProject @rustTestParams @VerboseParam
257+
}
258+
if (-not $ExcludePesterTests) {
259+
$installParams = @{
260+
UsingADO = $usingADO
261+
}
262+
$pesterParams = @{
263+
UsingADO = $usingADO
264+
}
265+
if ($null -ne $PesterTestGroup) {
266+
$pesterParams.Group = $PesterTestGroup
267+
}
268+
Write-BuildProgress @progressParams -Status "Installing PowerShell test prerequisites"
269+
Install-PowerShellTestPrerequisite @installParams @VerboseParam
270+
Write-BuildProgress @progressParams -Status "Invoking pester"
271+
Test-ProjectWithPester @pesterParams @VerboseParam
239272
}
240-
Write-BuildProgress @progressParams -Status "Testing Rust projects"
241-
Test-RustProject @testParams @VerboseParam
242-
Write-BuildProgress @progressParams -Status "Invoking pester"
243-
Test-ProjectWithPester -UsingADO:$usingADO @VerboseParam
244273
}
245-
274+
246275
if (-not [string]::IsNullOrEmpty($PackageType)) {
247276
$progressParams.Activity = "Packaging"
248277
$packageParams = @{

0 commit comments

Comments
 (0)