Files
ucvl-zonghengjia-open-source/windows/build/Build-TailnetGuardianCandidate.ps1

146 lines
13 KiB
PowerShell

#requires -Version 7.0
# Build/package only. The only executed app modes are the six reviewed offline
# self-tests below, offline startup/preview UI and --installer-verify; no installation/network/TUN commands.
param(
[string]$OutputDirectory,
[string]$ToolRoot,
[string]$DependencyPayloadRoot,
[ValidateSet(2,3,4)][int]$PreviewRevision = 2,
[switch]$FormalChannel,
[ValidateSet('0.2.20','0.2.21','0.2.22','0.2.23','0.2.24','0.3.0')][string]$FormalVersion = '0.2.21'
)
$ErrorActionPreference='Stop'
Set-StrictMode -Version Latest
$project=[IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
if(-not $OutputDirectory){$OutputDirectory=Join-Path $project $(if($FormalChannel){"artifacts/windows-$FormalVersion-formal-20261011"}else{"artifacts/tailnet-0.2.20-preview.$PreviewRevision-20260924"})}
if(-not $ToolRoot){$ToolRoot=Join-Path $project '.tools'}
if(-not $DependencyPayloadRoot){$DependencyPayloadRoot=Join-Path $project 'artifacts/tailnet-20260924/payload'}
$root=[IO.Path]::GetFullPath($OutputDirectory);$tools=[IO.Path]::GetFullPath($ToolRoot);$basis=[IO.Path]::GetFullPath($DependencyPayloadRoot)
function Plain([string]$Path){
$full=[IO.Path]::GetFullPath($Path)
for($part=$full;$part;$part=[IO.Path]::GetDirectoryName($part)){
if((Test-Path -LiteralPath $part) -and ((Get-Item -LiteralPath $part -Force).Attributes -band [IO.FileAttributes]::ReparsePoint)){throw 'Linked build path refused'}
}
return $full
}
foreach($path in @($root,$project,$tools,$basis)){[void](Plain $path)}
if((Test-Path -LiteralPath $root) -or -not $root.StartsWith($project+'\artifacts\',[StringComparison]::OrdinalIgnoreCase)){throw 'A new project artifacts directory is required; no overwrite'}
$baseVersion=if($FormalChannel){$FormalVersion}else{'0.2.20'}
$version=if($FormalChannel){$baseVersion}else{"0.2.20-tailnet.preview.$PreviewRevision"}
$fileVersion="$baseVersion.0"
$releaseNotes=if($FormalChannel){"release/RELEASE-NOTES-$baseVersion.md"}elseif($PreviewRevision -eq 4){'release/TAILNET-PREVIEW-4-20260926.md'}else{"release/TAILNET-PREVIEW-$PreviewRevision-20260924.md"}
$expected=@('VPNPlus.exe','README.md','THIRD_PARTY_NOTICES.md','licenses/Xray-MPL-2.0.txt','licenses/Wintun-License.txt','licenses/NSIS-COPYING.txt','assets/company-logo-original.png','assets/zonghengjia-app-logo-v1.png','assets/zonghengjia-app-v1.ico','xray/xray.exe','xray/wintun.dll','xray/geoip.dat','xray/geosite.dat')
$prior=@(Get-Content -LiteralPath (Join-Path $basis 'install-manifest.json') -Raw | ConvertFrom-Json)
if($prior.Count -ne 13 -or @(Compare-Object ($expected | Sort-Object) ($prior.Path | Sort-Object)).Count){throw 'Unexpected dependency payload inventory'}
foreach($row in $prior){if((Get-FileHash -LiteralPath (Join-Path $basis $row.Path)).Hash -cne $row.Sha256){throw 'Frozen dependency bytes differ from prior manifest'}}
$source=Join-Path $root 'source';$candidate=Join-Path $root 'candidate';$payload=Join-Path $root 'payload';$package=Join-Path $root 'package';$evidence=Join-Path $root 'evidence'
New-Item -ItemType Directory -Path $source,$candidate,$payload,$package,$evidence,(Join-Path $root 'empty-feed') | Out-Null
function Save([string]$Path,$Value){[IO.File]::WriteAllText($Path,($Value | ConvertTo-Json -Depth 30),[Text.UTF8Encoding]::new($false))}
function Copy-Checked([string]$From,[string]$To){
[void](Plain $From);[void](Plain $To)
if(Test-Path -LiteralPath $To){throw 'Snapshot target already exists'}
New-Item -ItemType Directory -Force -Path ([IO.Path]::GetDirectoryName($To)) | Out-Null
$hash=(Get-FileHash -LiteralPath $From).Hash
Copy-Item -LiteralPath $From -Destination $To
if((Get-FileHash -LiteralPath $To).Hash -cne $hash -or (Get-FileHash -LiteralPath $From).Hash -cne $hash){throw 'Source changed during snapshot'}
return $hash
}
$relative=@(Get-ChildItem -LiteralPath $project -File -Filter '*.cs' | ForEach-Object Name)+@('VPNPlus.csproj','app.manifest','README.md','THIRD_PARTY_NOTICES.md')+
@(Get-ChildItem -LiteralPath (Join-Path $project 'assets') -File | ForEach-Object {'assets/'+$_.Name})+
@(Get-ChildItem -LiteralPath (Join-Path $project 'installer') -File | Where-Object Extension -in @('.nsi','.nsh') | ForEach-Object {'installer/'+$_.Name})+
@('build/Build-TailnetGuardianCandidate.ps1','build/GuardianGateFixture.cs','build/GuardianGateFixture.csproj','build/GuardianApprovalPipe.cs','build/Test-InstallerGuardianGate.ps1',
'build/ProductionNetworkBaseline.ps1','build/Test-ProductionNetworkBaseline.ps1','build/ProductionInstallationBaseline.ps1','build/Test-ProductionInstallationBaseline.ps1','build/OwnedProcessGroup.cs',
$releaseNotes,'release/TAILNET-PRIORITY-20260924.md','release/INSTALLER-GUARDIAN-GATE-20260924.md','release/PRODUCTION-NETWORK-BASELINE-20260924.md')
$snapshot=@(foreach($name in @($relative | Sort-Object -Unique)){
$hash=Copy-Checked (Join-Path $project $name) (Join-Path $source $name)
[ordered]@{Path=$name;Sha256=$hash}
})
Save (Join-Path $evidence 'source-manifest.json') $snapshot
$dotnet=Join-Path $tools 'dotnet/dotnet.exe';$nsis=Join-Path $tools 'nsis/nsis-3.12/makensis.exe'
$buildArgs=@('publish',(Join-Path $source 'VPNPlus.csproj'),'-c','Release','-r','win-x64','--self-contained','true','--source',(Join-Path $root 'empty-feed'),
"-p:Version=$version","-p:AssemblyVersion=$fileVersion","-p:FileVersion=$fileVersion","-p:InformationalVersion=$version",'-p:IncludeSourceRevisionInInformationalVersion=false',
"-p:BaseIntermediateOutputPath=$root\obj\","-p:MSBuildProjectExtensionsPath=$root\obj\",'-o',$candidate)
& $dotnet @buildArgs
if($LASTEXITCODE -ne 0){throw 'Isolated publish failed'}
$exe=Join-Path $candidate 'VPNPlus.exe';$exeHash=(Get-FileHash -LiteralPath $exe).Hash
$exeInfo=[Diagnostics.FileVersionInfo]::GetVersionInfo($exe)
if($exeInfo.ProductVersion -cne $version -or $exeInfo.FileVersion -cne $fileVersion){throw 'Candidate version metadata mismatch'}
function Run-Offline([string]$File,[string]$Argument,[int]$Timeout=45){
$start=[Diagnostics.ProcessStartInfo]::new($File);$start.UseShellExecute=$false;$start.CreateNoWindow=$true;$start.WindowStyle=[Diagnostics.ProcessWindowStyle]::Hidden
$start.ArgumentList.Add($Argument)
$child=[Diagnostics.Process]::Start($start);$watch=[Diagnostics.Stopwatch]::StartNew()
try {
while(-not $child.WaitForExit(100)){
if($watch.Elapsed.TotalSeconds -gt $Timeout){$child.Kill($true);throw ('Only the owned offline child exceeded its deadline: '+$Argument)}
}
return $child.ExitCode
} finally {$child.Dispose()}
}
$offlineTests=@('tailnet-transport-self-test','connection-health-self-test','connection-selection-self-test','private-auxiliary-self-test','learning-self-test','window-chrome-self-test','installation-self-test')
if($FormalChannel -and $FormalVersion -eq '0.3.0'){
$offlineTests+=@('public-tailnet-selection-self-test','learning-sync-coordinator-self-test','tailnet-readiness-self-test','nextgen-lifecycle-self-test','network-handover-self-test','dashboard-interaction-self-test')
}
$results=@(foreach($name in $offlineTests){
$report=Join-Path $candidate ($name+'.json');if(Test-Path -LiteralPath $report){throw 'Stale offline report'}
$exit=Run-Offline $exe ('--'+$name)
$parsed=Get-Content -LiteralPath $report -Raw | ConvertFrom-Json
$passed=$exit -eq 0 -and $parsed.passed -eq $true -and @($parsed.checks.PSObject.Properties | Where-Object Value -ne $true).Count -eq 0
if(-not $passed){throw ('Offline check failed: '+$name)}
[ordered]@{Test=$name;ExitCode=$exit;Passed=$passed;Checks=@($parsed.checks.PSObject.Properties).Count;ReportSha256=(Get-FileHash -LiteralPath $report).Hash;CandidateSha256=$exeHash}
})
if((Get-FileHash -LiteralPath $exe).Hash -cne $exeHash){throw 'Candidate changed during offline tests'}
$offline=[ordered]@{Kind='exact-build-offline-executable';Version=$version;CandidateSha256=$exeHash;Passed=$true;Count=($results.Checks | Measure-Object -Sum).Sum;Tests=$results;NetworkActions=@();Installed=$false;Published=$false;ProductionAccepted=$false}
Save (Join-Path $evidence 'offline-validation.json') $offline
# Validate the actual login composition before CPU-intensive NSIS compression.
# This owned UI-only mode never loads credentials or changes networking.
$startupReport=Join-Path $candidate 'startup-self-test.json'
if(Test-Path -LiteralPath $startupReport){throw 'Stale startup report'}
$startupExit=Run-Offline $exe '--startup-self-test'
$startup=Get-Content -LiteralPath $startupReport -Raw | ConvertFrom-Json
if($startupExit -ne 0 -or $startup.passed -ne $true){throw 'Offline startup/login UI check failed'}
foreach($name in @('startup-self-test.json','startup-login-test.png')){
Copy-Checked (Join-Path $candidate $name) (Join-Path $evidence $name) | Out-Null
}
if($FormalChannel -and $FormalVersion -eq '0.3.0'){
$previewExit=Run-Offline $exe '--render-preview'
$previewReport=Join-Path $candidate 'dashboard-ui-self-test.json'
$preview=Get-Content -LiteralPath $previewReport -Raw | ConvertFrom-Json
if($previewExit -ne 0 -or $preview.passed -ne $true){throw 'Exact-build dashboard preview failed'}
Copy-Checked $previewReport (Join-Path $evidence 'dashboard-ui-self-test.json') | Out-Null
foreach($previewImage in Get-ChildItem -LiteralPath $candidate -Filter 'preview-*.png' -File){
Copy-Checked $previewImage.FullName (Join-Path $evidence $previewImage.Name) | Out-Null
}
}
foreach($name in $results.Test){Copy-Item -LiteralPath (Join-Path $candidate ($name+'.json')) -Destination (Join-Path $evidence ($name+'.json'))}
if(Test-Path -LiteralPath (Join-Path $candidate 'window-chrome-offline.png')){Copy-Item -LiteralPath (Join-Path $candidate 'window-chrome-offline.png') -Destination (Join-Path $evidence 'window-chrome-offline.png')}
$manifest=@(foreach($name in $expected){
$from=switch -Exact ($name){
'VPNPlus.exe' {$exe;break}
'README.md' {Join-Path $source $releaseNotes;break}
default {Join-Path $basis $name}
}
[ordered]@{Path=$name;Sha256=(Copy-Checked $from (Join-Path $payload $name))}
})
Save (Join-Path $payload 'install-manifest.json') $manifest
if((Run-Offline (Join-Path $payload 'VPNPlus.exe') '--installer-verify') -ne 0){throw 'Exact new payload installer verification failed'}
$filename="UCVL-Zonghengjia-$version-win-x64-setup.exe";$setup=Join-Path $package $filename
[string[]]$versionArgs=if($FormalChannel){@('/DPRODUCT_REVISION=0')}else{@("/DPRODUCT_BUILD_SUFFIX=-tailnet.preview.$PreviewRevision","/DPRODUCT_REVISION=$PreviewRevision")}
& $nsis '/V2' "/DPRODUCT_VERSION=$baseVersion" @versionArgs "/DAPP_SOURCE_DIR=$payload" "/DINSTALLER_OUTPUT=$setup" '/INPUTCHARSET' 'UTF8' (Join-Path $source 'installer/VPNPlus.nsi')
if($LASTEXITCODE -ne 0){throw 'Production NSIS packaging failed'}
$setupHash=(Get-FileHash -LiteralPath $setup).Hash
[IO.File]::WriteAllText(($setup+'.sha256'),($setupHash.ToLowerInvariant()+' '+$filename+[Environment]::NewLine),[Text.Encoding]::ASCII)
$packageInfo=[Diagnostics.FileVersionInfo]::GetVersionInfo($setup)
if($packageInfo.ProductVersion -cne $version -or $packageInfo.FileVersion -cne $version){throw 'Package prerelease metadata mismatch'}
foreach($row in $manifest){if((Get-FileHash -LiteralPath (Join-Path $payload $row.Path)).Hash -cne $row.Sha256){throw 'Payload changed during packaging'}}
$actual=@(Get-ChildItem -LiteralPath $payload -Recurse -File | ForEach-Object {[IO.Path]::GetRelativePath($payload,$_.FullName).Replace('\','/')})
if(@(Compare-Object (@($expected)+@('install-manifest.json') | Sort-Object) ($actual | Sort-Object)).Count){throw 'Unexpected diagnostics in release payload'}
foreach($row in $snapshot){if((Get-FileHash -LiteralPath (Join-Path $source $row.Path)).Hash -cne $row.Sha256){throw 'Frozen source changed during build'}}
$signatures=@(foreach($file in @($exe,$setup)){[ordered]@{File=[IO.Path]::GetFileName($file);Status=[string](Get-AuthenticodeSignature -LiteralPath $file).Status}})
$summary=[ordered]@{Kind='windows-build-package-only';RequestedChannel=$(if($FormalChannel){'formal-nonmandatory'}else{'preview'});Version=$version;CandidateSha256=$exeHash;PackageSha256=$setupHash;PackageBytes=(Get-Item -LiteralPath $setup).Length;
PayloadFiles=13;SourceFiles=$snapshot.Count;OfflineChecks=$offline.Count;FileVersion=$exeInfo.FileVersion;ProductVersion=$exeInfo.ProductVersion;PackageProductVersion=$packageInfo.ProductVersion;
Signatures=$signatures;Installed=$false;Published=$false;ProductionAccepted=$false;CandidateDirectory=$root;SourceManifestSha256=(Get-FileHash -LiteralPath (Join-Path $evidence 'source-manifest.json')).Hash;
Build=[ordered]@{DotnetSha256=(Get-FileHash -LiteralPath $dotnet).Hash;NsisSha256=(Get-FileHash -LiteralPath $nsis).Hash;Arguments=$buildArgs};
NotAccepted=@('live same-node Tailscale proxy','TUN and Tailscale UDP/DERP underlay coexistence','live failover/network handover','current node firewall','production UAC/upgrade/complete guardian rollback','authenticated sustained session','physical multi-monitor DPI, drag and snap')}
Save (Join-Path $root 'frozen-candidate.json') $summary
$summary | ConvertTo-Json -Depth 8