param([string]$OutputDirectory = '', [string]$UpdateOrigin = '') $ErrorActionPreference = 'Stop' $taskApp = Split-Path $PSScriptRoot -Parent $taskRepo = Split-Path $taskApp -Parent if (!$OutputDirectory) { $OutputDirectory = Join-Path $taskRepo '.codex-tmp/app-dev-ota/data' } if (!$UpdateOrigin) { $UpdateOrigin = (Get-Content -LiteralPath (Join-Path $taskApp 'config/development.json') -Encoding UTF8 -Raw | ConvertFrom-Json).updateOrigin } try { $env:APP_ENV = 'dev' $env:APP_UPDATE_ORIGIN = $UpdateOrigin $env:OTA_PRIVATE_KEY = Join-Path $taskApp 'keys/development/ota-private-key.pem' $env:OTA_CERTIFICATE = Join-Path $taskApp 'certs/dev.pem' $env:OTA_DATA_DIR = $OutputDirectory $taskRuntime = (Get-Content -LiteralPath (Join-Path $taskApp 'dist/runtime-version.txt') -Raw).Trim() $taskApkRuntime = (Get-Content -LiteralPath (Join-Path $taskApp 'android/app/build/generated/assets/createReleaseUpdatesResources/fingerprint') -Raw).Trim() if ($taskRuntime -ne $taskApkRuntime) { throw 'Export fingerprint differs from built APK; rebuild before staging' } $taskExportConfig = Get-Content -LiteralPath (Join-Path $taskApp 'dist/resolved-config.json') -Encoding UTF8 -Raw | ConvertFrom-Json if ($taskExportConfig.extra.environment -ne 'dev' -or $taskExportConfig.updates.url -ne ($UpdateOrigin.TrimEnd('/') + '/updates/dev')) { throw 'Exported App update URL differs from the development feed; export with matching development config first' } & node.exe (Join-Path $PSScriptRoot 'publish-update.mjs') (Join-Path $taskApp 'dist') (Join-Path $taskApp 'dist/resolved-config.json') $taskRuntime if ($LASTEXITCODE) { throw 'Local signed development update staging failed' } } finally { foreach ($taskName in @('OTA_PRIVATE_KEY','OTA_CERTIFICATE')) { Remove-Item -LiteralPath "Env:$taskName" -ErrorAction SilentlyContinue } }