Open History to see the last commit
1param(
2 [string[]]$Distros = @("Ubuntu-24.04", "Debian")
3)
4
5$ErrorActionPreference = "Stop"
6Set-StrictMode -Version Latest
7
8function Invoke-WslChecked {
9 param(
10 [Parameter(Mandatory = $true)][string[]]$Arguments,
11 [string]$Description = "wsl.exe command"
12 )
13
14 & wsl.exe @Arguments
15 if ($LASTEXITCODE -ne 0) {
16 throw "$Description failed with exit code ${LASTEXITCODE}: wsl.exe $($Arguments -join ' ')"
17 }
18}
19
20function Get-InstalledWslDistros {
21 $output = & wsl.exe --list --quiet
22 if ($LASTEXITCODE -ne 0) {
23 throw "wsl.exe --list --quiet failed with exit code $LASTEXITCODE"
24 }
25 return @($output | ForEach-Object { $_.Trim().Trim([char]0) } | Where-Object { $_ })
26}
27
28Write-Host "=== WSL runtime ==="
29Invoke-WslChecked -Arguments @("--version") -Description "WSL version probe"
30Invoke-WslChecked -Arguments @("--set-default-version", "2") -Description "WSL2 default selection"
31
32foreach ($distro in $Distros) {
33 $installed = Get-InstalledWslDistros
34 if ($installed -notcontains $distro) {
35 Write-Host "Installing $distro as a real WSL2 integration target..."
36 Invoke-WslChecked -Arguments @(
37 "--install",
38 "--distribution", $distro,
39 "--no-launch",
40 "--web-download"
41 ) -Description "WSL distro install ($distro)"
42 }
43
44 # Initialize the distro as root to avoid interactive first-user setup on CI.
45 Invoke-WslChecked -Arguments @(
46 "--distribution", $distro,
47 "--user", "root",
48 "--",
49 "/bin/sh", "-lc", "true"
50 ) -Description "WSL distro initialization ($distro)"
51
52 Invoke-WslChecked -Arguments @("--set-version", $distro, "2") -Description "WSL2 enforcement ($distro)"
53
54 # The cross-distro native smoke uses readelf for diagnostics. Install only
55 # that CI inspection tool; deliberately do not install Node.js or compilers.
56 Invoke-WslChecked -Arguments @(
57 "--distribution", $distro,
58 "--user", "root",
59 "--",
60 "/bin/sh", "-lc",
61 "apt-get update >/dev/null && DEBIAN_FRONTEND=noninteractive apt-get install -y binutils >/dev/null"
62 ) -Description "WSL CI inspection tooling ($distro)"
63
64 # Exercise the same non-root cache and process semantics as a normal desktop
65 # user. Store-installed CI distros are initialized as root above to avoid an
66 # interactive OOBE, so explicitly create and pin a normal default user.
67 Invoke-WslChecked -Arguments @(
68 "--distribution", $distro,
69 "--user", "root",
70 "--",
71 "/bin/sh", "-lc",
72 'id -u t3ci >/dev/null 2>&1 || useradd -m -s /bin/bash t3ci; printf "[user]\ndefault=t3ci\n" > /etc/wsl.conf'
73 ) -Description "WSL non-root CI user setup ($distro)"
74 Invoke-WslChecked -Arguments @("--terminate", $distro) -Description "WSL distro restart ($distro)"
75 $defaultUser = (& wsl.exe --distribution $distro -- /bin/sh -lc "id -un" | Out-String).Trim()
76 if ($LASTEXITCODE -ne 0 -or $defaultUser -ne "t3ci") {
77 throw "Expected $distro to restart as non-root user t3ci, got '$defaultUser'"
78 }
79
80 Write-Host "=== $distro runtime identity ==="
81 Invoke-WslChecked -Arguments @(
82 "--distribution", $distro,
83 "--user", "root",
84 "--",
85 "/bin/sh", "-lc", 'printf "distro=%s\n" "$(. /etc/os-release && printf "%s %s" "$ID" "$VERSION_ID")"; printf "arch=%s\n" "$(uname -m)"; printf "libc=%s\n" "$(getconf GNU_LIBC_VERSION 2>/dev/null || true)"'
86 ) -Description "WSL distro identity probe ($distro)"
87}
88
89# Deliberately make the second distro the Windows default. The integration test
90# still targets each concrete distro explicitly, catching regressions where
91# `wsl:default` is accidentally re-resolved after backend selection.
92if ($Distros.Count -gt 1) {
93 Invoke-WslChecked -Arguments @("--set-default", $Distros[1]) -Description "WSL default-distro drift setup"
94}
95
96Write-Host "=== Installed WSL distros ==="
97Invoke-WslChecked -Arguments @("--list", "--verbose") -Description "WSL distro inventory"
98
99if ($env:GITHUB_ENV) {
100 "T3CODE_WSL_INTEGRATION=1" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
101 "T3CODE_WSL_TEST_DISTROS=$($Distros -join ',')" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
102 if ($Distros.Count -gt 1) {
103 "T3CODE_WSL_EXPECTED_DEFAULT_DISTRO=$($Distros[1])" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
104 }
105}