-
Notifications
You must be signed in to change notification settings - Fork 4.5k
680 lines (553 loc) · 19.8 KB
/
Copy pathinstall.yml
File metadata and controls
680 lines (553 loc) · 19.8 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
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
name: Installation
on:
workflow_call:
inputs:
name:
description: Display name for the Windows version
required: true
type: string
version:
description: VERSION value passed to the container
required: true
type: string
runner:
description: GitHub Actions runner
required: false
default: ubuntu-24.04
type: string
image:
description: Container image to test
required: false
default: ghcr.io/dockur/windows:latest
type: string
callback:
description: Guest script type
required: false
default: powershell
type: string
cpu:
description: CPU model exposed to Windows
required: false
default: host
type: string
expected_caption:
description: Text expected in the Windows caption
required: true
type: string
expected_edition:
description: Expected Windows EditionID
required: false
default: ""
type: string
minimum_build:
description: Minimum acceptable Windows build number
required: true
type: number
platform:
description: Expected Windows platform
required: true
type: string
permissions:
contents: read
jobs:
install:
name: ${{ inputs.name }}
runs-on: ${{ inputs.runner }}
timeout-minutes: 180
env:
CONTAINER: windows-test
IMAGE: ${{ inputs.image }}
steps:
- name: Check KVM
shell: bash
run: |
set -Eeuo pipefail
test -c /dev/kvm
- name: Free disk space
shell: bash
run: |
set -Eeuo pipefail
sudo rm -rf \
/usr/local/.ghcup \
/usr/local/lib/android \
/usr/local/lib/node_modules \
/usr/local/share/boost \
/usr/local/share/chromium \
/usr/local/share/powershell \
/usr/share/dotnet \
/usr/share/swift \
/opt/az \
/opt/ghc \
/opt/google \
/opt/hostedtoolcache \
/opt/microsoft \
/opt/pipx
sudo apt-get clean
sudo rm -rf \
/var/cache/apt/* \
/var/lib/apt/lists/*
docker system prune \
--all \
--force \
--volumes > /dev/null || true
available_kb="$(df --output=avail / | tail -1)"
available_gb="$((available_kb / 1024 / 1024))"
echo "Available disk space: ${available_gb} GB"
if (( available_gb < 40 )); then
echo "At least 40 GB of free space is required."
exit 1
fi
- name: Prepare installation test
id: test
shell: bash
env:
CALLBACK: ${{ inputs.callback }}
run: |
set -Eeuo pipefail
case "$CALLBACK" in
powershell | legacy)
;;
*)
echo "Unsupported guest script type: $CALLBACK"
exit 1
;;
esac
token="$(cat /proc/sys/kernel/random/uuid)"
mkdir -p \
"$RUNNER_TEMP/data" \
"$RUNNER_TEMP/oem" \
"$RUNNER_TEMP/storage"
printf '%s\n' "$token" > "$RUNNER_TEMP/data/readme.txt"
case "$CALLBACK" in
powershell)
cat > "$RUNNER_TEMP/oem/ready.ps1" <<'POWERSHELL'
param(
[Parameter(Mandatory = $true)]
[string]$Token
)
$ErrorActionPreference = "Stop"
$windows = Get-CimInstance Win32_OperatingSystem
$registry = Get-ItemProperty `
"HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion"
$platform = switch (
$env:PROCESSOR_ARCHITECTURE.ToUpperInvariant()
) {
"AMD64" {
"x64"
}
"ARM64" {
"arm64"
}
"X86" {
"x86"
}
default {
$env:PROCESSOR_ARCHITECTURE.ToLowerInvariant()
}
}
while ($true) {
try {
$share = (
Get-Content `
-LiteralPath "\\host.lan\Data\readme.txt" `
-Raw
).Trim()
$result = @{
token = $Token
caption = [string]$windows.Caption
edition = [string]$registry.EditionID
version = [string]$windows.Version
build = [string]$windows.BuildNumber
platform = $platform
share = $share
}
$json = $result | ConvertTo-Json -Compress
$temporary = "\\host.lan\Data\windows.tmp"
$destination = "\\host.lan\Data\windows.json"
$encoding = New-Object System.Text.UTF8Encoding($false)
[System.IO.File]::WriteAllText(
$temporary,
$json,
$encoding
)
Move-Item `
-LiteralPath $temporary `
-Destination $destination `
-Force
break
}
catch {
Start-Sleep -Seconds 10
}
}
POWERSHELL
cat > "$RUNNER_TEMP/oem/install.bat" <<EOF
@echo off
powershell.exe -NoProfile -ExecutionPolicy Bypass ^
-File C:\OEM\ready.ps1 ^
-Token "$token"
EOF
;;
legacy)
cat > "$RUNNER_TEMP/oem/ready.vbs" <<'VBSCRIPT'
Option Explicit
Const ForReading = 1
Const ForWriting = 2
Dim arguments
Dim token
Set arguments = WScript.Arguments
If arguments.Count < 1 Then
WScript.Quit 1
End If
token = arguments(0)
Function EscapeJson(value)
Dim result
result = CStr(value)
result = Replace(result, "\", "\\")
result = Replace(result, Chr(34), "\" & Chr(34))
result = Replace(result, vbCr, "\r")
result = Replace(result, vbLf, "\n")
result = Replace(result, vbTab, "\t")
EscapeJson = result
End Function
Function ReadRegistry(shell, path)
Dim value
value = ""
On Error Resume Next
value = shell.RegRead(path)
If Err.Number <> 0 Then
Err.Clear
value = ""
End If
On Error GoTo 0
ReadRegistry = CStr(value)
End Function
Function ReadTextFile(filesystem, path)
Dim file
Dim value
value = ""
Set file = filesystem.OpenTextFile(path, ForReading, False)
value = file.ReadAll
file.Close
value = Replace(value, vbCr, "")
value = Replace(value, vbLf, "")
ReadTextFile = value
End Function
Function GetPlatform(shell)
Dim architecture
architecture = UCase(shell.ExpandEnvironmentStrings("%PROCESSOR_ARCHITECTURE%"))
Select Case architecture
Case "AMD64"
GetPlatform = "x64"
Case "ARM64"
GetPlatform = "arm64"
Case "X86"
GetPlatform = "x86"
Case Else
GetPlatform = LCase(architecture)
End Select
End Function
Dim filesystem
Dim shell
Dim locator
Dim service
Dim systems
Dim system
Dim caption
Dim edition
Dim version
Dim build
Dim platform
Dim share
Dim json
Dim temporary
Dim destination
Dim file
Set filesystem = CreateObject("Scripting.FileSystemObject")
Set shell = CreateObject("WScript.Shell")
Set locator = CreateObject("WbemScripting.SWbemLocator")
Set service = locator.ConnectServer(".", "root\cimv2")
Set systems = service.ExecQuery("SELECT Caption, Version, BuildNumber FROM Win32_OperatingSystem")
caption = ""
version = ""
build = ""
For Each system In systems
caption = CStr(system.Caption)
version = CStr(system.Version)
build = CStr(system.BuildNumber)
Exit For
Next
edition = ReadRegistry(shell, "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\EditionID")
platform = GetPlatform(shell)
temporary = "\\host.lan\Data\windows.tmp"
destination = "\\host.lan\Data\windows.json"
Do
On Error Resume Next
share = ReadTextFile(filesystem, "\\host.lan\Data\readme.txt")
If Err.Number = 0 Then
json = _
"{" & _
"""token"":""" & EscapeJson(token) & """," & _
"""caption"":""" & EscapeJson(caption) & """," & _
"""edition"":""" & EscapeJson(edition) & """," & _
"""version"":""" & EscapeJson(version) & """," & _
"""build"":""" & EscapeJson(build) & """," & _
"""platform"":""" & EscapeJson(platform) & """," & _
"""share"":""" & EscapeJson(share) & """" & _
"}"
Set file = filesystem.OpenTextFile(temporary, ForWriting, True)
file.Write json
file.Close
If filesystem.FileExists(destination) Then
filesystem.DeleteFile destination, True
End If
filesystem.MoveFile temporary, destination
End If
If Err.Number = 0 Then
On Error GoTo 0
Exit Do
End If
Err.Clear
On Error GoTo 0
WScript.Sleep 10000
Loop
VBSCRIPT
cat > "$RUNNER_TEMP/oem/install.bat" <<EOF
@echo off
cscript.exe //B //NoLogo C:\OEM\ready.vbs "$token"
EOF
;;
esac
echo "token=$token" >> "$GITHUB_OUTPUT"
- name: Pull image
shell: bash
run: |
set -Eeuo pipefail
docker pull "$IMAGE"
docker image inspect "$IMAGE" \
--format 'Digest: {{index .RepoDigests 0}}'
- name: Install and validate Windows
shell: bash
env:
CPU: ${{ inputs.cpu }}
EXPECTED_TOKEN: ${{ steps.test.outputs.token }}
EXPECTED_CAPTION: ${{ inputs.expected_caption }}
EXPECTED_EDITION: ${{ inputs.expected_edition }}
EXPECTED_PLATFORM: ${{ inputs.platform }}
MINIMUM_BUILD: ${{ inputs.minimum_build }}
VERSION: ${{ inputs.version }}
DISPLAY_NAME: ${{ inputs.name }}
run: |
set -Eeuo pipefail
docker run --detach \
--name "$CONTAINER" \
--device /dev/kvm \
--device /dev/net/tun \
--cap-add NET_ADMIN \
--stop-timeout 120 \
--env "VERSION=$VERSION" \
--env "RAM_SIZE=half" \
--env "CPU_CORES=half" \
--env "CPU_MODEL=$CPU" \
--env "DISK_SIZE=64G" \
--volume "$RUNNER_TEMP/data:/shared" \
--volume "$RUNNER_TEMP/oem:/oem:ro" \
--volume "$RUNNER_TEMP/storage:/storage" \
"$IMAGE"
echo
echo "Container log:"
echo "------------------------------------------------------------"
docker logs \
--follow \
--timestamps \
"$CONTAINER" &
logs_pid="$!"
stop_logs() {
kill "$logs_pid" 2>/dev/null || true
wait "$logs_pid" 2>/dev/null || true
}
trap stop_logs EXIT
deadline=$((SECONDS + 9000))
reboot_timeout=1800
minimum_reboots=1
boot_loop_limit=5
first_bios_start=-1
while (( SECONDS < deadline )); do
state="$(
docker inspect \
--format '{{.State.Status}}' \
"$CONTAINER" 2>/dev/null || true
)"
if [[ "$state" != "running" ]]; then
echo
echo "------------------------------------------------------------"
echo "Container stopped before Windows became ready."
echo "Container state: ${state:-missing}"
exit 1
fi
container_log="$(docker logs "$CONTAINER" 2>&1 || true)"
if grep -Eqi \
'KVM internal error|KVM: entry failed|hardware error 0x[0-9a-f]+|Triple fault' \
<<< "$container_log"; then
echo
echo "------------------------------------------------------------"
echo "Detected a fatal QEMU or KVM error."
exit 1
fi
if grep -Eqi \
'CDBOOT: Cannot boot from CD.*Code: 5' \
<<< "$container_log"; then
echo
echo "------------------------------------------------------------"
echo "The installation media could not be booted."
exit 1
fi
bios_starts="$(
grep -Fci 'SeaBIOS (version ' <<< "$container_log" || true
)"
hard_disk_boots="$(
grep -Fci 'Booting from Hard Disk' <<< "$container_log" || true
)"
dvd_boots="$(
grep -Fci 'Booting from DVD/CD' <<< "$container_log" || true
)"
not_bootable_disk="$(
grep -Fci \
'Boot failed: not a bootable disk' \
<<< "$container_log" || true
)"
unreadable_boot_disk="$(
grep -Fci \
'Boot failed: could not read the boot disk' \
<<< "$container_log" || true
)"
no_bootable_device="$(
grep -Fci 'No bootable device.' <<< "$container_log" || true
)"
bootmgr_missing="$(
grep -Fci 'BOOTMGR is missing' <<< "$container_log" || true
)"
reboots=$((bios_starts > 0 ? bios_starts - 1 : 0))
if (( first_bios_start < 0 && bios_starts > 0 )); then
first_bios_start=$SECONDS
fi
if (( first_bios_start >= 0 &&
SECONDS - first_bios_start >= reboot_timeout &&
reboots < minimum_reboots )); then
echo
echo "------------------------------------------------------------"
echo "The installation did not reboot within" \
"$((reboot_timeout / 60)) minutes after the first BIOS start."
echo "Observed reboots: $reboots"
echo "Required reboots: $minimum_reboots"
exit 1
fi
if (( bios_starts >= boot_loop_limit )) &&
(( hard_disk_boots >= boot_loop_limit ||
dvd_boots >= boot_loop_limit ||
not_bootable_disk >= boot_loop_limit ||
unreadable_boot_disk >= boot_loop_limit ||
no_bootable_device >= boot_loop_limit ||
bootmgr_missing >= boot_loop_limit )); then
echo
echo "------------------------------------------------------------"
echo "Detected a repeated BIOS boot loop."
echo "SeaBIOS starts: $bios_starts"
echo "Hard disk boots: $hard_disk_boots"
echo "DVD boots: $dvd_boots"
echo "Not-bootable disk failures: $not_bootable_disk"
echo "Unreadable boot-disk failures: $unreadable_boot_disk"
echo "No-bootable-device failures: $no_bootable_device"
echo "BOOTMGR failures: $bootmgr_missing"
exit 1
fi
response=""
if [[ -s "$RUNNER_TEMP/data/windows.json" ]]; then
response="$(cat "$RUNNER_TEMP/data/windows.json")"
fi
if [[ -n "$response" ]]; then
stop_logs
trap - EXIT
echo
echo "------------------------------------------------------------"
echo "Received response:"
if ! jq . <<< "$response"; then
echo "$response"
echo "The guest returned invalid JSON."
exit 1
fi
token="$(jq -r '.token // empty' <<< "$response")"
caption="$(jq -r '.caption // empty' <<< "$response")"
edition="$(jq -r '.edition // empty' <<< "$response")"
version="$(jq -r '.version // empty' <<< "$response")"
build="$(jq -r '.build // empty' <<< "$response")"
platform="$(jq -r '.platform // empty' <<< "$response")"
share="$(jq -r '.share // empty' <<< "$response")"
if [[ "$token" != "$EXPECTED_TOKEN" ]]; then
echo "The response token does not match."
exit 1
fi
if [[ "$share" != "$EXPECTED_TOKEN" ]]; then
echo "Failed to read \\\\host.lan\\Data\\readme.txt."
echo "Expected contents:"
echo " $EXPECTED_TOKEN"
echo "Received:"
echo " ${share:-empty}"
exit 1
fi
normalized_caption="${caption//\(R\)/}"
normalized_expected_caption="${EXPECTED_CAPTION//\(R\)/}"
if [[ "$normalized_caption" != *"$normalized_expected_caption"* ]]; then
echo "Expected caption containing:"
echo " $EXPECTED_CAPTION"
echo "Received:"
echo " $caption"
exit 1
fi
normalized_edition="${edition%Eval}"
normalized_expected_edition="${EXPECTED_EDITION%Eval}"
if [[ -n "$EXPECTED_EDITION" &&
"$normalized_edition" != "$normalized_expected_edition" ]]; then
echo "Expected edition: $EXPECTED_EDITION"
echo "Received edition: $edition"
exit 1
fi
if [[ ! "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Unexpected Windows version: $version"
exit 1
fi
if [[ ! "$build" =~ ^[0-9]+$ ]]; then
echo "Invalid Windows build number: $build"
exit 1
fi
if (( build < MINIMUM_BUILD )); then
echo "Expected build $MINIMUM_BUILD or newer."
echo "Received build: $build"
exit 1
fi
if [[ "$platform" != "$EXPECTED_PLATFORM" ]]; then
echo "Expected platform:"
echo " $EXPECTED_PLATFORM"
echo "Received platform:"
echo " $platform"
exit 1
fi
echo
echo "$DISPLAY_NAME installed successfully."
echo "Version: $version"
echo "Build: $build"
echo "Platform: $platform"
echo "Shared file: accessible"
exit 0
fi
sleep 10
done
echo
echo "------------------------------------------------------------"
echo "Timed out waiting for Windows installation."
exit 1
- name: Cleanup
if: always()
shell: bash
run: |
docker rm --force "$CONTAINER" 2>/dev/null || true