d3ro-voice/scripts/ci/build-mobile-local-e2e.ps1
2026-08-29 18:33:45 +09:00

72 lines
3.1 KiB
PowerShell

[CmdletBinding()]
param(
[Parameter(Mandatory = $true)]
[string]$VersionName,
[Parameter(Mandatory = $true)]
[int64]$VersionCode,
[Parameter(Mandatory = $true)]
[string]$OutputApk
)
$ErrorActionPreference = 'Stop'
$root = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path
$androidRoot = Join-Path $root 'apps\mobile-rn\android'
$status = & supabase status --workdir (Join-Path $root 'server') -o env 2>$null
$configuration = @{}
foreach ($line in $status) {
if ($line -match '^([A-Z_]+)="(.*)"$') { $configuration[$matches[1]] = $matches[2] }
}
$publishableKey = [string]$configuration.PUBLISHABLE_KEY
if ($publishableKey -notmatch '^sb_publishable_[A-Za-z0-9_-]{20,}$') {
throw 'The local Supabase publishable key is unavailable.'
}
if ($VersionName -notmatch '^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$') {
throw 'VersionName must be strict semver.'
}
if ($VersionCode -le 0 -or $VersionCode -gt 2100000000) {
throw 'VersionCode is outside the Android range.'
}
$env:JAVA_HOME = 'C:\Program Files\Eclipse Adoptium\jdk-17.0.14.7-hotspot'
$env:D3RO_VERSION_NAME = $VersionName
$env:D3RO_VERSION_CODE = $VersionCode.ToString()
$builtApk = Join-Path $androidRoot 'app\build\outputs\apk\e2e\app-e2e.apk'
$expectedOutputParent = [System.IO.Path]::GetFullPath((Join-Path $androidRoot 'app\build\outputs\apk\e2e'))
$resolvedOutputParent = [System.IO.Path]::GetFullPath((Split-Path $builtApk -Parent))
if ($resolvedOutputParent -ne $expectedOutputParent) {
throw 'Refusing to replace an APK outside the exact E2E build output directory.'
}
try {
# A previously restored public TEST-DEMO APK can have the same Gradle output
# path while containing different BuildConfig inputs. Removing this one
# reproducible build artifact forces packageE2e to materialize the local
# runtime override instead of trusting stale up-to-date metadata.
if (Test-Path -LiteralPath $builtApk) {
Remove-Item -LiteralPath $builtApk -Force
}
Push-Location $androidRoot
try {
$arguments = @(
':app:assembleE2e',
'-PreactNativeArchitectures=arm64-v8a,x86_64',
'-PD3RO_E2E_SUPABASE_URL=http://10.0.2.2:55321',
"-PD3RO_E2E_SUPABASE_ANON_KEY=$publishableKey",
'--no-daemon'
)
& .\gradlew.bat @arguments
if ($LASTEXITCODE -ne 0) { throw "Gradle failed with exit code $LASTEXITCODE" }
} finally {
Pop-Location
}
if (-not (Test-Path -LiteralPath $builtApk)) {
throw 'Gradle did not materialize the local E2E APK.'
}
Copy-Item -LiteralPath $builtApk -Destination $OutputApk -Force
$sourceHash = (Get-FileHash -Algorithm SHA256 -LiteralPath $builtApk).Hash
$outputHash = (Get-FileHash -Algorithm SHA256 -LiteralPath $OutputApk).Hash
if ($sourceHash -ne $outputHash) { throw 'Local E2E APK copy hash mismatch.' }
Write-Output "local_e2e_apk=$OutputApk"
Write-Output "sha256=$outputHash"
} finally {
Remove-Item Env:D3RO_VERSION_NAME, Env:D3RO_VERSION_CODE -ErrorAction SilentlyContinue
}