Files
SubConverter-Extended/.github/actions/smoke-windows-artifact/action.yml
2026-05-25 17:22:47 +08:00

94 lines
3.6 KiB
YAML

name: Smoke test Windows portable artifact
description: Extract a Windows release artifact and verify that the HTTP endpoint responds.
inputs:
artifact:
description: Path to the zip artifact.
required: true
port:
description: Port used for the smoke test.
required: false
default: "25500"
runs:
using: composite
steps:
- name: Run artifact and check /version
shell: pwsh
run: |
$ErrorActionPreference = "Stop"
$artifact = "${{ inputs.artifact }}"
$port = "${{ inputs.port }}"
$workDir = Join-Path $env:RUNNER_TEMP ("subconverter-windows-" + [guid]::NewGuid().ToString("N"))
New-Item -ItemType Directory -Path $workDir | Out-Null
try {
Expand-Archive -Path $artifact -DestinationPath $workDir -Force
$root = Join-Path $workDir "SubConverter-Extended"
$pref = Join-Path $root "base\pref.toml"
$stdout = Join-Path $workDir "stdout.log"
$stderr = Join-Path $workDir "stderr.log"
Remove-Item (Join-Path $root "base\pref.toml") -ErrorAction SilentlyContinue
Remove-Item (Join-Path $root "base\pref.yml") -ErrorAction SilentlyContinue
Remove-Item (Join-Path $root "base\pref.ini") -ErrorAction SilentlyContinue
$previousPort = $env:PORT
$previousPath = $env:PATH
$env:PORT = $port
$env:PATH = "$root;$env:PATH"
$process = Start-Process `
-FilePath "pwsh" `
-ArgumentList @("-NoProfile", "-ExecutionPolicy", "Bypass", "-File", (Join-Path $root "start.ps1")) `
-WorkingDirectory $root `
-RedirectStandardOutput $stdout `
-RedirectStandardError $stderr `
-PassThru
$url = "http://127.0.0.1:$port/version"
$ok = $false
for ($i = 0; $i -lt 30; $i++) {
try {
$response = Invoke-WebRequest -UseBasicParsing -Uri $url -TimeoutSec 2
if ($response.StatusCode -eq 200) {
$response.Content.Substring(0, [Math]::Min(200, $response.Content.Length))
$ok = $true
break
}
} catch {
Start-Sleep -Seconds 1
}
if ($process.HasExited) {
break
}
}
if (-not $ok) {
Write-Host "stdout:"
if (Test-Path $stdout) { Get-Content $stdout -ErrorAction SilentlyContinue }
Write-Host "stderr:"
if (Test-Path $stderr) { Get-Content $stderr -ErrorAction SilentlyContinue }
throw "Windows artifact smoke test failed."
}
python "$env:GITHUB_WORKSPACE\scripts\run-subconverter-smoke.py" --base-url "http://127.0.0.1:$port"
if (-not (Test-Path $pref)) {
throw "Windows launcher did not create base\pref.toml on first start."
}
} finally {
if ($process -and -not $process.HasExited) {
$process.Kill()
$process.WaitForExit()
}
Get-CimInstance Win32_Process -Filter "name = 'subconverter.exe'" -ErrorAction SilentlyContinue |
Where-Object { $_.ExecutablePath -and $_.ExecutablePath.StartsWith($root, [System.StringComparison]::OrdinalIgnoreCase) } |
ForEach-Object { Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue }
if ($null -ne $previousPort) { $env:PORT = $previousPort } else { Remove-Item Env:PORT -ErrorAction SilentlyContinue }
if ($null -ne $previousPath) { $env:PATH = $previousPath }
Remove-Item -Recurse -Force $workDir -ErrorAction SilentlyContinue
}