-
Notifications
You must be signed in to change notification settings - Fork 147
379 lines (317 loc) · 13.3 KB
/
Copy pathpr-validation.yml
File metadata and controls
379 lines (317 loc) · 13.3 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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
# PR Validation — Full cross-architecture build and test
#
# Mirrors the Azure Pipelines CI pipeline (azure-pipelines.yml) but runs as a
# GitHub Actions workflow so PR checks work without Azure DevOps integration.
#
# Pipeline structure:
# 1. Three parallel scrape jobs (x64, x86, arm64) generate metadata source
# 2. One build job assembles the winmd, packages, samples, and runs tests
name: PR Validation
on:
pull_request:
branches: [main]
paths-ignore:
- 'apidocs/**'
- 'docs/**'
push:
branches: [main]
paths-ignore:
- 'apidocs/**'
- 'docs/**'
workflow_dispatch:
permissions:
contents: read
pull-requests: write
concurrency:
group: pr-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
BUILD_CONFIGURATION: Release
jobs:
# ──────────────────────────────────────────────────────────────────────
# Stage 1: Parallel header scraping (one job per architecture)
# ──────────────────────────────────────────────────────────────────────
scrape:
name: 'Scrape headers: ${{ matrix.arch }}'
runs-on: windows-2022
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
arch: [x64, x86, arm64]
include:
- arch: x64
extra_args: ''
set_version: true
- arch: x86
extra_args: '-scrapeConstants'
set_version: false
- arch: arm64
extra_args: ''
set_version: false
steps:
- uses: actions/checkout@v4
with:
lfs: true
fetch-depth: 0
- uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- name: Install nbgv and set version
if: matrix.set_version
shell: pwsh
run: |
.\scripts\Install-DotNetTool.ps1 -Name nbgv -NuGetConfigFile "${{ github.workspace }}\nuget.config"
nbgv cloud
- name: Generate metadata source (${{ matrix.arch }})
shell: pwsh
run: .\scripts\GenerateMetadataSource.ps1 -arch ${{ matrix.arch }} ${{ matrix.extra_args }}
- name: Upload generated assets
uses: actions/upload-artifact@v4
with:
name: generated_${{ matrix.arch }}
path: generation/WinSDK/obj
retention-days: 1
- name: Upload build logs
uses: actions/upload-artifact@v4
if: always()
with:
name: scrape_logs_${{ matrix.arch }}
path: bin/logs
retention-days: 7
# ──────────────────────────────────────────────────────────────────────
# Stage 2: Build, test, and package (depends on all scrape jobs)
# ──────────────────────────────────────────────────────────────────────
build-test:
name: 'Build, test, package'
needs: [scrape]
runs-on: windows-2022
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
with:
lfs: true
fetch-depth: 0
- uses: actions/setup-dotnet@v4
with:
global-json-file: global.json
- uses: microsoft/setup-msbuild@v2
- name: Download all generated assets
uses: actions/download-artifact@v4
with:
pattern: generated_*
path: generation/WinSDK/obj
merge-multiple: true
- name: Build metadata binary
shell: pwsh
run: .\scripts\BuildMetadataBin.ps1 -assetsScrapedSeparately
- name: Package
shell: pwsh
run: .\scripts\DoPackages.ps1
- name: Build samples
shell: pwsh
run: .\scripts\DoSamples.ps1
- name: Run tests
shell: pwsh
run: .\scripts\DoTests.ps1
- name: Download baseline winmd from target branch
if: github.event_name == 'pull_request'
id: baseline
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const path = require('path');
// Find the latest successful run on the target branch
const baseBranch = context.payload.pull_request.base.ref;
const runs = await github.rest.actions.listWorkflowRuns({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: 'pr-validation.yml',
branch: baseBranch,
status: 'success',
per_page: 1
});
if (runs.data.workflow_runs.length === 0) {
core.warning(`No successful runs found on ${baseBranch}. Will fall back to NuGet baseline.`);
return;
}
const runId = runs.data.workflow_runs[0].id;
core.info(`Found baseline run ${runId} on ${baseBranch}`);
// Find the winmd artifact
const artifacts = await github.rest.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: runId
});
const winmdArtifact = artifacts.data.artifacts.find(a => a.name === 'winmd');
if (!winmdArtifact) {
core.warning('No winmd artifact found in baseline run. Will fall back to NuGet baseline.');
return;
}
// Download and extract
const download = await github.rest.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: winmdArtifact.id,
archive_format: 'zip'
});
const outputDir = 'bin/baseline-artifact';
fs.mkdirSync(outputDir, { recursive: true });
const zipPath = path.join(outputDir, 'artifact.zip');
fs.writeFileSync(zipPath, Buffer.from(download.data));
// Extract using PowerShell
const { execSync } = require('child_process');
execSync(`Expand-Archive -Path "${zipPath}" -DestinationPath "${outputDir}" -Force`, { shell: 'pwsh' });
fs.unlinkSync(zipPath);
core.info(`Extracted baseline winmd to ${outputDir}`);
- name: Generate API surface diff
if: github.event_name == 'pull_request'
id: apidump
shell: pwsh
run: |
$ErrorActionPreference = 'Continue'
$PSNativeCommandUseErrorActionPreference = $false
$winmdUtils = "bin\Release\net8.0\WinmdUtils.dll"
$currentWinmd = "bin\Windows.Win32.winmd"
# Determine baseline: prefer main branch artifact, fall back to last release
$baselineWinmd = "bin\baseline-artifact\Windows.Win32.winmd"
if (-not (Test-Path $baselineWinmd)) {
Write-Host "No main branch artifact found, falling back to last NuGet release..."
. .\scripts\CommonUtils.ps1
$baselineWinmd = Get-Win32MetadataLastReleaseWinmdPath
}
Write-Host "Baseline: $baselineWinmd"
Write-Host "Current: $currentWinmd"
# Dump baseline
Write-Host "Dumping baseline..."
& dotnet $winmdUtils dump --winmd $baselineWinmd --output bin\baseline.apidump.cs
if ($LASTEXITCODE -ne 0) { throw "Failed to dump baseline" }
# Dump current build
Write-Host "Dumping current build..."
& dotnet $winmdUtils dump --winmd $currentWinmd --output bin\current.apidump.cs
if ($LASTEXITCODE -ne 0) { throw "Failed to dump current" }
# Generate diff — git diff exits 1 when differences exist, which is expected
& cmd /c "git diff --no-index --unified=3 bin\baseline.apidump.cs bin\current.apidump.cs > bin\api-diff.patch 2>&1"
$diffExitCode = $LASTEXITCODE
if ($diffExitCode -eq 0) {
Write-Host "No API differences found."
"has_diff=false" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
} else {
Write-Host "API differences detected."
"has_diff=true" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
# Count additions/deletions from the patch file
$diffLines = Get-Content bin\api-diff.patch
$additions = ($diffLines | Where-Object { $_ -match '^\+[^+]' }).Count
$deletions = ($diffLines | Where-Object { $_ -match '^\-[^-]' }).Count
"additions=$additions" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
"deletions=$deletions" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
Write-Host "+$additions additions / -$deletions deletions"
# Truncate if too large for a GH comment
$diffText = $diffLines -join "`n"
$maxLen = 60000
if ($diffText.Length -gt $maxLen) {
$diffText = $diffText.Substring(0, $maxLen) + "`n`n... (diff truncated - see full artifact)"
Set-Content -Path bin\api-diff.patch -Value $diffText -Encoding UTF8
}
}
# Reset LASTEXITCODE so GitHub Actions doesn't treat this step as failed
$global:LASTEXITCODE = 0
- name: Post API diff comment on PR
if: github.event_name == 'pull_request' && steps.apidump.outputs.has_diff == 'true'
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const diff = fs.readFileSync('bin/api-diff.patch', 'utf8');
const prNumber = context.payload.pull_request.number;
const additions = ${{ steps.apidump.outputs.additions || 0 }};
const deletions = ${{ steps.apidump.outputs.deletions || 0 }};
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const marker = '<!-- win32metadata-api-diff -->';
const body = `${marker}
## 📋 API Surface Diff
**+${additions} additions / -${deletions} deletions** vs main branch ([full build log](${runUrl}))
<details>
<summary>Click to expand API diff</summary>
\`\`\`diff
${diff}
\`\`\`
</details>
> This comment is automatically updated on each push.`;
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
per_page: 100
});
const existing = comments.data.find(c => c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: body
});
}
- name: Post no-diff comment on PR
if: github.event_name == 'pull_request' && steps.apidump.outputs.has_diff == 'false'
uses: actions/github-script@v7
with:
script: |
const prNumber = context.payload.pull_request.number;
const marker = '<!-- win32metadata-api-diff -->';
const body = `${marker}\n## 📋 API Surface Diff\n\n✅ No API differences vs last release.\n\n> This comment is automatically updated on each push.`;
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
per_page: 100
});
const existing = comments.data.find(c => c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body: body
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: body
});
}
- name: Upload winmd and API dump
uses: actions/upload-artifact@v4
if: always()
with:
name: winmd
path: |
bin/Windows.Win32.winmd
bin/current.apidump.cs
bin/baseline.apidump.cs
bin/api-diff.patch
retention-days: 30
- name: Upload build logs
uses: actions/upload-artifact@v4
if: always()
with:
name: build_logs
path: bin/logs
retention-days: 7
- name: Upload NuGet packages
uses: actions/upload-artifact@v4
with:
name: NuGetPackages
path: bin/Packages/Release/NuGet
retention-days: 7