Repository navigation
438 lines (394 loc) · 17.1 KB
/
Copy pathMuPrValidation.yml
File metadata and controls
438 lines (394 loc) · 17.1 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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
# A reusable workflow that builds mu_tiano_platforms QEMU platforms with
# PR changes and validates booting on QEMU.
#
# The caller specifies which submodule in mu_tiano_platforms to update
# (e.g. MU_BASECORE or Common/MU) with the PR commit before building.
#
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
##
name: Mu QEMU PR Validation
on:
workflow_call:
inputs:
app-id:
description: "GitHub App ID for generating tokens (must be passed since vars don't cross repo boundaries)"
required: true
type: string
caller-ref:
description: "Commit SHA to checkout for the PR head"
required: true
type: string
caller-repo:
description: "Full repo name (owner/repo) where the PR commit exists"
required: true
type: string
caller-repo-name:
description: "Short display name for the calling repo (e.g. mu_basecore, mu_plus)"
required: true
type: string
head-sha:
description: "PR head commit SHA for commit status updates"
required: false
type: string
default: ''
pr-number:
description: "Pull request number in the calling repository"
required: true
type: number
submodule-path:
description: "Path to the submodule in mu_tiano_platforms to update (e.g. MU_BASECORE, Common/MU)"
required: true
type: string
secrets:
private-key:
description: "GitHub App private key for generating tokens"
required: true
permissions:
contents: read
actions: read
jobs:
notify-in-progress:
name: Post In-Progress Notification
runs-on: ubuntu-latest
steps:
- name: Generate GitHub App Token
id: app-token
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
app-id: ${{ inputs.app-id }}
private-key: ${{ secrets.private-key }}
owner: ${{ github.repository_owner }}
- name: Update PR Comment to In-Progress
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ steps.app-token.outputs.token }}
script: |
const issue_number = ${{ inputs.pr-number }};
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
const hiddenMarker = '<!-- mu-qemu-validation-result -->';
const workflowName = '${{ github.workflow }}';
const marker = `*This comment was automatically generated by the ${workflowName} workflow.*`;
const comments = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number,
});
const existingComment = comments.data.find((c) =>
c.body.includes(hiddenMarker)
);
const body = [
hiddenMarker,
'## :hourglass_flowing_sand: QEMU Validation In Progress',
'',
'A new QEMU validation run has started. Results from any previous run(s) are now outdated.',
'',
'> **Note:** Previous results are available in this comment\'s edit history.',
'',
`**Workflow run:** ${runUrl}`,
'',
marker,
].join('\n');
if (existingComment) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number,
body,
});
}
- name: Set In-Progress Commit Status
# TODO: Requires microsoft org admin to accept permissions
# if: inputs.head-sha != ''
if: false
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
github-token: ${{ steps.app-token.outputs.token }}
script: |
const runUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: '${{ inputs.head-sha }}',
state: 'pending',
description: 'Pre-build setup in progress',
context: 'Mu QEMU PR Validation',
target_url: runUrl,
});
build-and-boot:
name: ${{ matrix.platform }} - Build and Boot
runs-on: ubuntu-latest
needs: [notify-in-progress]
container:
image: ghcr.io/microsoft/mu_devops/ubuntu-24-test:latest
options: ${{ matrix.platform == 'Q35' && '--device=/dev/kvm:/dev/kvm' || '' }}
strategy:
fail-fast: false
matrix:
include:
- platform: Q35
build_pkg: QemuQ35Pkg
build_file: Platforms/QemuQ35Pkg/PlatformBuild.py
run_flags: "QEMU_ACCEL=kvm SHUTDOWN_AFTER_RUN=TRUE QEMU_HEADLESS=TRUE EMPTY_DRIVE=TRUE BLD_*_QEMU_CORE_NUM=2"
- platform: ArmVirt
build_pkg: QemuArmVirtPkg
build_file: Platforms/QemuArmVirtPkg/PlatformBuild.py
run_flags: "SHUTDOWN_AFTER_RUN=TRUE QEMU_HEADLESS=TRUE EMPTY_DRIVE=TRUE"
env:
TOOL_CHAIN_TAG: CLANGPDB
BUILD_TARGET: DEBUG
steps:
- name: Generate GitHub App Token
if: inputs.head-sha != ''
id: app-token
uses: actions/create-github-app-token@64ab729a6294000f5aa4a4bc0b73d1f32bc45510 # v3.3.0
with:
app-id: ${{ inputs.app-id }}
private-key: ${{ secrets.private-key }}
owner: ${{ github.repository_owner }}
- name: Checkout mu_tiano_platforms
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
ref: main
repository: microsoft/mu_tiano_platforms
- name: Mark Workspace as Safe for Git
shell: bash
run: git config --global --add safe.directory '*'
- name: Install Python Prerequisites
shell: bash
run: pip install -r pip-requirements.txt --upgrade
- name: Redirect Submodule URLs
shell: bash
run: |
git config --global url."https://github.com/TF-Hafnium/hafnium-prebuilts".insteadOf "https://git.trustedfirmware.org/hafnium/prebuilts"
git config --global url."https://github.com/TF-Hafnium/hafnium-project-reference".insteadOf "https://git.trustedfirmware.org/hafnium/project/reference"
git config --global url."https://github.com/TF-Hafnium/hafnium-third_party-dtc".insteadOf "https://git.trustedfirmware.org/hafnium/third_party/dtc"
git config --global url."https://github.com/TF-Hafnium/hafnium-third_party-googletest".insteadOf "https://git.trustedfirmware.org/hafnium/third_party/googletest"
git config --global url."https://github.com/TF-Shared/libTPM".insteadOf "https://review.trustedfirmware.org/shared/libTPM"
git config --global url."https://github.com/TF-Shared/transfer-list-library".insteadOf "https://review.trustedfirmware.org/shared/transfer-list-library"
- name: Stuart Setup
shell: bash
run: |
stuart_setup -c ${{ matrix.build_file }} \
TOOL_CHAIN_TAG=${{ env.TOOL_CHAIN_TAG }} \
-t ${{ env.BUILD_TARGET }}
- name: Update ${{ inputs.submodule-path }} to PR Commit
shell: bash
run: |
set -euo pipefail
REF='${{ inputs.caller-ref }}'
REPO='${{ inputs.caller-repo }}'
cd '${{ inputs.submodule-path }}'
git remote set-url origin "https://github.com/${REPO}.git"
git fetch origin "${REF}"
git checkout "${REF}"
echo "${{ inputs.submodule-path }} updated to $(git rev-parse HEAD)"
cd ..
- name: Stuart Update
shell: bash
run: |
stuart_update -c ${{ matrix.build_file }} \
TOOL_CHAIN_TAG=${{ env.TOOL_CHAIN_TAG }} \
-t ${{ env.BUILD_TARGET }}
- name: Update Commit Status - Build
# TODO: Requires microsoft org admin to accept permissions
# if: inputs.head-sha != ''
if: false
shell: bash
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
curl -sS -X POST \
-H "Authorization: Bearer $GH_TOKEN" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${{ github.repository }}/statuses/${{ inputs.head-sha }}" \
-d '{"state":"pending","description":"Building ${{ matrix.platform }}...","context":"Mu QEMU PR Validation","target_url":"https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"}'
- name: Build ${{ matrix.platform }}
id: build
shell: bash
run: |
stuart_build -c ${{ matrix.build_file }} \
TOOL_CHAIN_TAG=${{ env.TOOL_CHAIN_TAG }} \
TARGET=${{ env.BUILD_TARGET }}
- name: Update Commit Status - Boot
# TODO: Requires microsoft org admin to accept permissions
# if: inputs.head-sha != '' && steps.build.outcome == 'success'
if: false
shell: bash
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
curl -sS -X POST \
-H "Authorization: Bearer $GH_TOKEN" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${{ github.repository }}/statuses/${{ inputs.head-sha }}" \
-d '{"state":"pending","description":"Booting ${{ matrix.platform }}...","context":"Mu QEMU PR Validation","target_url":"https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"}'
- name: Record Boot Start Time
if: steps.build.outcome == 'success'
id: boot-start
shell: bash
run: echo "epoch=$(date +%s)" >> "$GITHUB_OUTPUT"
- name: Boot ${{ matrix.platform }} to EFI Shell
id: boot
if: steps.build.outcome == 'success'
shell: bash
run: |
stuart_build -c ${{ matrix.build_file }} \
TOOL_CHAIN_TAG=${{ env.TOOL_CHAIN_TAG }} \
TARGET=${{ env.BUILD_TARGET }} \
${{ matrix.run_flags }} \
--FlashOnly
timeout-minutes: 5
- name: Record Boot End Time
if: always() && steps.boot-start.outputs.epoch != ''
id: boot-end
shell: bash
run: echo "epoch=$(date +%s)" >> "$GITHUB_OUTPUT"
- name: Update Commit Status - Post-Boot
# TODO: Requires microsoft org admin to accept permissions
# if: always() && inputs.head-sha != ''
if: false
shell: bash
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
run: |
curl -sS -X POST \
-H "Authorization: Bearer $GH_TOKEN" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${{ github.repository }}/statuses/${{ inputs.head-sha }}" \
-d '{"state":"pending","description":"Post-boot (${{ matrix.platform }})...","context":"Mu QEMU PR Validation","target_url":"https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"}'
- name: Record Step Results
if: always()
shell: python3 {0}
env:
BOOT_END: ${{ steps.boot-end.outputs.epoch }}
BOOT_OUTCOME: ${{ steps.boot.outcome }}
BOOT_START: ${{ steps.boot-start.outputs.epoch }}
BOOT_TIMEOUT_SEC: '300'
BUILD_OUTCOME: ${{ steps.build.outcome }}
PLATFORM: ${{ matrix.platform }}
run: |
import json
import os
import pathlib
boot_start = os.environ.get('BOOT_START', '')
boot_end = os.environ.get('BOOT_END', '')
timeout_sec = int(os.environ.get('BOOT_TIMEOUT_SEC', '300'))
if boot_start and boot_end:
duration_s = int(boot_end) - int(boot_start)
minutes, seconds = divmod(duration_s, 60)
boot_duration = f'{minutes}m {seconds}s'
if duration_s >= timeout_sec:
boot_duration += ' (timed out)'
else:
boot_duration = 'N/A'
results = {
'platform': os.environ['PLATFORM'],
'build': os.environ.get('BUILD_OUTCOME', ''),
'boot': os.environ.get('BOOT_OUTCOME', ''),
'boot_duration': boot_duration,
}
output_dir = pathlib.Path('results')
output_dir.mkdir(exist_ok=True)
output_path = output_dir / f'{results["platform"]}.json'
output_path.write_text(json.dumps(results, indent=2), encoding='utf-8')
- name: Upload Step Results
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: mu-qemu-results-${{ matrix.platform }}
path: results/${{ matrix.platform }}.json
- name: Upload Build Logs
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: mu-qemu-build-logs-${{ matrix.platform }}
path: |
Build/**/BUILDLOG*Pkg.txt
if-no-files-found: warn
- name: Upload Boot Logs
if: always() && steps.build.outcome == 'success'
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: mu-qemu-boot-logs-${{ matrix.platform }}
path: |
Build/**/BUILDLOG*_Run.txt
if-no-files-found: warn
emit-pr-metadata:
name: Emit PR Metadata
runs-on: ubuntu-latest
needs: [build-and-boot]
if: always()
steps:
- name: Download Q35 Results
id: dl-q35
continue-on-error: true
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: mu-qemu-results-Q35
path: results
- name: Download ArmVirt Results
id: dl-armvirt
continue-on-error: true
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: mu-qemu-results-ArmVirt
path: results
- name: Write PR Metadata
shell: python3 {0}
env:
BUILD_BOOT_RESULT: ${{ needs.build-and-boot.result }}
CALLER_REF: ${{ inputs.caller-ref }}
CALLER_REPO_NAME: ${{ inputs.caller-repo-name }}
HEAD_SHA: ${{ inputs.head-sha }}
PR_NUMBER: ${{ inputs.pr-number }}
run: |
import json
import os
import pathlib
import subprocess
build_boot_result = os.environ['BUILD_BOOT_RESULT']
# Resolve mu_tiano_platforms HEAD commit (same ref used by the build job)
result = subprocess.run(
['git', 'ls-remote', 'https://github.com/microsoft/mu_tiano_platforms.git', 'HEAD'],
capture_output=True, text=True, check=True,
)
mu_tiano_platforms_sha = result.stdout.split()[0] if result.stdout.strip() else ''
# Aggregate per-platform results
platforms = {}
for p in ('Q35', 'ArmVirt'):
result_file = pathlib.Path(f'results/{p}.json')
if result_file.exists():
platforms[p] = json.loads(result_file.read_text(encoding='utf-8'))
else:
platforms[p] = {'platform': p, 'build': 'skipped', 'boot': 'skipped'}
metadata = {
'pr_number': int(os.environ['PR_NUMBER']),
'head_sha': os.environ['HEAD_SHA'],
'caller_ref': os.environ['CALLER_REF'],
'caller_repo_name': os.environ.get('CALLER_REPO_NAME', ''),
'mu_tiano_platforms_sha': mu_tiano_platforms_sha,
'platforms': platforms,
'validation': {
'build_and_boot_result': build_boot_result,
'failed': build_boot_result not in ('success', 'skipped'),
},
}
output_dir = pathlib.Path('metadata')
output_dir.mkdir(exist_ok=True)
output_path = output_dir / 'pr-metadata.json'
output_path.write_text(json.dumps(metadata, indent=2), encoding='utf-8')
- name: Upload PR Metadata Artifact
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: mu-qemu-pr-metadata
path: metadata/pr-metadata.json
if-no-files-found: error