Release Android 1.0.9 single-node client

This commit is contained in:
UCVL Software Automation
2026-11-30 09:09:47 +08:00
parent 9c122a8913
commit 277284ea03
27 changed files with 1569 additions and 202 deletions
+178
View File
@@ -0,0 +1,178 @@
# Local candidate only. Uses cached dependencies; never starts adb or an emulator.
param([string]$JobDirectory = '',[switch]$ResumeAfterBuild,[string]$ToolRoot = '')
$ErrorActionPreference = 'Stop'
Set-StrictMode -Version Latest
$repo = [IO.Path]::GetFullPath((Join-Path $PSScriptRoot '..'))
$tempRoot = [IO.Path]::GetFullPath([IO.Path]::GetTempPath()).TrimEnd(
[char[]]@([IO.Path]::DirectorySeparatorChar,[IO.Path]::AltDirectorySeparatorChar)
)
if ($ResumeAfterBuild -and -not $JobDirectory) { throw 'Resume requires the exact completed build directory' }
if (-not $JobDirectory) { $JobDirectory = Join-Path $tempRoot ('ucvl-android-109-' + [guid]::NewGuid().ToString('N')) }
$job = [IO.Path]::GetFullPath($JobDirectory)
if ([IO.Path]::GetDirectoryName($job) -ine $tempRoot -or [IO.Path]::GetFileName($job) -cnotmatch '^ucvl-android-109-[a-f0-9]{32}$' -or $job -match '[^\x00-\x7F]') {
throw 'A fresh scoped ASCII temporary directory is required'
}
if ((Test-Path -LiteralPath $job) -and -not $ResumeAfterBuild) { throw 'Candidate directory already exists' }
$buildText = Get-Content -LiteralPath (Join-Path $repo 'V2rayNG/app/build.gradle.kts') -Raw
if ($buildText -notmatch 'versionCode = 10009' -or $buildText -notmatch 'versionName = "1.0.9"') { throw 'Source version mismatch' }
$toolRootValue = if ($ToolRoot) { $ToolRoot } else { $env:UCVL_ANDROID_TOOL_ROOT }
if (-not $toolRootValue) { throw 'ToolRoot or UCVL_ANDROID_TOOL_ROOT is required' }
$toolRootPath = [IO.Path]::GetFullPath($toolRootValue)
$javaHome = Join-Path $toolRootPath '.tools/jdk-staging/jdk-21.0.12.1+1'
$androidSdk = Join-Path $toolRootPath '.tools/android-sdk'
$signingProperties = Join-Path $toolRootPath '.tools/signing/signing.properties'
$keyStore = Join-Path $toolRootPath '.tools/signing/ucvl-zonghengjia-release.jks'
foreach ($required in @($javaHome,$androidSdk,$signingProperties,$keyStore)) {
if (-not (Test-Path -LiteralPath $required)) { throw "Missing private build input: $required" }
}
$project = Join-Path $job 'project'
$source = Join-Path $repo 'V2rayNG'
function Save-Json([string]$Name,$Value) {
[IO.File]::WriteAllText((Join-Path $job "evidence/$Name"),($Value | ConvertTo-Json -Depth 12),[Text.UTF8Encoding]::new($false))
}
function Get-PortableRelativePath([string]$Base,[string]$Target) {
$basePath = [IO.Path]::GetFullPath($Base).TrimEnd([char[]]@([char]'\',[char]'/')) + [IO.Path]::DirectorySeparatorChar
$baseUri = New-Object System.Uri($basePath)
$targetUri = New-Object System.Uri([IO.Path]::GetFullPath($Target))
[Uri]::UnescapeDataString($baseUri.MakeRelativeUri($targetUri).ToString()).Replace('\','/')
}
function Read-UnitTestSuites {
@(Get-ChildItem -LiteralPath (Join-Path $project 'app/build/test-results/testPlaystoreReleaseUnitTest') -Filter 'TEST-*.xml' -File -ErrorAction SilentlyContinue | Sort-Object Name | ForEach-Object {
[xml]$xml = [IO.File]::ReadAllText($_.FullName,[Text.Encoding]::UTF8)
[pscustomobject]@{
Name=[string]$xml.testsuite.name
Tests=[int]$xml.testsuite.tests
Failures=[int]$xml.testsuite.failures
Errors=[int]$xml.testsuite.errors
Skipped=[int]$xml.testsuite.skipped
TestCases=@($xml.testsuite.testcase).Count
ReportName=$_.Name
ReportSha256=(Get-FileHash -LiteralPath $_.FullName -Algorithm SHA256).Hash
}
})
}
$env:JAVA_HOME = $javaHome
$env:ANDROID_HOME = $androidSdk
if (-not $ResumeAfterBuild) {
$null = New-Item -ItemType Directory -Path $job,$project,(Join-Path $job 'evidence'),(Join-Path $job 'artifacts')
foreach ($name in @('gradlew','gradlew.bat','gradle.properties','settings.gradle.kts','build.gradle.kts','gradle')) {
Copy-Item -LiteralPath (Join-Path $source $name) -Destination $project -Recurse
}
$null = New-Item -ItemType Directory -Path (Join-Path $project 'app')
foreach ($name in @('src','libs','build.gradle.kts','proguard-rules.pro')) {
Copy-Item -LiteralPath (Join-Path $source "app/$name") -Destination (Join-Path $project 'app') -Recurse
}
$inputs = @(Get-ChildItem -LiteralPath $project -File -Recurse | Sort-Object FullName | ForEach-Object {
[ordered]@{Path=(Get-PortableRelativePath $project $_.FullName);Bytes=$_.Length;Sha256=(Get-FileHash -LiteralPath $_.FullName -Algorithm SHA256).Hash}
})
Save-Json 'build-inputs.json' $inputs
$inputsHash = (Get-FileHash -LiteralPath (Join-Path $job 'evidence/build-inputs.json')).Hash
$started = [DateTimeOffset]::Now
Push-Location $project
try {
$savedErrorActionPreference = $ErrorActionPreference
try {
# Windows PowerShell 5 wraps benign native stderr (for example JVM
# warnings) as NativeCommandError. The Gradle process exit code is the
# authoritative build result and its complete output remains in evidence.
$ErrorActionPreference = 'Continue'
& ./gradlew.bat --offline --no-daemon --max-workers=2 :app:testPlaystoreReleaseUnitTest :app:assemblePlaystoreRelease :app:assemblePlaystoreReleaseAndroidTest *> (Join-Path $job 'evidence/gradle.log')
$buildExit = $LASTEXITCODE
} finally {
$ErrorActionPreference = $savedErrorActionPreference
}
} finally { Pop-Location }
$suites = @(Read-UnitTestSuites)
$tests = [ordered]@{StartedAt=$started.ToString('O');ExitCode=$buildExit;Offline=$true;Suites=$suites;BuildInputsSha256=$inputsHash;PhysicalDeviceTested=$false;EmulatorStarted=$false;Published=$false}
Save-Json 'tests.json' $tests
} else {
$tests = Get-Content -LiteralPath (Join-Path $job 'evidence/tests.json') -Raw | ConvertFrom-Json
$suites = @(Read-UnitTestSuites)
if (($tests.Suites | ConvertTo-Json -Depth 5 -Compress) -cne ($suites | ConvertTo-Json -Depth 5 -Compress)) { throw 'Completed JUnit XML evidence changed' }
$buildExit = $tests.ExitCode
$inputs = Get-Content -LiteralPath (Join-Path $job 'evidence/build-inputs.json') -Raw | ConvertFrom-Json
$inputsHash = (Get-FileHash -LiteralPath (Join-Path $job 'evidence/build-inputs.json')).Hash
if ($inputsHash -ne $tests.BuildInputsSha256) { throw 'Completed build input manifest changed' }
}
if ($buildExit -ne 0) { throw "Gradle failed ($buildExit); evidence retained at $job" }
$totalUnitTests = [int]($suites | Measure-Object Tests -Sum).Sum
$authorizationSuites = @($suites | Where-Object { $_.Name -ceq 'com.v2ray.ang.ucvl.UcvlAuthorizationGuardTest' })
$startupLeaseSuites = @($suites | Where-Object { $_.Name -ceq 'com.v2ray.ang.ucvl.UcvlVpnStartupLeaseTest' })
$upgradeSuites = @($suites | Where-Object { $_.Name -ceq 'com.v2ray.ang.ucvl.UcvlUpgradeReliabilityTest' })
$singleNodeSuites = @($suites | Where-Object { $_.Name -ceq 'com.v2ray.ang.ucvl.UcvlSingleNodePolicyTest' })
$modeSwitchSuites = @($suites | Where-Object { $_.Name -ceq 'com.v2ray.ang.ucvl.UcvlModeSwitchTransactionTest' })
$managedRecordSuites = @($suites | Where-Object { $_.Name -ceq 'com.v2ray.ang.ucvl.UcvlManagedConfigRecordTest' })
$serviceStateSuites = @($suites | Where-Object { $_.Name -ceq 'com.v2ray.ang.ucvl.UcvlServiceStateReconcilerTest' })
if ($totalUnitTests -lt 100 -or ($suites | Measure-Object Failures -Sum).Sum -ne 0 -or ($suites | Measure-Object Errors -Sum).Sum -ne 0 -or ($suites | Measure-Object Skipped -Sum).Sum -ne 0) {
throw 'Unexpected unit test coverage or failures'
}
if ($authorizationSuites.Count -ne 1 -or $authorizationSuites[0].Tests -ne 10 -or $startupLeaseSuites.Count -ne 1 -or $startupLeaseSuites[0].Tests -lt 8) {
throw 'Required authorization or VPN startup lease regressions missing'
}
if ($upgradeSuites.Count -ne 1 -or $upgradeSuites[0].Tests -ne 8) { throw 'Required Android upgrade regressions missing' }
if ($singleNodeSuites.Count -ne 1 -or $singleNodeSuites[0].Tests -lt 20 -or $modeSwitchSuites.Count -ne 1 -or $modeSwitchSuites[0].Tests -lt 9 -or $managedRecordSuites.Count -ne 1 -or $managedRecordSuites[0].Tests -ne 4 -or $serviceStateSuites.Count -ne 1 -or $serviceStateSuites[0].Tests -ne 4) {
throw 'Required single-node or live mode-switch regressions missing'
}
foreach ($suite in $suites) {
if (-not $suite.Name -or $suite.Tests -lt 1 -or $suite.Tests -ne $suite.TestCases) { throw 'JUnit suite count differs from actual test cases' }
}
$authorizationUnitTests = [int]$authorizationSuites[0].Tests
$startupLeaseUnitTests = [int]$startupLeaseSuites[0].Tests
foreach ($row in $inputs) {
if ((Get-FileHash -LiteralPath (Join-Path $project $row.Path)).Hash -ne $row.Sha256 -or (Get-FileHash -LiteralPath (Join-Path $source $row.Path)).Hash -ne $row.Sha256) {
throw "Input changed during build: $($row.Path)"
}
}
$java = Join-Path $env:JAVA_HOME 'bin/java.exe'
$signer = Join-Path $env:ANDROID_HOME 'build-tools/37.0.0/lib/apksigner.jar'
$signerBat = Join-Path $env:ANDROID_HOME 'build-tools/37.0.0/apksigner.bat'
$zipAlign = Join-Path $env:ANDROID_HOME 'build-tools/37.0.0/zipalign.exe'
$aapt = Join-Path $env:ANDROID_HOME 'build-tools/37.0.0/aapt.exe'
$expectedCertificate = '0f1a09870d6ee1e73b62138f99463e7066f4228ce28b7f16ff0aeccca59ea14f'
$previousPackage = Join-Path $toolRootPath 'releases/UCVL-Zonghengjia-1.0.8-android-universal.apk'
$oldVerification = (& $java -jar $signer verify --verbose --print-certs $previousPackage 2>&1 | Out-String)
if ($LASTEXITCODE -ne 0 -or $oldVerification -notmatch $expectedCertificate) { throw 'Old 1.0.8 signing identity differs' }
$signing = @{}
Get-Content -LiteralPath $signingProperties | ForEach-Object {
$parts = $_ -split '=',2
if ($parts.Length -eq 2) { $signing[$parts[0].Trim()] = $parts[1].Trim() }
}
$env:UCVL_ANDROID_STORE_PASS = $signing['storePassword']
$env:UCVL_ANDROID_KEY_PASS = $signing['keyPassword']
try {
foreach ($unsigned in Get-ChildItem -LiteralPath (Join-Path $project 'app/build/outputs/apk/playstore/release') -Filter 'UCVL-Zonghengjia-1.0.9-android-*.apk' -File) {
$aligned = Join-Path $job ('.aligned-' + $unsigned.Name)
$signed = Join-Path $job ('artifacts/' + $unsigned.Name)
& $zipAlign -f -p 4 $unsigned.FullName $aligned
if ($LASTEXITCODE -ne 0) { throw "APK alignment failed: $($unsigned.Name)" }
& $signerBat sign --ks $keyStore --ks-key-alias $signing['keyAlias'] --ks-pass env:UCVL_ANDROID_STORE_PASS --key-pass env:UCVL_ANDROID_KEY_PASS --out $signed $aligned
if ($LASTEXITCODE -ne 0) { throw "APK signing failed: $($unsigned.Name)" }
Remove-Item -LiteralPath $aligned -Force
}
$unsignedTest = Get-ChildItem -LiteralPath (Join-Path $project 'app/build/outputs/apk/androidTest/playstore/release') -Filter '*androidTest*.apk' -File
if (@($unsignedTest).Count -ne 1) { throw 'Expected exactly one Android instrumentation APK' }
$alignedTest = Join-Path $job '.aligned-app-playstore-release-androidTest-1.0.9.apk'
$signedTest = Join-Path $job 'artifacts/app-playstore-release-androidTest-1.0.9.apk'
& $zipAlign -f -p 4 $unsignedTest.FullName $alignedTest
if ($LASTEXITCODE -ne 0) { throw 'Android instrumentation APK alignment failed' }
& $signerBat sign --ks $keyStore --ks-key-alias $signing['keyAlias'] --ks-pass env:UCVL_ANDROID_STORE_PASS --key-pass env:UCVL_ANDROID_KEY_PASS --out $signedTest $alignedTest
if ($LASTEXITCODE -ne 0) { throw 'Android instrumentation APK signing failed' }
Remove-Item -LiteralPath $alignedTest -Force
} finally {
Remove-Item Env:UCVL_ANDROID_STORE_PASS,Env:UCVL_ANDROID_KEY_PASS -ErrorAction SilentlyContinue
$signing.Clear()
}
$packages = @(foreach ($file in Get-ChildItem -LiteralPath (Join-Path $job 'artifacts') -Filter 'UCVL-Zonghengjia-1.0.9-android-*.apk' -File | Sort-Object Name) {
$verification = (& $java -jar $signer verify --verbose --print-certs $file.FullName 2>&1 | Out-String)
if ($LASTEXITCODE -ne 0 -or $verification -notmatch $expectedCertificate -or $verification -notmatch 'v2\): true' -or $verification -notmatch 'v3\): true') { throw "Candidate signature mismatch: $($file.Name)" }
$badging = (& $aapt dump badging $file.FullName 2>&1 | Out-String)
if ($LASTEXITCODE -ne 0 -or $badging -notmatch "package: name='cn.toplc.zonghengjia' versionCode='4010009' versionName='1.0.9'") { throw "Candidate manifest mismatch: $($file.Name)" }
[ordered]@{Name=$file.Name;Bytes=$file.Length;Sha256=(Get-FileHash -LiteralPath $file.FullName).Hash;Version='1.0.9';VersionCode=4010009;SignerSha256=$expectedCertificate;V2=$true;V3=$true}
})
if ($packages.Count -ne 5) { throw 'Expected all five ABI/universal packages' }
$testApk = Get-Item -LiteralPath (Join-Path $job 'artifacts/app-playstore-release-androidTest-1.0.9.apk')
$testVerification = (& $java -jar $signer verify --verbose --print-certs $testApk.FullName 2>&1 | Out-String)
if ($LASTEXITCODE -ne 0 -or $testVerification -notmatch $expectedCertificate) { throw 'Android instrumentation APK signature mismatch' }
Save-Json 'candidate.json' ([ordered]@{Version='1.0.9';VersionCode=4010009;BaseVersionCode=10009;JobDirectory=$job;BuiltAt=[DateTimeOffset]::Now.ToString('O');Packages=$packages;AndroidTest=[ordered]@{Name=$testApk.Name;Bytes=$testApk.Length;Sha256=(Get-FileHash -LiteralPath $testApk.FullName).Hash;SignerSha256=$expectedCertificate};BuildInputsSha256=$inputsHash;UnitTests=$totalUnitTests;AuthorizationLifecycleJvmTests=$authorizationUnitTests;StartupLeaseJvmTests=$startupLeaseUnitTests;SingleNodeJvmTests=[int]$singleNodeSuites[0].Tests;ModeSwitchJvmTests=[int]$modeSwitchSuites[0].Tests;ManagedConfigRecordJvmTests=[int]$managedRecordSuites[0].Tests;ServiceStateJvmTests=[int]$serviceStateSuites[0].Tests;SameSignerAs=@('1.0.8');PhysicalDeviceTested=$false;AndroidServiceBroadcastTested=$false;StableReleaseAccepted=$false;Published=$false})
Write-Output "CANDIDATE_JOB=$job"
Write-Output 'CANDIDATE_BUILD_SIGN_VERIFY_PASSED'