From 2f2aa2bd9c249fd4093a515ec2f01d93519d0ab7 Mon Sep 17 00:00:00 2001 From: Simone Date: Sat, 9 May 2026 00:46:27 +0200 Subject: [PATCH] test: add Test-NsinnounpBuild.ps1 e2e smoke test script Wraps Invoke-CIJob.ps1 with nsinnounp params, verifies artifact exists. Optional -VerifyArtifact flag expands zip and checks for expected DLL/EXE names. Supports -Commit for pinned SHA testing. Co-Authored-By: Claude Sonnet 4.6 --- scripts/Test-NsinnounpBuild.ps1 | 145 ++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 scripts/Test-NsinnounpBuild.ps1 diff --git a/scripts/Test-NsinnounpBuild.ps1 b/scripts/Test-NsinnounpBuild.ps1 new file mode 100644 index 0000000..2dd3a6f --- /dev/null +++ b/scripts/Test-NsinnounpBuild.ps1 @@ -0,0 +1,145 @@ +#Requires -Version 5.1 +<# +.SYNOPSIS + Runs a full end-to-end CI test build of nsis-plugin-nsinnounp. + +.DESCRIPTION + Invokes Invoke-CIJob.ps1 with the nsinnounp repo parameters and + verifies the artifact was produced. Useful for smoke-testing the + CI pipeline after changes to scripts or template VM. + + Exits 0 on success, 1 on failure. + +.PARAMETER JobId + Job identifier used for artifact and log directory names. + Default: e2e-test- + +.PARAMETER Branch + Branch to build. Default: main + +.PARAMETER Commit + Optional specific commit SHA. Default: empty (HEAD of branch). + +.PARAMETER TemplatePath + Path to template VMX. Default: env:GITEA_CI_TEMPLATE_PATH or + F:\CI\Templates\WinBuild\CI-WinBuild.vmx + +.PARAMETER VerifyArtifact + If set, unzips artifacts.zip and verifies expected DLL/EXE names + are present. Requires 7-Zip or Expand-Archive. + +.EXAMPLE + # Quick smoke test (HEAD of main): + .\Test-NsinnounpBuild.ps1 + + # Test a specific commit with artifact verification: + .\Test-NsinnounpBuild.ps1 -Commit abc1234 -VerifyArtifact + + # Custom job ID to avoid colliding with a running e2e series: + .\Test-NsinnounpBuild.ps1 -JobId 'e2e-010' +#> +[CmdletBinding()] +param( + [string] $JobId = "e2e-test-$(Get-Date -Format 'yyyyMMdd_HHmmss')", + [string] $Branch = 'main', + [string] $Commit = '', + [string] $TemplatePath = $( + if ($env:GITEA_CI_TEMPLATE_PATH) { $env:GITEA_CI_TEMPLATE_PATH } + else { 'F:\CI\Templates\WinBuild\CI-WinBuild.vmx' } + ), + [switch] $VerifyArtifact +) + +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 e2e test" +Write-Host " JobId : $JobId" +Write-Host " Branch : $Branch" +if ($Commit) { Write-Host " Commit : $Commit" } +Write-Host " Template : $TemplatePath" +Write-Host " Artifacts: $artifactDir" +Write-Host "============================================================" +Write-Host "" + +$params = @{ + JobId = $JobId + RepoUrl = 'ssh://gitea-ci/Simone/nsis-plugin-nsinnounp.git' + Branch = $Branch + TemplatePath = $TemplatePath + Submodules = $true + BuildCommand = 'python build_plugin.py --final --dist-dir dist' + GuestArtifactSource = 'dist' + GuestCredentialTarget = 'BuildVMGuest' +} +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 + + $expectedPatterns = @( + '*nsInnoUnp*.dll', + '*nsInnoUnpCLI*.exe' + ) + $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'" + } + else { + Write-Host "[Test] MISSING: no files matching '$pattern'" -ForegroundColor Red + $allFound = $false + } + } + 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