ci: add fresh install package smoke test
Windows Package CI / package-fresh-install (push) Waiting to run
Windows Package CI / package-fresh-install (push) Waiting to run
This commit is contained in:
1 parent
f5a77867ee
commit
7745f9a57f
4 files changed
+436
No files matched your search
@@ -0,0 +1,87 @@
|
||||
name: Windows Package CI
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches: [main]
|
||||
paths:
|
||||
- "bin/**"
|
||||
- "douyin/**"
|
||||
- "gui/**"
|
||||
- "operations/**"
|
||||
- "packaging/**"
|
||||
- "tools/**"
|
||||
- "tests/**"
|
||||
- "webui/**"
|
||||
- "pyproject.toml"
|
||||
- "requirements.txt"
|
||||
- ".github/workflows/windows-package-ci.yml"
|
||||
|
||||
jobs:
|
||||
package-fresh-install:
|
||||
runs-on: windows-latest
|
||||
timeout-minutes: 90
|
||||
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: "3.12"
|
||||
cache: "pip"
|
||||
|
||||
- name: Install Inno Setup
|
||||
shell: powershell
|
||||
run: choco install innosetup --yes --no-progress
|
||||
|
||||
- name: Install Python dependencies
|
||||
shell: powershell
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
python -m pip install -r requirements.txt
|
||||
python -m pip install pyinstaller cython setuptools wheel
|
||||
|
||||
- name: Run fast regression tests
|
||||
shell: powershell
|
||||
run: >
|
||||
python -m pytest
|
||||
tests/test_web_gui_routes_logic.py
|
||||
tests/test_startup_update_bootstrap.py
|
||||
tests/test_distribution_manifest.py
|
||||
tests/test_exe_packing.py
|
||||
tests/test_auto_update.py
|
||||
tests/test_version_consistency.py
|
||||
tests/test_tools_dev.py
|
||||
tests/test_ci_fresh_install.py
|
||||
|
||||
- name: Build portable package
|
||||
shell: powershell
|
||||
run: powershell -NoProfile -ExecutionPolicy Bypass -File packaging\pyinstaller\build_windows.ps1 -SkipInstall -ReuseCache
|
||||
|
||||
- name: Build installer
|
||||
shell: powershell
|
||||
run: |
|
||||
$version = python -c "from douyin.core.version import APP_VERSION; print(str(APP_VERSION).lstrip('Vv'))"
|
||||
$iscc = @(
|
||||
"${env:ProgramFiles(x86)}\Inno Setup 6\ISCC.exe",
|
||||
"${env:ProgramFiles}\Inno Setup 6\ISCC.exe",
|
||||
"${env:LOCALAPPDATA}\Programs\Inno Setup 6\ISCC.exe"
|
||||
) | Where-Object { Test-Path $_ } | Select-Object -First 1
|
||||
if (-not $iscc) { throw "ISCC.exe not found" }
|
||||
& $iscc packaging\inno\douyin_guaji.iss /DMyAppVersion=$version
|
||||
|
||||
- name: Fresh install smoke test
|
||||
shell: powershell
|
||||
run: powershell -NoProfile -ExecutionPolicy Bypass -File tools\ci\fresh_install_smoke.ps1
|
||||
|
||||
- name: Upload package and smoke report
|
||||
uses: actions/upload-artifact@v4
|
||||
if: always()
|
||||
with:
|
||||
name: douyin-guaji-windows-package
|
||||
path: |
|
||||
dist/installer/*.exe
|
||||
artifacts/fresh_install_ci/**
|
||||
if-no-files-found: ignore
|
||||
@@ -94,6 +94,22 @@ iscc packaging\inno\douyin_guaji.iss /DMyAppVersion=3.3.3
|
||||
dist\installer\DouyinGuaji-3.3.3-Setup.exe
|
||||
```
|
||||
|
||||
## 从零安装验收
|
||||
|
||||
打完便携包和安装包后,运行:
|
||||
|
||||
```powershell
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -File tools\ci\fresh_install_smoke.ps1
|
||||
```
|
||||
|
||||
脚本会静默安装到 `artifacts\fresh_install_ci\DouyinGuajiApp`,并检查默认配置、随包 ADB、ADBKeyboard、WebGUI 首次卡密门禁、未授权运行接口拦截、Dashboard 首次启动不闪退。
|
||||
|
||||
验收报告:
|
||||
|
||||
```text
|
||||
artifacts\fresh_install_ci\fresh_install_report.json
|
||||
```
|
||||
|
||||
## 发给别人前检查
|
||||
|
||||
- 打包脚本会自动运行 `python -m tools.distribution_manifest dist\DouyinGuaji-<version>`,防止源码、调试产物、个人配置和旧日志混入分发目录。
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def test_fresh_install_smoke_script_covers_new_machine_contract():
|
||||
script = Path("tools/ci/fresh_install_smoke.ps1").read_text(encoding="utf-8")
|
||||
|
||||
assert "tools.distribution_manifest" in script
|
||||
assert "tools.exe_packing" in script
|
||||
assert "Start-Process -FilePath $Installer" in script
|
||||
assert "config\\config.json" in script
|
||||
assert "platform-tools\\adb.exe" in script
|
||||
assert "android-tools\\ADBKeyboard.apk" in script
|
||||
assert "adb.exe\") `\n -Arguments @(\"version\")" in script
|
||||
assert "run_cli.exe\") `\n -Arguments @(\"--help\")" in script
|
||||
assert "cli_fails_closed_without_license" in script
|
||||
assert "web_gui.exe" in script
|
||||
assert "license-form" in script
|
||||
assert "license-input" in script
|
||||
assert "/api/license" in script
|
||||
assert "/api/start-run" in script
|
||||
assert "license_required" in script
|
||||
assert "DouyinGuajiGUI.exe" in script
|
||||
assert "fresh_install_report.json" in script
|
||||
assert "DOUYIN_DISABLE_AUTO_UPDATE" in script
|
||||
assert "Assert-UnderDirectory $WorkRoot $ArtifactsRoot" in script
|
||||
|
||||
|
||||
def test_windows_package_ci_builds_installer_then_runs_fresh_install_smoke():
|
||||
workflow = Path(".github/workflows/windows-package-ci.yml").read_text(encoding="utf-8")
|
||||
|
||||
assert "runs-on: windows-latest" in workflow
|
||||
assert "choco install innosetup" in workflow
|
||||
assert "packaging\\pyinstaller\\build_windows.ps1 -SkipInstall -ReuseCache" in workflow
|
||||
assert "packaging\\inno\\douyin_guaji.iss" in workflow
|
||||
assert "tools\\ci\\fresh_install_smoke.ps1" in workflow
|
||||
assert "actions/upload-artifact@v4" in workflow
|
||||
@@ -0,0 +1,295 @@
|
||||
param(
|
||||
[string]$Version = "",
|
||||
[string]$DistDir = "",
|
||||
[string]$Installer = "",
|
||||
[string]$WorkRoot = "",
|
||||
[int]$WebPort = 18080,
|
||||
[int]$WebStartupTimeoutSeconds = 45,
|
||||
[int]$DashboardStartupSeconds = 8
|
||||
)
|
||||
|
||||
$ErrorActionPreference = "Stop"
|
||||
|
||||
function Resolve-FullPath([string]$PathText) {
|
||||
if ([System.IO.Path]::IsPathRooted($PathText)) {
|
||||
return [System.IO.Path]::GetFullPath($PathText)
|
||||
}
|
||||
return [System.IO.Path]::GetFullPath((Join-Path $Root $PathText))
|
||||
}
|
||||
|
||||
function Assert-UnderDirectory([string]$Child, [string]$Parent, [string]$Label) {
|
||||
$childFull = [System.IO.Path]::GetFullPath($Child).TrimEnd('\', '/')
|
||||
$parentFull = [System.IO.Path]::GetFullPath($Parent).TrimEnd('\', '/')
|
||||
if (-not $childFull.StartsWith($parentFull, [System.StringComparison]::OrdinalIgnoreCase)) {
|
||||
throw "$Label must be under $parentFull, got $childFull"
|
||||
}
|
||||
}
|
||||
|
||||
function Assert-FileExists([string]$PathText, [string]$Label) {
|
||||
if (-not (Test-Path -LiteralPath $PathText -PathType Leaf)) {
|
||||
throw "Missing $Label`: $PathText"
|
||||
}
|
||||
}
|
||||
|
||||
function Assert-DirExists([string]$PathText, [string]$Label) {
|
||||
if (-not (Test-Path -LiteralPath $PathText -PathType Container)) {
|
||||
throw "Missing $Label`: $PathText"
|
||||
}
|
||||
}
|
||||
|
||||
function ConvertTo-ProcessArgument([string]$Arg) {
|
||||
if ($Arg -notmatch '[\s"]') {
|
||||
return $Arg
|
||||
}
|
||||
return '"' + ($Arg -replace '\\(?=\\*")', '$0$0' -replace '"', '\"') + '"'
|
||||
}
|
||||
|
||||
function Invoke-CheckedProcess([string]$FilePath, [string[]]$Arguments, [string]$Label, [string]$WorkingDirectory = "") {
|
||||
$psi = New-Object System.Diagnostics.ProcessStartInfo
|
||||
$psi.FileName = $FilePath
|
||||
$psi.Arguments = (($Arguments | ForEach-Object { ConvertTo-ProcessArgument $_ }) -join " ")
|
||||
if ($WorkingDirectory) {
|
||||
$psi.WorkingDirectory = $WorkingDirectory
|
||||
}
|
||||
$psi.UseShellExecute = $false
|
||||
$psi.RedirectStandardOutput = $true
|
||||
$psi.RedirectStandardError = $true
|
||||
$proc = [System.Diagnostics.Process]::Start($psi)
|
||||
$stdout = $proc.StandardOutput.ReadToEnd()
|
||||
$stderr = $proc.StandardError.ReadToEnd()
|
||||
$proc.WaitForExit()
|
||||
if ($proc.ExitCode -ne 0) {
|
||||
$detail = (($stderr + " " + $stdout) -replace "\s+", " ").Trim()
|
||||
throw "$Label failed with exit code $($proc.ExitCode): $detail"
|
||||
}
|
||||
return $stdout
|
||||
}
|
||||
|
||||
function Invoke-ProcessCapture([string]$FilePath, [string[]]$Arguments, [string]$WorkingDirectory = "") {
|
||||
$psi = New-Object System.Diagnostics.ProcessStartInfo
|
||||
$psi.FileName = $FilePath
|
||||
$psi.Arguments = (($Arguments | ForEach-Object { ConvertTo-ProcessArgument $_ }) -join " ")
|
||||
if ($WorkingDirectory) {
|
||||
$psi.WorkingDirectory = $WorkingDirectory
|
||||
}
|
||||
$psi.UseShellExecute = $false
|
||||
$psi.RedirectStandardOutput = $true
|
||||
$psi.RedirectStandardError = $true
|
||||
$proc = [System.Diagnostics.Process]::Start($psi)
|
||||
$stdout = $proc.StandardOutput.ReadToEnd()
|
||||
$stderr = $proc.StandardError.ReadToEnd()
|
||||
$proc.WaitForExit()
|
||||
return [pscustomobject]@{
|
||||
ExitCode = $proc.ExitCode
|
||||
Stdout = $stdout
|
||||
Stderr = $stderr
|
||||
}
|
||||
}
|
||||
|
||||
$Root = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot "..\.."))
|
||||
Set-Location $Root
|
||||
|
||||
if (-not $Version) {
|
||||
$Version = (python -c "from douyin.core.version import APP_VERSION; print(str(APP_VERSION).lstrip('Vv'))").Trim()
|
||||
}
|
||||
if (-not $DistDir) {
|
||||
$DistDir = Join-Path $Root "dist\DouyinGuaji-$Version"
|
||||
}
|
||||
if (-not $Installer) {
|
||||
$Installer = Join-Path $Root "dist\installer\DouyinGuaji-$Version-Setup.exe"
|
||||
}
|
||||
if (-not $WorkRoot) {
|
||||
$WorkRoot = Join-Path $Root "artifacts\fresh_install_ci"
|
||||
}
|
||||
|
||||
$DistDir = Resolve-FullPath $DistDir
|
||||
$Installer = Resolve-FullPath $Installer
|
||||
$WorkRoot = Resolve-FullPath $WorkRoot
|
||||
$ArtifactsRoot = Resolve-FullPath "artifacts"
|
||||
Assert-UnderDirectory $WorkRoot $ArtifactsRoot "WorkRoot"
|
||||
|
||||
Assert-DirExists $DistDir "portable dist"
|
||||
Assert-FileExists $Installer "installer"
|
||||
|
||||
python -m tools.distribution_manifest $DistDir
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "distribution manifest check failed"
|
||||
}
|
||||
|
||||
python -m tools.exe_packing $DistDir --smoke-only
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
throw "exe smoke check failed"
|
||||
}
|
||||
|
||||
if (Test-Path -LiteralPath $WorkRoot) {
|
||||
Remove-Item -LiteralPath $WorkRoot -Recurse -Force
|
||||
}
|
||||
New-Item -ItemType Directory -Force $WorkRoot | Out-Null
|
||||
|
||||
$InstallDir = Join-Path $WorkRoot "DouyinGuajiApp"
|
||||
$InstallLog = Join-Path $WorkRoot "install.log"
|
||||
$InstallerHash = (Get-FileHash -LiteralPath $Installer -Algorithm SHA256).Hash
|
||||
$InstallArgs = @(
|
||||
"/VERYSILENT",
|
||||
"/SUPPRESSMSGBOXES",
|
||||
"/NORESTART",
|
||||
"/DIR=$InstallDir",
|
||||
"/LOG=$InstallLog"
|
||||
)
|
||||
$installProc = Start-Process -FilePath $Installer -ArgumentList $InstallArgs -Wait -PassThru
|
||||
if ($installProc.ExitCode -ne 0) {
|
||||
throw "installer exited with code $($installProc.ExitCode); log=$InstallLog"
|
||||
}
|
||||
|
||||
Assert-DirExists $InstallDir "installed app"
|
||||
Assert-FileExists (Join-Path $InstallDir "DouyinGuajiGUI.exe") "dashboard exe"
|
||||
Assert-FileExists (Join-Path $InstallDir "web_gui.exe") "web gui exe"
|
||||
Assert-FileExists (Join-Path $InstallDir "run_cli.exe") "cli exe"
|
||||
Assert-FileExists (Join-Path $InstallDir "config\config.json") "default runtime config"
|
||||
Assert-FileExists (Join-Path $InstallDir "platform-tools\adb.exe") "bundled adb"
|
||||
Assert-FileExists (Join-Path $InstallDir "platform-tools\AdbWinApi.dll") "ADB Win API"
|
||||
Assert-FileExists (Join-Path $InstallDir "platform-tools\AdbWinUsbApi.dll") "ADB USB API"
|
||||
Assert-FileExists (Join-Path $InstallDir "android-tools\ADBKeyboard.apk") "ADBKeyboard helper"
|
||||
|
||||
$adbVersion = Invoke-CheckedProcess `
|
||||
-FilePath (Join-Path $InstallDir "platform-tools\adb.exe") `
|
||||
-Arguments @("version") `
|
||||
-Label "bundled adb version" `
|
||||
-WorkingDirectory $InstallDir
|
||||
|
||||
$cliProbe = Invoke-ProcessCapture `
|
||||
-FilePath (Join-Path $InstallDir "run_cli.exe") `
|
||||
-Arguments @("--help") `
|
||||
-WorkingDirectory $InstallDir
|
||||
if ($cliProbe.ExitCode -ne 86 -or (($cliProbe.Stdout + $cliProbe.Stderr) -notmatch "missing|缺少")) {
|
||||
throw "run_cli --help should fail closed without license, got exit=$($cliProbe.ExitCode)"
|
||||
}
|
||||
|
||||
$licensePath = Join-Path $InstallDir "license.dat"
|
||||
if (Test-Path -LiteralPath $licensePath) {
|
||||
throw "fresh install unexpectedly contains license.dat"
|
||||
}
|
||||
|
||||
$webLog = Join-Path $WorkRoot "web_gui.stdout.log"
|
||||
$webErr = Join-Path $WorkRoot "web_gui.stderr.log"
|
||||
$oldPort = $env:PORT
|
||||
$oldDisableUpdate = $env:DOUYIN_DISABLE_AUTO_UPDATE
|
||||
$oldLicenseRequired = $env:DOUYIN_LICENSE_REQUIRED
|
||||
$oldSkipOcr = $env:SKIP_OCR_INIT
|
||||
$webProc = $null
|
||||
try {
|
||||
$env:PORT = [string]$WebPort
|
||||
$env:DOUYIN_DISABLE_AUTO_UPDATE = "1"
|
||||
$env:DOUYIN_LICENSE_REQUIRED = "1"
|
||||
$env:SKIP_OCR_INIT = "1"
|
||||
$webProc = Start-Process `
|
||||
-FilePath (Join-Path $InstallDir "web_gui.exe") `
|
||||
-WorkingDirectory $InstallDir `
|
||||
-RedirectStandardOutput $webLog `
|
||||
-RedirectStandardError $webErr `
|
||||
-WindowStyle Hidden `
|
||||
-PassThru
|
||||
|
||||
$rootResponse = $null
|
||||
$deadline = (Get-Date).AddSeconds($WebStartupTimeoutSeconds)
|
||||
while ((Get-Date) -lt $deadline) {
|
||||
if ($webProc.HasExited) {
|
||||
throw "web_gui exited early with code $($webProc.ExitCode); stdout=$webLog stderr=$webErr"
|
||||
}
|
||||
try {
|
||||
$rootResponse = Invoke-WebRequest -Uri "http://127.0.0.1:$WebPort/" -UseBasicParsing -TimeoutSec 2
|
||||
break
|
||||
} catch {
|
||||
Start-Sleep -Milliseconds 500
|
||||
}
|
||||
}
|
||||
if ($null -eq $rootResponse) {
|
||||
throw "web_gui did not become ready on port $WebPort"
|
||||
}
|
||||
if ([int]$rootResponse.StatusCode -ne 200) {
|
||||
throw "web root returned status $($rootResponse.StatusCode)"
|
||||
}
|
||||
if (-not ($rootResponse.Content.Contains("license-form") -and $rootResponse.Content.Contains("license-input"))) {
|
||||
throw "web root did not render the first-run license gate"
|
||||
}
|
||||
|
||||
$licenseStatus = Invoke-RestMethod -Uri "http://127.0.0.1:$WebPort/api/license" -TimeoutSec 10
|
||||
if ($licenseStatus.ok -ne $false -or "$($licenseStatus.reason)" -ne "missing") {
|
||||
throw "expected missing license status, got ok=$($licenseStatus.ok) reason=$($licenseStatus.reason)"
|
||||
}
|
||||
|
||||
$csrf = Invoke-RestMethod -Uri "http://127.0.0.1:$WebPort/api/csrf-token" -TimeoutSec 10
|
||||
$startRunStatus = $null
|
||||
$startRunBody = ""
|
||||
try {
|
||||
Invoke-RestMethod `
|
||||
-Uri "http://127.0.0.1:$WebPort/api/start-run" `
|
||||
-Method Post `
|
||||
-ContentType "application/json" `
|
||||
-Headers @{"X-CSRF-Token" = $csrf.token} `
|
||||
-Body "{}" `
|
||||
-TimeoutSec 10 | Out-Null
|
||||
throw "start-run unexpectedly succeeded without license"
|
||||
} catch {
|
||||
$startRunStatus = [int]$_.Exception.Response.StatusCode
|
||||
$startRunBody = $_.ErrorDetails.Message
|
||||
}
|
||||
if ($startRunStatus -ne 403 -or $startRunBody -notlike "*license_required*") {
|
||||
throw "expected /api/start-run 403 license_required, got status=$startRunStatus body=$startRunBody"
|
||||
}
|
||||
} finally {
|
||||
if ($webProc -and -not $webProc.HasExited) {
|
||||
Stop-Process -Id $webProc.Id -Force
|
||||
}
|
||||
$env:PORT = $oldPort
|
||||
$env:DOUYIN_DISABLE_AUTO_UPDATE = $oldDisableUpdate
|
||||
$env:DOUYIN_LICENSE_REQUIRED = $oldLicenseRequired
|
||||
$env:SKIP_OCR_INIT = $oldSkipOcr
|
||||
}
|
||||
|
||||
$dashProc = $null
|
||||
try {
|
||||
$env:DOUYIN_DISABLE_AUTO_UPDATE = "1"
|
||||
$env:DOUYIN_LICENSE_REQUIRED = "1"
|
||||
$env:SKIP_OCR_INIT = "1"
|
||||
$dashProc = Start-Process `
|
||||
-FilePath (Join-Path $InstallDir "DouyinGuajiGUI.exe") `
|
||||
-WorkingDirectory $InstallDir `
|
||||
-WindowStyle Hidden `
|
||||
-PassThru
|
||||
Start-Sleep -Seconds $DashboardStartupSeconds
|
||||
if ($dashProc.HasExited) {
|
||||
throw "dashboard exited early with code $($dashProc.ExitCode)"
|
||||
}
|
||||
} finally {
|
||||
if ($dashProc -and -not $dashProc.HasExited) {
|
||||
Stop-Process -Id $dashProc.Id -Force
|
||||
}
|
||||
$env:DOUYIN_DISABLE_AUTO_UPDATE = $oldDisableUpdate
|
||||
$env:DOUYIN_LICENSE_REQUIRED = $oldLicenseRequired
|
||||
$env:SKIP_OCR_INIT = $oldSkipOcr
|
||||
}
|
||||
|
||||
$report = [ordered]@{
|
||||
ok = $true
|
||||
version = $Version
|
||||
installer = $Installer
|
||||
installer_sha256 = $InstallerHash
|
||||
install_dir = $InstallDir
|
||||
web_port = $WebPort
|
||||
checks = [ordered]@{
|
||||
distribution_manifest = "pass"
|
||||
exe_smoke = "pass"
|
||||
silent_install = "pass"
|
||||
bundled_config = "pass"
|
||||
bundled_adb = "pass"
|
||||
adb_version = ($adbVersion -split "`r?`n" | Select-Object -First 1)
|
||||
cli_fails_closed_without_license = "pass"
|
||||
web_license_gate = "pass"
|
||||
web_runtime_requires_license = "pass"
|
||||
dashboard_waits_for_license = "pass"
|
||||
}
|
||||
}
|
||||
$reportPath = Join-Path $WorkRoot "fresh_install_report.json"
|
||||
$report | ConvertTo-Json -Depth 6 | Set-Content -LiteralPath $reportPath -Encoding UTF8
|
||||
Write-Host "[FRESH-INSTALL] PASS version=$Version report=$reportPath"
|
||||
Reference in new issue
Block a user