Repository navigation
275 lines (251 loc) · 10.2 KB
/
Copy pathtest-samples.yml
File metadata and controls
275 lines (251 loc) · 10.2 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
name: Test Samples & Guides
on:
workflow_call:
inputs:
use-existing-artifacts:
description: 'Use npm-package and nuget-packages from this run instead of rebuilding'
type: boolean
default: false
workflow_dispatch:
inputs:
sample:
description: 'Specific sample to test (or "all")'
required: false
default: 'all'
type: choice
options:
- all
- cpp-app
- cpp-winui-app
- dotnet-app
- dotnet-file-app
- electron
- flutter-app
- maui-app
- node-winui
- packaging-cli
- rust-app
- sparse-app
- tauri-app
- wpf-app
- winui-app
- winui-solution
- winui-unpackaged-app
permissions:
contents: read
jobs:
# Manual runs stay self-contained; Build and Package calls us after uploading
# the same-run artifacts, so PRs do not publish the CLI a second time.
build:
if: ${{ !inputs.use-existing-artifacts }}
runs-on: windows-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
with:
dotnet-version: '10.0.x'
- uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: '22'
- name: Build npm package
shell: pwsh
run: .\scripts\build-cli.ps1 -SkipTests -SkipMsix -SkipDocs
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: npm-package
path: artifacts/*.tgz
if-no-files-found: error
overwrite: true
- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: nuget-packages
path: artifacts/nuget/*.nupkg
if-no-files-found: error
overwrite: true
test-sample:
needs: [build]
if: ${{ !cancelled() && ((inputs.use-existing-artifacts && needs.build.result == 'skipped') || needs.build.result == 'success') }}
strategy:
fail-fast: false
matrix:
sample: [cpp-app, cpp-winui-app, dotnet-app, dotnet-file-app, electron, flutter-app, maui-app, node-winui, packaging-cli, rust-app, sparse-app, tauri-app, wpf-app, winui-app, winui-solution, winui-unpackaged-app]
runs-on: windows-latest
name: ${{ matrix.sample }}
steps:
- name: Check if sample should run
id: check
shell: pwsh
env:
REQUESTED_SAMPLE: ${{ inputs.sample || 'all' }}
MATRIX_SAMPLE: ${{ matrix.sample }}
run: |
$requested = $env:REQUESTED_SAMPLE
if ($requested -ne 'all' -and $requested -ne $env:MATRIX_SAMPLE) {
echo "skip=true" >> $env:GITHUB_OUTPUT
} else {
echo "skip=false" >> $env:GITHUB_OUTPUT
}
- name: Checkout
if: steps.check.outputs.skip != 'true'
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
# Both entry points use artifacts from this run, never a privileged workflow_run.
- name: Download npm package
if: steps.check.outputs.skip != 'true'
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: npm-package
path: artifacts/npm
# Download NuGet package for .NET samples
- name: Download NuGet package
if: >-
steps.check.outputs.skip != 'true' &&
contains(fromJson('["dotnet-app", "dotnet-file-app", "wpf-app"]'), matrix.sample)
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: nuget-packages
path: artifacts/nuget
- name: Add local NuGet source
if: >-
steps.check.outputs.skip != 'true' &&
contains(fromJson('["dotnet-app", "dotnet-file-app", "wpf-app"]'), matrix.sample)
shell: pwsh
run: |
$nugetPath = "artifacts/nuget"
$resolvedPath = (Resolve-Path $nugetPath).Path
dotnet nuget add source $resolvedPath --name WinAppLocal
if ($LASTEXITCODE -ne 0) { throw "Failed to add local NuGet source" }
Write-Host "Added local NuGet source: $resolvedPath"
# --- Toolchain setup (conditional per sample) ---
- name: Setup .NET
if: >-
steps.check.outputs.skip != 'true' &&
contains(fromJson('["dotnet-app", "dotnet-file-app", "wpf-app", "sparse-app", "packaging-cli", "electron", "maui-app", "winui-app", "winui-solution", "winui-unpackaged-app"]'), matrix.sample)
uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
with:
dotnet-version: '10.0.x'
- name: Install MAUI Windows workload
if: >-
steps.check.outputs.skip != 'true' &&
matrix.sample == 'maui-app'
shell: pwsh
run: dotnet workload install maui-windows
- name: Setup Node.js
if: >-
steps.check.outputs.skip != 'true' &&
contains(fromJson('["electron", "node-winui", "tauri-app", "cpp-app", "cpp-winui-app", "dotnet-app", "dotnet-file-app", "wpf-app", "sparse-app", "rust-app", "flutter-app", "packaging-cli", "maui-app", "winui-app", "winui-solution", "winui-unpackaged-app"]'), matrix.sample)
uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7.1.0
with:
node-version: '22'
- name: Setup Flutter
if: >-
steps.check.outputs.skip != 'true' &&
matrix.sample == 'flutter-app'
uses: subosito/flutter-action@1a449444c387b1966244ae4d4f8c696479add0b2 # v2.23.0
with:
channel: stable
- name: Setup Rust
if: >-
steps.check.outputs.skip != 'true' &&
contains(fromJson('["rust-app", "tauri-app"]'), matrix.sample)
shell: pwsh
# windows-latest already ships rustup with a stable toolchain, so this selects
# what is on the image rather than pulling a third-party action or fetching a toolchain.
run: |
rustup default stable
rustc --version
cargo --version
# Install the Inno Setup compiler (ISCC.exe) so the sparse-app installer test
# actually compiles installer/setup.iss instead of being skipped for a missing ISCC.
- name: Setup Inno Setup
if: >-
steps.check.outputs.skip != 'true' &&
matrix.sample == 'sparse-app'
shell: pwsh
run: |
choco install innosetup --no-progress -y
$iscc = Join-Path ${env:ProgramFiles(x86)} 'Inno Setup 6\ISCC.exe'
if (-not (Test-Path $iscc)) { throw "ISCC.exe not found at $iscc after install" }
Add-Content -Path $env:GITHUB_PATH -Value (Split-Path $iscc)
Write-Host "Inno Setup installed: $iscc"
# --- Run the sample's self-contained Pester test ---
# Hosted Windows images ship Pester 5.x, so this normally short-circuits.
# When it does need to install, PSGallery registration/download is a known
# flake ("Missing option value for: '-source'"), so retry before failing.
- name: Install Pester
if: steps.check.outputs.skip != 'true'
shell: pwsh
run: |
function Get-Pester5 {
Get-Module -Name Pester -ListAvailable |
Where-Object { $_.Version.Major -ge 5 } |
Sort-Object Version -Descending |
Select-Object -First 1
}
$pester = Get-Pester5
if (-not $pester) {
foreach ($attempt in 1..3) {
try {
if (-not (Get-PSRepository -Name PSGallery -ErrorAction SilentlyContinue)) {
Register-PSRepository -Default -ErrorAction Stop
}
Set-PSRepository -Name PSGallery -InstallationPolicy Trusted -ErrorAction Stop
Install-Module -Name Pester -Force -SkipPublisherCheck -Scope CurrentUser -MinimumVersion 5.0 -Repository PSGallery -ErrorAction Stop
} catch {
Write-Host "::warning::Pester install attempt $attempt failed: $($_.Exception.Message)"
}
$pester = Get-Pester5
if ($pester) { break }
if ($attempt -lt 3) { Start-Sleep -Seconds (10 * $attempt) }
}
}
if (-not $pester) {
Write-Error "Pester 5.x is not available after 3 install attempts"
exit 1
}
Write-Host "Using Pester $($pester.Version)"
- name: Run ${{ matrix.sample }} test
if: steps.check.outputs.skip != 'true'
# The slowest sample takes about 15 minutes. A hang should fail the job, not hold a runner
# for the 6-hour default.
timeout-minutes: 40
shell: pwsh
run: |
$container = New-PesterContainer -Path "samples/${{ matrix.sample }}/test.Tests.ps1" -Data @{
WinappPath = "artifacts/npm"
}
$config = New-PesterConfiguration
$config.Run.Container = $container
$config.Run.Exit = $true
$config.Output.Verbosity = 'Detailed'
$config.TestResult.Enabled = $true
$config.TestResult.OutputPath = Join-Path $env:GITHUB_WORKSPACE "test-results-${{ matrix.sample }}.xml"
$config.TestResult.OutputFormat = 'JUnitXml'
Invoke-Pester -Configuration $config
- name: Upload test results
if: always() && steps.check.outputs.skip != 'true'
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: test-results-${{ matrix.sample }}
path: test-results-${{ matrix.sample }}.xml
if-no-files-found: error
overwrite: true
# Summary job to provide a single check status for branch protection
test-samples-result:
if: always()
needs: [build, test-sample]
runs-on: ubuntu-latest
steps:
- name: Check results
shell: pwsh
env:
BUILD_RESULT: ${{ needs.build.result }}
SAMPLE_RESULT: ${{ needs.test-sample.result }}
REUSE_ARTIFACTS: ${{ inputs.use-existing-artifacts }}
run: |
$expectedBuild = if ($env:REUSE_ARTIFACTS -eq 'true') { 'skipped' } else { 'success' }
if ($env:BUILD_RESULT -ne $expectedBuild -or $env:SAMPLE_RESULT -ne 'success') {
throw "Sample validation did not succeed (build=$env:BUILD_RESULT, tests=$env:SAMPLE_RESULT)"
}
Write-Host "All requested sample jobs passed"