Skip to content

Commit 6db7973

Browse files
committed
CI: factor windows-plain smoke test into a composite action
Both windows-plain-wsl2 and windows-plain-qemu duplicated the smoke test (create / start / shell / copy / stop / delete) and the on-failure log dump, differing only by the template path, the LIMA_HOME subdirectory, and (potentially) the instance name. Move both steps into .github/actions/windows_plain_smoke_test/action.yml with template, instance-name, and lima-home-suffix as inputs, and call it from both jobs. Each plain job is now ~10 lines of `uses:` plus the smoke test invocation, instead of ~60 lines of inlined PowerShell. Signed-off-by: Jan Dubois <jan.dubois@suse.com>
1 parent 54b13d9 commit 6db7973

3 files changed

Lines changed: 102 additions & 42 deletions

File tree

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: 'windows plain smoke test'
2+
description: >
3+
Runs Lima's create / start / shell / copy / stop / delete cycle against a
4+
given template on a plain Windows host. Each limactl invocation runs with
5+
--debug so traces land in the workflow log, and on failure the workflow
6+
dumps the instance's hostagent / serial logs so the run carries enough
7+
context to diagnose without re-running.
8+
inputs:
9+
template:
10+
description: Path to the Lima template (e.g. .\templates\experimental\wsl2.yaml).
11+
required: true
12+
instance-name:
13+
description: Name to use for the test instance.
14+
required: false
15+
default: plain
16+
lima-home-suffix:
17+
description: >
18+
Suffix appended to runner.temp for LIMA_HOME (e.g. "plain-wsl2"). Must be
19+
unique per job sharing a runner so concurrent jobs cannot collide.
20+
required: true
21+
vm-type:
22+
description: >
23+
Lima vmType to force via `--vm-type` (e.g. "qemu" or "wsl2"). When empty,
24+
`limactl create` auto-selects, which on Windows prefers wsl2 over qemu
25+
even when the template ships a disk image incompatible with wsl2.
26+
required: false
27+
default: ''
28+
runs:
29+
using: composite
30+
steps:
31+
- name: Smoke test (create / start / shell / copy / stop / delete)
32+
shell: pwsh
33+
env:
34+
LIMA_HOME: ${{ runner.temp }}\lima-${{ inputs.lima-home-suffix }}
35+
INSTANCE: ${{ inputs.instance-name }}
36+
TEMPLATE: ${{ inputs.template }}
37+
VM_TYPE: ${{ inputs.vm-type }}
38+
run: |
39+
$ErrorActionPreference = 'Stop'
40+
# $ErrorActionPreference does not propagate to native commands; wrap
41+
# limactl so a non-zero exit aborts the whole script instead of
42+
# silently continuing past the failure.
43+
function Invoke-Limactl {
44+
& .\_output\bin\limactl.exe --debug @args
45+
if ($LASTEXITCODE -ne 0) { throw "limactl $($args -join ' ') exited $LASTEXITCODE" }
46+
}
47+
if (Test-Path $env:LIMA_HOME) { Remove-Item $env:LIMA_HOME -Recurse -Force }
48+
New-Item -ItemType Directory -Path $env:LIMA_HOME | Out-Null
49+
$createArgs = @('--tty=false', "--name=$env:INSTANCE")
50+
if ($env:VM_TYPE) { $createArgs += "--vm-type=$env:VM_TYPE" }
51+
$createArgs += $env:TEMPLATE
52+
Invoke-Limactl create @createArgs
53+
Invoke-Limactl start $env:INSTANCE
54+
Invoke-Limactl shell --tty=false $env:INSTANCE -- uname -srm
55+
'roundtrip' | Out-File -Encoding ascii "$env:LIMA_HOME\rt.txt"
56+
Invoke-Limactl copy "$env:LIMA_HOME\rt.txt" "${env:INSTANCE}:/tmp/rt.txt"
57+
Invoke-Limactl shell --tty=false $env:INSTANCE -- cat /tmp/rt.txt
58+
# Cover the guest -> host direction too: it runs through different
59+
# parseCopyPaths plumbing than the upload above.
60+
Invoke-Limactl copy "${env:INSTANCE}:/tmp/rt.txt" "$env:LIMA_HOME\rt-back.txt"
61+
$back = (Get-Content "$env:LIMA_HOME\rt-back.txt" -Raw).Trim()
62+
if ($back -ne 'roundtrip') {
63+
throw "round-trip mismatch: expected 'roundtrip', got '$back'"
64+
}
65+
Invoke-Limactl stop $env:INSTANCE
66+
Invoke-Limactl delete --force $env:INSTANCE
67+
68+
- name: Dump Lima logs on failure
69+
if: failure()
70+
shell: pwsh
71+
env:
72+
LIMA_HOME: ${{ runner.temp }}\lima-${{ inputs.lima-home-suffix }}
73+
INSTANCE: ${{ inputs.instance-name }}
74+
run: |
75+
$instDir = Join-Path $env:LIMA_HOME $env:INSTANCE
76+
if (-not (Test-Path $instDir)) {
77+
Write-Host "No instance directory at $instDir, nothing to dump."
78+
exit 0
79+
}
80+
Get-ChildItem $instDir | Format-Table Name, Length, LastWriteTime
81+
foreach ($name in 'ha.stdout.log','ha.stderr.log','serial.log','lima.yaml','ssh.config') {
82+
$p = Join-Path $instDir $name
83+
if (Test-Path $p) {
84+
Write-Host ("===== {0} =====" -f $p)
85+
Get-Content $p
86+
}
87+
}

