-
Notifications
You must be signed in to change notification settings - Fork 0
96 lines (86 loc) · 3.61 KB
/
Copy pathon-demand-test.yml
File metadata and controls
96 lines (86 loc) · 3.61 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
name: on-demand image test
# Triggered by wslcontainers.com's /api/ask when a user asks about an image
# with no verified result yet. Runs a real wslc pull+run, then POSTs the
# outcome back to /api/ingest so the next lookup for the same image is
# verified instead of predicted.
on:
repository_dispatch:
types: [test-image]
jobs:
test:
runs-on: windows-2025
timeout-minutes: 15
steps:
- name: Install wslc
shell: pwsh
run: |
wsl --update --pre-release
wsl --version
- name: Validate image reference
id: validate
shell: pwsh
run: |
$ref = "${{ github.event.client_payload.image }}"
# Mirrors the regex /api/ask already applies before dispatching --
# re-checked here since this step is what actually shells out.
if ($ref -notmatch '^[a-z0-9][a-z0-9._/-]{0,120}(:[a-z0-9._-]{1,60})?$') {
Write-Error "Rejected image reference: $ref"
exit 1
}
echo "ref=$ref" >> $env:GITHUB_OUTPUT
- name: Test image
id: test
shell: pwsh
run: |
$ref = "${{ steps.validate.outputs.ref }}"
$wslc = 'C:\Program Files\WSL\wslc.exe'
$t0 = Get-Date
$pull = & $wslc image pull $ref 2>&1 | Out-String
$pullExit = $LASTEXITCODE
$pullTail = ($pull -split "`n" | Where-Object { $_.Trim() } | Select-Object -Last 1)
$runExit = $null; $runOk = $false; $runTail = 'skipped, pull failed'
if ($pullExit -eq 0) {
$run = & $wslc run --rm $ref /bin/sh -c 'echo PROBE_OK' 2>&1 | Out-String
$runExit = $LASTEXITCODE
$runOk = [bool]($run -match 'PROBE_OK')
$runTail = ($run -split "`n" | Where-Object { $_.Trim() } | Select-Object -Last 1)
}
$seconds = [math]::Round(((Get-Date) - $t0).TotalSeconds, 1)
$wslcVersion = (& $wslc version 2>&1 | Select-Object -First 1)
$payload = [ordered]@{
image = $ref
requestId = "${{ github.event.client_payload.requestId }}"
pullExit = $pullExit
runExit = $runExit
runOk = $runOk
pullTail = $pullTail
runTail = $runTail
seconds = $seconds
wslcVersion = $wslcVersion
testedAt = (Get-Date).ToUniversalTime().ToString('o')
}
$json = $payload | ConvertTo-Json -Compress
Write-Host $json
Set-Content -Path result.json -Value $json -Encoding utf8
# A "fails on wslc" outcome is a valid, expected result to collect and
# report -- it must not be conflated with this step erroring out.
# GitHub Actions appends `exit $LASTEXITCODE` after pwsh steps, and the
# last native call above (wslc version) would otherwise leave a stale
# non-zero code here that silently skips the report-back step below.
exit 0
- name: Report back to wslcontainers.com
if: always()
shell: pwsh
env:
INGEST_SECRET: ${{ secrets.INGEST_SECRET }}
run: |
if (-not (Test-Path result.json)) {
Write-Warning "result.json missing (test step likely crashed before writing it) -- nothing to report."
exit 0
}
$body = Get-Content result.json -Raw
Invoke-RestMethod -Uri 'https://wslcontainers.com/api/ingest' `
-Method Post `
-Headers @{ Authorization = "Bearer $env:INGEST_SECRET" } `
-ContentType 'application/json' `
-Body $body