Files
local-ci-cd-system/scripts/Test-NsinnounpBuild-Linux.ps1
T
Simone 383d6864ce test: add Linux build E2E test scripts
Test-Ns7zipBuild-Linux.ps1: e2e test for nsis7z plugin build on Linux VM
  (confirmed PASS: nsis7z.dll 2272 KB in 03:09  2026-05-11)

Test-NsinnounpBuild-Linux.ps1: e2e test for nsinnounp plugin build on Linux VM
2026-05-11 18:34:50 +02:00

174 lines
5.9 KiB
PowerShell

#Requires -Version 5.1
<#
.SYNOPSIS
Runs a full end-to-end CI test build of nsis-plugin-nsinnounp on the Linux template.
.DESCRIPTION
Invokes Invoke-CIJob.ps1 with the nsinnounp repo parameters targeting the Linux
build template (LinuxBuild2404) and verifies the artifact was produced.
Useful for smoke-testing the Linux CI pipeline after changes to scripts or
the LinuxBuild2404 template VM.
Exits 0 on success, 1 on failure.
.PARAMETER JobId
Job identifier used for artifact and log directory names.
Default: e2e-linux-<yyyyMMdd_HHmmss>
.PARAMETER Branch
Branch to build. Default: main
.PARAMETER Commit
Optional specific commit SHA. Default: empty (HEAD of branch).
.PARAMETER TemplatePath
Path to the Linux template VMX.
Default: env:GITEA_CI_LINUX_TEMPLATE_PATH or
F:\CI\Templates\LinuxBuild2404\LinuxBuild2404.vmx
.PARAMETER SnapshotName
Snapshot name to clone from. Default: BaseClean-Linux
.PARAMETER SshKeyPath
SSH private key for the ci_build user in the guest.
Default: F:\CI\keys\ci_linux
.PARAMETER VerifyArtifact
If set, expands artifacts.zip and checks that at least one file is present.
Default: $true
.EXAMPLE
# Quick smoke test (HEAD of main):
.\Test-NsinnounpBuild-Linux.ps1
# Test a specific commit:
.\Test-NsinnounpBuild-Linux.ps1 -Commit abc1234 -VerifyArtifact
# Custom job ID:
.\Test-NsinnounpBuild-Linux.ps1 -JobId 'e2e-linux-001'
#>
[CmdletBinding()]
param(
[string] $JobId = "e2e-linux-$(Get-Date -Format 'yyyyMMdd_HHmmss')",
[string] $Branch = 'main',
[string] $Commit = '',
[string] $TemplatePath = $(
if ($env:GITEA_CI_LINUX_TEMPLATE_PATH) { $env:GITEA_CI_LINUX_TEMPLATE_PATH }
else { 'F:\CI\Templates\LinuxBuild2404\LinuxBuild2404.vmx' }
),
[string] $SnapshotName = 'BaseClean-Linux',
[string] $SshKeyPath = 'F:\CI\keys\ci_linux',
[switch] $VerifyArtifact = $true
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
$scriptDir = Split-Path $MyInvocation.MyCommand.Path -Parent
$orchestrator = Join-Path $scriptDir 'Invoke-CIJob.ps1'
$artifactDir = "F:\CI\Artifacts\$JobId"
$artifactZip = Join-Path $artifactDir 'artifacts.zip'
Write-Host "============================================================"
Write-Host " nsinnounp Linux e2e test"
Write-Host " JobId : $JobId"
Write-Host " Branch : $Branch"
if ($Commit) { Write-Host " Commit : $Commit" }
Write-Host " Template : $TemplatePath"
Write-Host " Snapshot : $SnapshotName"
Write-Host " Artifacts: $artifactDir"
Write-Host "============================================================"
Write-Host ""
$params = @{
JobId = $JobId
RepoUrl = 'ssh://gitea-ci/Simone/nsis-plugin-nsinnounp.git'
Branch = $Branch
TemplatePath = $TemplatePath
SnapshotName = $SnapshotName
Submodules = $true
BuildCommand = 'python3 build_plugin.py --final --dist-dir dist'
GuestArtifactSource = 'dist'
GuestOS = 'Linux'
SshKeyPath = $SshKeyPath
SshUser = 'ci_build'
}
if ($Commit -ne '') { $params['Commit'] = $Commit }
$startTime = Get-Date
$exitCode = 0
try {
& $orchestrator @params
$exitCode = $LASTEXITCODE
}
catch {
Write-Host "[Test] Invoke-CIJob.ps1 threw: $_"
$exitCode = 1
}
$elapsed = (Get-Date) - $startTime
Write-Host ""
Write-Host "============================================================"
if ($exitCode -ne 0) {
Write-Host "[Test] FAIL — Invoke-CIJob.ps1 exited $exitCode after $($elapsed.ToString('mm\:ss'))" -ForegroundColor Red
exit 1
}
# Verify artifact zip exists and is non-empty
if (-not (Test-Path $artifactZip)) {
Write-Host "[Test] FAIL — artifact not found: $artifactZip" -ForegroundColor Red
exit 1
}
$zipSize = [math]::Round((Get-Item $artifactZip).Length / 1KB)
Write-Host "[Test] Artifact OK: $artifactZip ($zipSize KB)"
# Optional: expand and verify expected files are present
if ($VerifyArtifact) {
$extractDir = Join-Path $artifactDir 'verify'
Write-Host "[Test] Expanding artifact for verification..."
if (Test-Path $extractDir) { Remove-Item $extractDir -Recurse -Force }
Expand-Archive -Path $artifactZip -DestinationPath $extractDir -Force
# Accept either Windows cross-compiled artifacts (mingw) or native Linux artifacts
$expectedPatterns = @(
'*nsInnoUnp*'
)
$allFound = $true
foreach ($pattern in $expectedPatterns) {
$found = Get-ChildItem -Path $extractDir -Filter $pattern -Recurse -ErrorAction SilentlyContinue
if ($found) {
Write-Host "[Test] OK: $($found.Count) file(s) matching '$pattern'"
$found | ForEach-Object { Write-Host "[Test] $($_.Name)" }
}
else {
Write-Host "[Test] MISSING: no files matching '$pattern'" -ForegroundColor Red
$allFound = $false
}
}
# Fallback: accept any non-empty dist
if (-not $allFound) {
$allFiles = @(Get-ChildItem -Path $extractDir -Recurse -File -ErrorAction SilentlyContinue)
if ($allFiles.Count -gt 0) {
Write-Host "[Test] NOTE: pattern check failed but $($allFiles.Count) file(s) found in dist:" -ForegroundColor Yellow
$allFiles | ForEach-Object { Write-Host "[Test] $($_.Name)" }
Write-Host "[Test] Update -expectedPatterns in this script to match actual Linux output." -ForegroundColor Yellow
$allFound = $true
}
}
Remove-Item $extractDir -Recurse -Force -ErrorAction SilentlyContinue
if (-not $allFound) {
Write-Host "[Test] FAIL — artifact missing expected files." -ForegroundColor Red
exit 1
}
}
Write-Host "[Test] PASS — $JobId completed in $($elapsed.ToString('mm\:ss'))" -ForegroundColor Green
Write-Host " Artifacts: $artifactDir"
Write-Host "============================================================"
exit 0