.github/actions/windows_plain_templates/action.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ runs:
2828
Copy-Item -Path "$srcRoot\*" -Destination $dstRoot -Recurse -Force
2929
3030
$linkTargets = @{}
31-
foreach ($line in (git ls-tree -r HEAD $srcRoot)) {
31+
# Capture before iterating: a partial-output failure of `git ls-tree`
32+
# would let the foreach run on truncated data, and the later
33+
# `git cat-file` calls would overwrite $LASTEXITCODE before any
34+
# check could see the original failure.
35+
$lsTreeOutput = git ls-tree -r HEAD $srcRoot
36+
if ($LASTEXITCODE -ne 0) { throw "git ls-tree failed: $LASTEXITCODE" }
37+
foreach ($line in $lsTreeOutput) {
3238
if ($line -notmatch '^120000\s') { continue }
3339
$parts = $line -split "`t", 2
3440
$sha = ($parts[0] -split '\s+')[2]
@@ -37,7 +43,6 @@ runs:
3743
if ($LASTEXITCODE -ne 0) { throw "git cat-file $sha failed: $LASTEXITCODE" }
3844
$linkTargets[$posixPath] = $target
3945
}
40-
if ($LASTEXITCODE -ne 0) { throw "git ls-tree failed: $LASTEXITCODE" }
4146
4247
foreach ($posixPath in $linkTargets.Keys) {
4348
$resolved = $posixPath

.github/workflows/test.yml

Lines changed: 8 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -245,46 +245,10 @@ jobs:
245245
- uses: ./.github/actions/windows_wsl2_setup
246246
- uses: ./.github/actions/windows_plain_host
247247
- uses: ./.github/actions/windows_plain_build
248-
- name: Smoke test (create / start / shell / copy / stop / delete)
249-
env:
250-
LIMA_HOME: ${{ runner.temp }}\lima-plain-wsl2
251-
run: |
252-
$ErrorActionPreference = 'Stop'
253-
# Wrap each limactl invocation so a non-zero exit aborts the whole
254-
# script. Without this, $ErrorActionPreference does not catch native
255-
# command failures and the script silently continues past errors.
256-
function Invoke-Limactl {
257-
& .\_output\bin\limactl.exe --debug @args
258-
if ($LASTEXITCODE -ne 0) { throw "limactl $($args -join ' ') exited $LASTEXITCODE" }
259-
}
260-
if (Test-Path $env:LIMA_HOME) { Remove-Item $env:LIMA_HOME -Recurse -Force }
261-
New-Item -ItemType Directory -Path $env:LIMA_HOME | Out-Null
262-
Invoke-Limactl create --tty=false --name=plain .\templates\experimental\wsl2.yaml
263-
Invoke-Limactl start plain
264-
Invoke-Limactl shell --tty=false plain -- uname -srm
265-
'roundtrip' | Out-File -Encoding ascii "$env:LIMA_HOME\rt.txt"
266-
Invoke-Limactl copy "$env:LIMA_HOME\rt.txt" plain:/tmp/rt.txt
267-
Invoke-Limactl shell --tty=false plain -- cat /tmp/rt.txt
268-
Invoke-Limactl stop plain
269-
Invoke-Limactl delete --force plain
270-
- name: Dump Lima logs on failure
271-
if: failure()
272-
env:
273-
LIMA_HOME: ${{ runner.temp }}\lima-plain-wsl2
274-
run: |
275-
$instDir = "$env:LIMA_HOME\plain"
276-
if (-not (Test-Path $instDir)) {
277-
Write-Host "No instance directory at $instDir, nothing to dump."
278-
exit 0
279-
}
280-
Get-ChildItem $instDir | Format-Table Name, Length, LastWriteTime
281-
foreach ($name in 'ha.stdout.log','ha.stderr.log','serial.log','lima.yaml','ssh.config') {
282-
$p = Join-Path $instDir $name
283-
if (Test-Path $p) {
284-
Write-Host ("===== {0} =====" -f $p)
285-
Get-Content $p
286-
}
287-
}
248+
- uses: ./.github/actions/windows_plain_smoke_test
249+
with:
250+
template: .\templates\experimental\wsl2.yaml
251+
lima-home-suffix: plain-wsl2
288252

289253
windows-plain-qemu:
290254
# Same shape as windows-plain-wsl2 but exercises the QEMU driver. Covers
@@ -324,6 +288,10 @@ jobs:
324288
with:
325289
template: .\templates\default.yaml
326290
lima-home-suffix: plain-qemu
291+
# Force qemu: on Windows, `limactl create` auto-selects wsl2
292+
# over qemu, and templates/default.yaml ships a cloud disk
293+
# image that the wsl2 driver rejects.
294+
vm-type: qemu
327295

328296
qemu:
329297
name: "Integration tests (QEMU, macOS host)"

0 commit comments

Comments
 (0)