Skip to content

Commit fa3afc1

Browse files
committed
Report Examples as job checks
Fork pull_request runs should stay unprivileged even when Examples statuses are required. The workflow now records the Examples result in the Windows build job and lets a tiny downstream Actions job publish the required check name automatically. Why: The old checks.create/update path cannot safely publish required Examples statuses for fork pull_request runs. Why: The reporter job fails closed when build-windows never reaches or never succeeds at the Examples step so required checks do not get stuck as Expected.
1 parent 6a60070 commit fa3afc1

1 file changed

Lines changed: 68 additions & 44 deletions

File tree

.github/workflows/build-nabla.yml

Lines changed: 68 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77

88
permissions:
99
contents: read
10-
checks: write
10+
actions: read
1111

1212
concurrency:
1313
group: push-lock-${{ github.ref }}
@@ -219,31 +219,14 @@ jobs:
219219
--profiling-format=google-trace
220220
221221
- name: Container – Build & Install Nabla
222+
id: build-nabla
222223
run: |
223224
docker exec orphan `
224225
${{ env.entry }} ${{ env.cmd }} -Command cmake --build `
225226
--preset ci-build-dynamic-${{ matrix.vendor }} `
226227
--target install `
227228
--config ${{ matrix.config }}
228229
229-
- name: API / Examples / Check Run (Create)
230-
id: check-run-create
231-
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
232-
uses: actions/github-script@v6
233-
with:
234-
github-token: ${{ secrets.GITHUB_TOKEN }}
235-
result-encoding: string
236-
script: |
237-
const headSha = context.payload.pull_request ? context.payload.pull_request.head.sha : context.sha;
238-
const response = await github.rest.checks.create({
239-
owner: context.repo.owner,
240-
repo: context.repo.repo,
241-
name: `Examples (${{ matrix.os }}, ${{ matrix.vendor }}-${{ matrix.tag }}, ${{ matrix.config }})`,
242-
head_sha: headSha,
243-
status: 'in_progress'
244-
});
245-
return response.data.id;
246-
247230
- name: Container – Build & Install Examples
248231
id: build-examples
249232
continue-on-error: true
@@ -259,35 +242,36 @@ jobs:
259242
${{ env.binary }}\examples_tests --config ${{ matrix.config }} `
260243
--prefix ${{ env.install }}
261244
262-
- name: API / Examples / Check Run (Conclusion)
263-
id: outcome-examples
245+
- name: Record Examples result
246+
if: ${{ always() }}
247+
shell: pwsh
264248
run: |
265-
$completedAt = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ")
266-
if ("${{ steps.build-examples.outcome }}" -eq "success") {
267-
"conclusion=success" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
249+
$examplesResult = if (
250+
"${{ steps.build-nabla.outcome }}" -eq "success" -and
251+
"${{ steps.build-examples.outcome }}" -eq "success"
252+
) {
253+
"success"
268254
} else {
269-
"conclusion=failure" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
255+
"failure"
270256
}
271-
"completed_at=$completedAt" | Out-File -FilePath $env:GITHUB_OUTPUT -Append
272-
273-
- name: API / Examples / Check Run (Update)
274-
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
275-
uses: actions/github-script@v6
257+
$statusDir = Join-Path $env:RUNNER_TEMP "examples-status"
258+
New-Item -ItemType Directory -Force -Path $statusDir | Out-Null
259+
$statusFile = Join-Path $statusDir "status.txt"
260+
$detailsFile = Join-Path $statusDir "details.txt"
261+
$examplesResult | Set-Content -Path $statusFile -Encoding ascii -NoNewline
262+
@(
263+
"build-nabla=${{ steps.build-nabla.outcome }}"
264+
"build-examples=${{ steps.build-examples.outcome }}"
265+
"result=$examplesResult"
266+
) | Set-Content -Path $detailsFile -Encoding ascii
267+
268+
- name: Upload Examples result
269+
if: ${{ always() }}
270+
uses: actions/upload-artifact@v4
276271
with:
277-
github-token: ${{ secrets.GITHUB_TOKEN }}
278-
script: |
279-
await github.rest.checks.update({
280-
owner: context.repo.owner,
281-
repo: context.repo.repo,
282-
check_run_id: ${{ steps.check-run-create.outputs.result }},
283-
status: 'completed',
284-
conclusion: '${{ steps.outcome-examples.outputs.conclusion }}',
285-
completed_at: '${{ steps.outcome-examples.outputs.completed_at }}',
286-
output: {
287-
title: '',
288-
summary: '[View logs](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) to see details.'
289-
}
290-
});
272+
name: examples-status-${{ matrix.os }}-${{ matrix.vendor }}-${{ matrix.tag }}-${{ matrix.config }}
273+
path: ${{ runner.temp }}/examples-status
274+
if-no-files-found: error
291275

292276
- name: Container – Save NSC Image
293277
run: |
@@ -438,6 +422,46 @@ jobs:
438422
run: |
439423
docker push ${{ steps.set-prefix.outputs.nscTargetTaggedImageLatest }}
440424
425+
examples-status:
426+
name: Examples (${{ matrix.os }}, ${{ matrix.vendor }}-${{ matrix.tag }}, ${{ matrix.config }})
427+
needs: build-windows
428+
if: ${{ always() }}
429+
runs-on: ubuntu-latest
430+
strategy:
431+
fail-fast: false
432+
matrix:
433+
vendor: [msvc]
434+
config: [Release, Debug, RelWithDebInfo]
435+
tag: ['17.13.6']
436+
os: [windows-2022]
437+
438+
steps:
439+
- name: Download Examples result
440+
uses: actions/download-artifact@v4
441+
with:
442+
name: examples-status-${{ matrix.os }}-${{ matrix.vendor }}-${{ matrix.tag }}-${{ matrix.config }}
443+
path: examples-status
444+
445+
- name: Fail if Examples did not succeed
446+
shell: bash
447+
run: |
448+
status_file="examples-status/status.txt"
449+
if [[ ! -f "$status_file" ]]; then
450+
echo "Missing Examples status artifact"
451+
exit 1
452+
fi
453+
454+
result="$(tr -d '\r\n' < "$status_file")"
455+
echo "Examples result: $result"
456+
457+
if [[ "$result" != "success" ]]; then
458+
if [[ -f "examples-status/details.txt" ]]; then
459+
echo "Details:"
460+
cat "examples-status/details.txt"
461+
fi
462+
exit 1
463+
fi
464+
441465
update-badges:
442466
name: Update Build & Image Badges
443467
if: ${{ always() && github.ref == 'refs/heads/master' }}

0 commit comments

Comments
 (0)