release(desktop): Release v1.6.0 (#4970)
* docs(mobile): prepare release changelog * release(mobile): release v0.4.1 * fix(ssr): route dist-external assets (#4956) * fix(cli): close login callback sockets (#4957) * fix(ci): sync release branches to dev via pull request * fix(mobile): increase ai summary font size * fix(desktop): improve pdf export layout and branding * fix(mobile): refresh social login state * fix: correct French translation language detection * build(deps): bump android-actions/setup-android from 3 to 4 (#4929) Bumps [android-actions/setup-android](https://github.com/android-actions/setup-android) from 3 to 4. - [Release notes](https://github.com/android-actions/setup-android/releases) - [Commits](https://github.com/android-actions/setup-android/compare/v3...v4) --- updated-dependencies: - dependency-name: android-actions/setup-android dependency-version: '4' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix(ai-chat): show reset date for future credits * feat: refine spotlight settings and highlighting * feat: add spotlight settings across desktop and mobile * build(deps): bump actions/github-script from 8 to 9 (#4961) Bumps [actions/github-script](https://github.com/actions/github-script) from 8 to 9. - [Release notes](https://github.com/actions/github-script/releases) - [Commits](https://github.com/actions/github-script/compare/v8...v9) --- updated-dependencies: - dependency-name: actions/github-script dependency-version: '9' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump signpath/github-action-submit-signing-request (#4960) Bumps [signpath/github-action-submit-signing-request](https://github.com/signpath/github-action-submit-signing-request) from 2.0 to 2.1. - [Release notes](https://github.com/signpath/github-action-submit-signing-request/releases) - [Commits](https://github.com/signpath/github-action-submit-signing-request/compare/v2.0...v2.1) --- updated-dependencies: - dependency-name: signpath/github-action-submit-signing-request dependency-version: '2.1' dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix(mobile): avoid YouTube embed error on iOS close #4958 * fix(mobile): patch fmt for Xcode 26.4 builds * build(deps): bump pnpm/action-setup from 4 to 5 (#4922) Bumps [pnpm/action-setup](https://github.com/pnpm/action-setup) from 4 to 5. - [Release notes](https://github.com/pnpm/action-setup/releases) - [Commits](https://github.com/pnpm/action-setup/compare/v4...v5) --- updated-dependencies: - dependency-name: pnpm/action-setup dependency-version: '5' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feat(desktop): migrate tts to folo service * docs(ota): add OTA service design spec * feat(ota): scaffold Cloudflare worker app * fix(ota): align scaffold with task spec * fix(ota): use standard worker types * fix(ota): tighten scaffold schema and dev config * fix(ota): require at least one platform * fix(ota): use dev env for local wrangler * docs(ota): add implementation plan and release scoping * chore(ota): update lockfile for worker deps * feat(ota): add release selection primitives * test(ota): cover incompatible newer release selection * fix(ota): tighten release compatibility checks * fix(ota): reject empty platform payloads * feat(ota): add kv helpers and policy logic * fix(ota): enforce min binary store policy * feat(ota): fetch OTA releases from GitHub * fix(ota): return GitHub release etags * feat(ota): mirror release payloads into R2 * fix(ota): stream mirrored archive extraction * fix(ota): verify mirrored asset hashes * feat(ota): serve manifests assets and policy * fix(ota): harden manifest and policy routes * fix(ota): validate route semver inputs * fix(ota): verify manifest pointer version * feat(ota): add sync orchestration routes * fix(ota): dedupe concurrent sync passes * feat(mobile): enable OTA background updates * fix(mobile): restore OTA provider typecheck * feat(mobile): add streaming tts playback * fix(mobile): align OTA provider state * feat(mobile): add ota policy client and debug controls * fix(mobile): harden ota policy and debug controls * test(mobile): cover ota provider helpers * ci(desktop): automate Mac App Store pkg upload * feat(ota): generate release assets from mobile export * test(mobile): fix ota provider test typing * test(mobile): discover ota script test via explicit config * fix: tighten OTA release asset metadata handling * fix: require OTA platform asset arrays * ci(ota): publish releases and trigger sync * fix(ci): harden ota publish workflow * ci(ota): tighten trailer validation * docs(ota): add rollout and rollback runbook * feat(mobile): upgrade expo sdk 55 and rnfirebase * fix(ota): emit expo-compatible update identifiers * fix(ota): support private GitHub release assets * fix(mobile): unblock ios archive on expo sdk 55 * build(deps): bump pnpm/action-setup from 5 to 6 (#4962) Bumps [pnpm/action-setup](https://github.com/pnpm/action-setup) from 5 to 6. - [Release notes](https://github.com/pnpm/action-setup/releases) - [Commits](https://github.com/pnpm/action-setup/compare/v5...v6) --- updated-dependencies: - dependency-name: pnpm/action-setup dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * fix(ci): restore ota typing and tailwind config compatibility * test(mobile): fix ota provider test typing * chore(ota): persist production cloudflare bindings * fix(ci): restore semver types and ota test mocks * feat(release): drive mobile release mode from config files * fix(ota): sign manifests and pin runtime version * fix(ci): disable frozen lockfile for local eas builds * docs(spec): add desktop ota unification design * feat(ota): unify desktop updates with ota service * fix(ota): harden desktop sync and updater flow * docs(skill): update desktop release workflow * fix(release): repair ota and desktop update flows * feat: cache storefront versions for ota policy * feat: expose ota version badges * feat: expose ota version badges * fix: backfill github version badges * fix: backfill github version badges * docs(skills): align release modes with implementation * fix: update Discord invite link in README.md * fix: update macOS and Windows app store links in README.md * fix: update GitHub badge labels in README.md * build(deps): bump actions/download-artifact from 5 to 8 (#4969) Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 5 to 8. - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/v5...v8) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-version: '8' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * build(deps): bump softprops/action-gh-release from 2 to 3 (#4968) Bumps [softprops/action-gh-release](https://github.com/softprops/action-gh-release) from 2 to 3. - [Release notes](https://github.com/softprops/action-gh-release/releases) - [Changelog](https://github.com/softprops/action-gh-release/blob/master/CHANGELOG.md) - [Commits](https://github.com/softprops/action-gh-release/compare/v2...v3) --- updated-dependencies: - dependency-name: softprops/action-gh-release dependency-version: '3' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * docs(release): prepare desktop and mobile release metadata * release(desktop): release v1.6.0 * fix(desktop): restore spotlight settings sync * fix(desktop): apply spotlight highlights in entry rendering * fix(desktop): extend spotlight highlight coverage --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
dependabot[bot]
parent
b469f07029
commit
bfbce383a2
@@ -0,0 +1,925 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { spawn, spawnSync } from "node:child_process"
|
||||
import { createHash } from "node:crypto"
|
||||
import { existsSync, readdirSync, readFileSync, statSync } from "node:fs"
|
||||
import { mkdir, readFile, writeFile } from "node:fs/promises"
|
||||
import { fileURLToPath } from "node:url"
|
||||
|
||||
import yaml from "js-yaml"
|
||||
import { dirname, extname, join, resolve } from "pathe"
|
||||
|
||||
const SCRIPT_DIR = dirname(fileURLToPath(import.meta.url))
|
||||
const REPO_ROOT = resolve(SCRIPT_DIR, "..", "..")
|
||||
const DEFAULT_MOBILE_PROJECT_DIR = join(REPO_ROOT, "apps", "mobile")
|
||||
const DEFAULT_DESKTOP_PROJECT_DIR = join(REPO_ROOT, "apps", "desktop")
|
||||
const OTA_PLATFORMS = ["ios", "android"]
|
||||
const DESKTOP_PLATFORMS = new Set(["macos", "windows", "linux"])
|
||||
const DESKTOP_DEFAULT_CHANNEL = "stable"
|
||||
const CONTENT_TYPES = new Map([
|
||||
[".aac", "audio/aac"],
|
||||
[".bmp", "image/bmp"],
|
||||
[".bundle", "application/javascript"],
|
||||
[".css", "text/css"],
|
||||
[".gif", "image/gif"],
|
||||
[".gz", "application/gzip"],
|
||||
[".hbc", "application/javascript"],
|
||||
[".html", "text/html"],
|
||||
[".jpeg", "image/jpeg"],
|
||||
[".jpg", "image/jpeg"],
|
||||
[".js", "application/javascript"],
|
||||
[".json", "application/json"],
|
||||
[".m4a", "audio/mp4"],
|
||||
[".mp3", "audio/mpeg"],
|
||||
[".mp4", "video/mp4"],
|
||||
[".otf", "font/otf"],
|
||||
[".pdf", "application/pdf"],
|
||||
[".png", "image/png"],
|
||||
[".svg", "image/svg+xml"],
|
||||
[".ttf", "font/ttf"],
|
||||
[".txt", "text/plain; charset=utf-8"],
|
||||
[".wav", "audio/wav"],
|
||||
[".webm", "video/webm"],
|
||||
[".webp", "image/webp"],
|
||||
[".woff", "font/woff"],
|
||||
[".woff2", "font/woff2"],
|
||||
[".xml", "application/xml"],
|
||||
])
|
||||
const DESKTOP_MANIFEST_FILE_NAMES = new Set(["latest.yml", "latest-mac.yml", "latest-linux.yml"])
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* path: string
|
||||
* ext?: string
|
||||
* }} ExportAssetMetadata
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* path: string
|
||||
* sha256: string
|
||||
* contentType: string
|
||||
* }} OtaAsset
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* bundle: string
|
||||
* assets?: unknown[]
|
||||
* }} ExportPlatformMetadata
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* fileMetadata?: Partial<Record<"ios" | "android", ExportPlatformMetadata>>
|
||||
* }} ExportMetadata
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* product: string
|
||||
* channel: string
|
||||
* releaseVersion: string
|
||||
* releaseKind: string
|
||||
* runtimeVersion: string
|
||||
* gitTag: string
|
||||
* gitCommit: string
|
||||
* publishedAt: string
|
||||
* policy: {
|
||||
* storeRequired: boolean
|
||||
* minSupportedBinaryVersion: string
|
||||
* message: string | null
|
||||
* }
|
||||
* metadata: ExportMetadata
|
||||
* resolveAsset: (asset: ExportAssetMetadata) => Promise<OtaAsset>
|
||||
* }} BuildOtaMetadataInput
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {BuildOtaMetadataInput} input
|
||||
*/
|
||||
export async function buildOtaMetadata(input) {
|
||||
/** @type {Record<string, { launchAsset: OtaAsset, assets: OtaAsset[] }>} */
|
||||
const platforms = {}
|
||||
|
||||
if (input.releaseKind === "ota") {
|
||||
const fileMetadata = resolveExportFileMetadata(input.metadata)
|
||||
|
||||
for (const platform of OTA_PLATFORMS) {
|
||||
const platformMetadata = resolvePlatformMetadata(fileMetadata, platform)
|
||||
const launchAsset = { path: normalizeAssetPath(platformMetadata.bundle) }
|
||||
const assets = collectAssets(platformMetadata.assets, platform)
|
||||
|
||||
platforms[platform] = {
|
||||
launchAsset: await input.resolveAsset(launchAsset),
|
||||
assets: await Promise.all(assets.map((asset) => input.resolveAsset(asset))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
schemaVersion: 1,
|
||||
updateId: createDeterministicUuid(
|
||||
`${input.product}:${input.channel}:${input.releaseVersion}:${input.runtimeVersion}:${input.gitTag}:${input.gitCommit}`,
|
||||
),
|
||||
product: input.product,
|
||||
channel: input.channel,
|
||||
releaseVersion: input.releaseVersion,
|
||||
releaseKind: input.releaseKind,
|
||||
runtimeVersion: input.runtimeVersion,
|
||||
publishedAt: input.publishedAt,
|
||||
git: {
|
||||
tag: input.gitTag,
|
||||
commit: input.gitCommit,
|
||||
},
|
||||
policy: input.policy,
|
||||
platforms,
|
||||
}
|
||||
}
|
||||
|
||||
function createDeterministicUuid(seed) {
|
||||
const digest = createHash("sha1").update(seed).digest()
|
||||
const bytes = Buffer.from(digest.subarray(0, 16))
|
||||
|
||||
bytes[6] = (bytes[6] & 0x0f) | 0x50
|
||||
bytes[8] = (bytes[8] & 0x3f) | 0x80
|
||||
|
||||
const hex = bytes.toString("hex")
|
||||
return [
|
||||
hex.slice(0, 8),
|
||||
hex.slice(8, 12),
|
||||
hex.slice(12, 16),
|
||||
hex.slice(16, 20),
|
||||
hex.slice(20, 32),
|
||||
].join("-")
|
||||
}
|
||||
|
||||
export async function buildReleaseAssets(options = {}) {
|
||||
const projectDir = resolveMobileProjectDir(options.projectDir)
|
||||
const distDir = join(projectDir, "dist")
|
||||
const metadataPath = join(distDir, "metadata.json")
|
||||
const archivePath = join(projectDir, "dist.tar.zst")
|
||||
|
||||
const packageJson = await readJson(join(projectDir, "package.json"))
|
||||
const product = process.env.OTA_PRODUCT ?? "mobile"
|
||||
const channel = process.env.OTA_CHANNEL ?? "production"
|
||||
const releaseVersion = process.env.OTA_RELEASE_VERSION ?? packageJson.version
|
||||
const releaseKind = process.env.OTA_RELEASE_KIND ?? "ota"
|
||||
const runtimeVersion = process.env.OTA_RUNTIME_VERSION ?? packageJson.version
|
||||
const gitTag = process.env.OTA_GIT_TAG ?? `${product}/v${releaseVersion}`
|
||||
const gitCommit = process.env.OTA_GIT_COMMIT ?? execGit(["rev-parse", "HEAD"], REPO_ROOT)
|
||||
const publishedAt = process.env.OTA_PUBLISHED_AT ?? new Date().toISOString()
|
||||
|
||||
if (releaseKind === "ota" && !existsSync(metadataPath)) {
|
||||
throw new Error(
|
||||
`Missing Expo export metadata at ${metadataPath}. Run "pnpm --dir apps/mobile run update:export" first.`,
|
||||
)
|
||||
}
|
||||
|
||||
const metadata = releaseKind === "ota" ? await readJson(metadataPath) : { fileMetadata: {} }
|
||||
|
||||
const otaMetadata = await buildOtaMetadata({
|
||||
product,
|
||||
channel,
|
||||
releaseVersion,
|
||||
releaseKind,
|
||||
runtimeVersion,
|
||||
gitTag,
|
||||
gitCommit,
|
||||
publishedAt,
|
||||
policy: {
|
||||
storeRequired: parseBooleanEnv("OTA_STORE_REQUIRED", false),
|
||||
minSupportedBinaryVersion: process.env.OTA_MIN_SUPPORTED_BINARY_VERSION ?? runtimeVersion,
|
||||
message: parseNullableEnv("OTA_POLICY_MESSAGE"),
|
||||
},
|
||||
metadata,
|
||||
resolveAsset: async (asset) => {
|
||||
const assetFilePath = join(distDir, asset.path)
|
||||
let assetBuffer
|
||||
|
||||
try {
|
||||
assetBuffer = await readFile(assetFilePath)
|
||||
} catch (error) {
|
||||
const reason = error instanceof Error ? error.message : String(error)
|
||||
throw new Error(
|
||||
`Failed to read exported asset "${asset.path}" at ${assetFilePath}: ${reason}`,
|
||||
)
|
||||
}
|
||||
|
||||
return {
|
||||
path: asset.path,
|
||||
sha256: createHash("sha256").update(assetBuffer).digest("hex"),
|
||||
contentType: resolveContentType(asset),
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
const outputPath = join(distDir, "ota-release.json")
|
||||
|
||||
await mkdir(distDir, { recursive: true })
|
||||
await writeFile(outputPath, `${JSON.stringify(otaMetadata, null, 2)}\n`, "utf8")
|
||||
|
||||
if (releaseKind === "ota") {
|
||||
await createTarZstArchive({ distDir, archivePath })
|
||||
}
|
||||
|
||||
return {
|
||||
projectDir,
|
||||
distDir,
|
||||
metadataPath,
|
||||
outputPath,
|
||||
archivePath: releaseKind === "ota" ? archivePath : null,
|
||||
otaMetadata,
|
||||
}
|
||||
}
|
||||
|
||||
export async function buildDesktopReleaseAssets(options = {}) {
|
||||
const projectDir = resolveDesktopProjectDir(options.projectDir)
|
||||
const distDir = join(projectDir, "dist")
|
||||
const outputPath = join(distDir, "ota-release.json")
|
||||
const archivePath = join(projectDir, "dist.tar.zst")
|
||||
const releaseConfig = await readJson(join(projectDir, "release.json"))
|
||||
const packageJson = await readJson(join(projectDir, "package.json"))
|
||||
const releaseVersion = releaseConfig.version ?? packageJson.version
|
||||
const product = process.env.OTA_PRODUCT ?? "desktop"
|
||||
const gitTag = process.env.OTA_GIT_TAG ?? `${product}/v${releaseVersion}`
|
||||
const gitCommit = process.env.OTA_GIT_COMMIT ?? execGit(["rev-parse", "HEAD"], REPO_ROOT)
|
||||
const publishedAt = process.env.OTA_PUBLISHED_AT ?? new Date().toISOString()
|
||||
const [owner, repo] = resolveRepository(options)
|
||||
const releaseKind = releaseConfig.mode === "ota" ? "ota" : "binary"
|
||||
const runtimeVersion = releaseConfig.mode === "ota" ? releaseConfig.runtimeVersion : null
|
||||
const channel = releaseConfig.channel ?? DESKTOP_DEFAULT_CHANNEL
|
||||
const desktopApp = await collectDesktopAppPayload({
|
||||
projectDir,
|
||||
owner,
|
||||
repo,
|
||||
gitTag,
|
||||
})
|
||||
|
||||
if (!desktopApp) {
|
||||
throw new Error(
|
||||
`Desktop ${releaseConfig.mode} mode requires direct installer manifests in ${join(projectDir, "out", "make")}`,
|
||||
)
|
||||
}
|
||||
const desktopRenderer =
|
||||
releaseConfig.mode === "ota"
|
||||
? await collectDesktopRendererPayload({
|
||||
projectDir,
|
||||
owner,
|
||||
repo,
|
||||
gitTag,
|
||||
})
|
||||
: null
|
||||
|
||||
await mkdir(distDir, { recursive: true })
|
||||
|
||||
const otaMetadata = {
|
||||
schemaVersion: 2,
|
||||
product,
|
||||
channel,
|
||||
releaseVersion,
|
||||
releaseKind,
|
||||
runtimeVersion,
|
||||
publishedAt,
|
||||
git: {
|
||||
tag: gitTag,
|
||||
commit: gitCommit,
|
||||
},
|
||||
policy: {
|
||||
required: false,
|
||||
minSupportedBinaryVersion: process.env.OTA_MIN_SUPPORTED_BINARY_VERSION ?? releaseVersion,
|
||||
message: null,
|
||||
distributions: {},
|
||||
},
|
||||
desktop: {
|
||||
renderer: desktopRenderer,
|
||||
app: desktopApp,
|
||||
},
|
||||
}
|
||||
|
||||
await writeFile(outputPath, `${JSON.stringify(otaMetadata, null, 2)}\n`, "utf8")
|
||||
|
||||
if (releaseConfig.mode === "ota") {
|
||||
await createTarZstArchive({ distDir, archivePath })
|
||||
}
|
||||
|
||||
return {
|
||||
projectDir,
|
||||
distDir,
|
||||
outputPath,
|
||||
archivePath: releaseConfig.mode === "ota" ? archivePath : null,
|
||||
otaMetadata,
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
const result =
|
||||
(process.env.OTA_PRODUCT ?? "mobile") === "desktop"
|
||||
? await buildDesktopReleaseAssets()
|
||||
: await buildReleaseAssets()
|
||||
|
||||
console.info(`Wrote OTA metadata: ${result.outputPath}`)
|
||||
if (result.archivePath) {
|
||||
console.info(`Wrote OTA archive: ${result.archivePath}`)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error instanceof Error ? error.message : String(error))
|
||||
process.exitCode = 1
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {unknown} value
|
||||
*/
|
||||
function resolveExportFileMetadata(metadata) {
|
||||
if (!metadata || typeof metadata !== "object") {
|
||||
throw new Error("Expo export metadata is missing fileMetadata")
|
||||
}
|
||||
|
||||
if (!metadata.fileMetadata || typeof metadata.fileMetadata !== "object") {
|
||||
throw new Error("Expo export metadata is missing fileMetadata")
|
||||
}
|
||||
|
||||
return metadata.fileMetadata
|
||||
}
|
||||
|
||||
function resolvePlatformMetadata(fileMetadata, platform) {
|
||||
const platformMetadata = fileMetadata[platform]
|
||||
|
||||
if (!platformMetadata || typeof platformMetadata !== "object") {
|
||||
throw new Error(`Expo export metadata is missing ${platform} platform metadata`)
|
||||
}
|
||||
|
||||
if (typeof platformMetadata.bundle !== "string" || platformMetadata.bundle.length === 0) {
|
||||
throw new Error(`Expo export metadata is missing ${platform} bundle metadata`)
|
||||
}
|
||||
|
||||
return platformMetadata
|
||||
}
|
||||
|
||||
function collectAssets(value, platform) {
|
||||
if (value == null) {
|
||||
throw new TypeError(`Expo export metadata is missing ${platform} assets metadata`)
|
||||
}
|
||||
|
||||
if (!Array.isArray(value)) {
|
||||
throw new TypeError(`Expo export metadata has invalid ${platform} assets metadata`)
|
||||
}
|
||||
|
||||
/** @type {Map<string, ExportAssetMetadata>} */
|
||||
const dedupedAssets = new Map()
|
||||
|
||||
for (const asset of value) {
|
||||
const normalizedAsset = normalizeExportAsset(asset)
|
||||
const existingAsset = dedupedAssets.get(normalizedAsset.path)
|
||||
|
||||
if (!existingAsset || (!existingAsset.ext && normalizedAsset.ext)) {
|
||||
dedupedAssets.set(normalizedAsset.path, normalizedAsset)
|
||||
continue
|
||||
}
|
||||
|
||||
if (existingAsset.ext && normalizedAsset.ext && existingAsset.ext !== normalizedAsset.ext) {
|
||||
throw new Error(
|
||||
`Expo export metadata has conflicting ext values for asset "${normalizedAsset.path}"`,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
return [...dedupedAssets.values()]
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {unknown} asset
|
||||
*/
|
||||
function normalizeExportAsset(asset) {
|
||||
if (typeof asset === "string") {
|
||||
return { path: normalizeAssetPath(asset) }
|
||||
}
|
||||
|
||||
if (!asset || typeof asset !== "object") {
|
||||
throw new Error(`Unsupported Expo asset metadata entry: ${JSON.stringify(asset)}`)
|
||||
}
|
||||
|
||||
const assetPath =
|
||||
"path" in asset && typeof asset.path === "string"
|
||||
? asset.path
|
||||
: "file" in asset && typeof asset.file === "string"
|
||||
? asset.file
|
||||
: null
|
||||
|
||||
if (!assetPath) {
|
||||
throw new Error(`Unsupported Expo asset metadata entry: ${JSON.stringify(asset)}`)
|
||||
}
|
||||
|
||||
return {
|
||||
path: normalizeAssetPath(assetPath),
|
||||
...("ext" in asset && asset.ext != null ? { ext: normalizeAssetExtension(asset.ext) } : {}),
|
||||
}
|
||||
}
|
||||
|
||||
function normalizeAssetExtension(ext) {
|
||||
if (typeof ext !== "string") {
|
||||
throw new TypeError(`Unsupported Expo asset ext metadata: ${JSON.stringify(ext)}`)
|
||||
}
|
||||
|
||||
const normalizedExt = ext.trim().replace(/^\.+/, "").toLowerCase()
|
||||
|
||||
if (!normalizedExt) {
|
||||
throw new Error(`Invalid exported asset ext "${ext}"`)
|
||||
}
|
||||
|
||||
return normalizedExt
|
||||
}
|
||||
|
||||
function resolveMobileProjectDir(projectDir) {
|
||||
if (projectDir) {
|
||||
return resolve(projectDir)
|
||||
}
|
||||
|
||||
const cwd = resolve(process.cwd())
|
||||
|
||||
if (existsSync(join(cwd, "package.json")) && existsSync(join(cwd, "scripts", "expo-update.ts"))) {
|
||||
return cwd
|
||||
}
|
||||
|
||||
if (existsSync(join(cwd, "apps", "mobile", "package.json"))) {
|
||||
return join(cwd, "apps", "mobile")
|
||||
}
|
||||
|
||||
return DEFAULT_MOBILE_PROJECT_DIR
|
||||
}
|
||||
|
||||
function resolveDesktopProjectDir(projectDir) {
|
||||
if (projectDir) {
|
||||
return resolve(projectDir)
|
||||
}
|
||||
|
||||
const cwd = resolve(process.cwd())
|
||||
|
||||
if (existsSync(join(cwd, "package.json")) && existsSync(join(cwd, "release.json"))) {
|
||||
return cwd
|
||||
}
|
||||
|
||||
if (existsSync(join(cwd, "apps", "desktop", "package.json"))) {
|
||||
return join(cwd, "apps", "desktop")
|
||||
}
|
||||
|
||||
return DEFAULT_DESKTOP_PROJECT_DIR
|
||||
}
|
||||
|
||||
function normalizeAssetPath(assetPath) {
|
||||
const normalized = assetPath
|
||||
.replaceAll("\\", "/")
|
||||
.replace(/^\/+/, "")
|
||||
.replace(/^(\.\/)+/, "")
|
||||
.replaceAll(/\/{2,}/g, "/")
|
||||
|
||||
if (!normalized || normalized.split("/").includes("..")) {
|
||||
throw new Error(`Invalid exported asset path "${assetPath}"`)
|
||||
}
|
||||
|
||||
return normalized
|
||||
}
|
||||
|
||||
function resolveContentType(asset) {
|
||||
const normalizedPath = String(asset.path).toLowerCase()
|
||||
const pathExtension = normalizedPath.endsWith(".tar.gz")
|
||||
? ".gz"
|
||||
: extname(normalizedPath).toLowerCase()
|
||||
const metadataExtension = asset.ext ? `.${asset.ext}` : ""
|
||||
const extension = pathExtension || metadataExtension
|
||||
|
||||
return CONTENT_TYPES.get(extension) ?? "application/octet-stream"
|
||||
}
|
||||
|
||||
async function createTarZstArchive({ distDir, archivePath }) {
|
||||
const zstdBinary = resolveZstdBinary()
|
||||
|
||||
await new Promise((resolvePromise, rejectPromise) => {
|
||||
let tarExited = false
|
||||
let zstdExited = false
|
||||
|
||||
const tarProcess = spawn("tar", ["-cf", "-", "-C", distDir, "."], {
|
||||
stdio: ["ignore", "pipe", "inherit"],
|
||||
})
|
||||
const zstdProcess = spawn(zstdBinary, ["-q", "-f", "-o", archivePath], {
|
||||
stdio: ["pipe", "inherit", "inherit"],
|
||||
})
|
||||
|
||||
const rejectOnce = once((error) => rejectPromise(error))
|
||||
const resolveIfComplete = () => {
|
||||
if (tarExited && zstdExited) {
|
||||
resolvePromise(void 0)
|
||||
}
|
||||
}
|
||||
|
||||
tarProcess.on("error", (error) => {
|
||||
rejectOnce(new Error(`Failed to run tar: ${error.message}`))
|
||||
})
|
||||
zstdProcess.on("error", (error) => {
|
||||
rejectOnce(new Error(`Failed to run zstd: ${error.message}`))
|
||||
})
|
||||
|
||||
tarProcess.stdout.on("error", (error) => {
|
||||
rejectOnce(new Error(`Failed to stream tar output: ${error.message}`))
|
||||
})
|
||||
zstdProcess.stdin.on("error", (error) => {
|
||||
rejectOnce(new Error(`Failed to stream zstd input: ${error.message}`))
|
||||
})
|
||||
|
||||
tarProcess.stdout.pipe(zstdProcess.stdin)
|
||||
|
||||
tarProcess.on("close", (code) => {
|
||||
if (code !== 0) {
|
||||
rejectOnce(new Error(`tar exited with code ${code}`))
|
||||
return
|
||||
}
|
||||
|
||||
tarExited = true
|
||||
resolveIfComplete()
|
||||
})
|
||||
|
||||
zstdProcess.on("close", (code) => {
|
||||
if (code !== 0) {
|
||||
rejectOnce(new Error(`zstd exited with code ${code}`))
|
||||
return
|
||||
}
|
||||
|
||||
zstdExited = true
|
||||
resolveIfComplete()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function resolveZstdBinary() {
|
||||
const candidates = [process.env.ZSTD_BIN, "zstd", "/opt/homebrew/bin/zstd"].filter(Boolean)
|
||||
|
||||
for (const candidate of candidates) {
|
||||
const args = candidate === "/opt/homebrew/bin/zstd" ? ["--version"] : ["--version"]
|
||||
const result = spawnSync(candidate, args, { stdio: "ignore" })
|
||||
|
||||
if (result.status === 0) {
|
||||
return candidate
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error('Unable to find "zstd". Set ZSTD_BIN or install zstd in PATH.')
|
||||
}
|
||||
|
||||
function execGit(args, cwd) {
|
||||
const result = spawnSync("git", args, {
|
||||
cwd,
|
||||
encoding: "utf8",
|
||||
})
|
||||
|
||||
if (result.status !== 0) {
|
||||
throw new Error(result.stderr?.trim() || `git ${args.join(" ")} failed`)
|
||||
}
|
||||
|
||||
return result.stdout.trim()
|
||||
}
|
||||
|
||||
async function readJson(path) {
|
||||
try {
|
||||
return JSON.parse(await readFile(path, "utf8"))
|
||||
} catch (error) {
|
||||
const reason = error instanceof Error ? error.message : String(error)
|
||||
throw new Error(`Failed to read JSON at ${path}: ${reason}`)
|
||||
}
|
||||
}
|
||||
|
||||
async function collectDesktopRendererPayload(input) {
|
||||
const rendererManifestPath = join(input.projectDir, "dist", "manifest.yml")
|
||||
|
||||
if (!existsSync(rendererManifestPath)) {
|
||||
throw new Error(`Missing desktop renderer manifest at ${rendererManifestPath}`)
|
||||
}
|
||||
|
||||
const rendererManifest = parseYamlFile(rendererManifestPath)
|
||||
|
||||
if (typeof rendererManifest.version !== "string" || !rendererManifest.version) {
|
||||
throw new Error(`Desktop renderer manifest at ${rendererManifestPath} is missing version`)
|
||||
}
|
||||
|
||||
if (typeof rendererManifest.commit !== "string" || !rendererManifest.commit) {
|
||||
throw new Error(`Desktop renderer manifest at ${rendererManifestPath} is missing commit`)
|
||||
}
|
||||
|
||||
const filename =
|
||||
typeof rendererManifest.filename === "string" && rendererManifest.filename
|
||||
? rendererManifest.filename
|
||||
: "render-asset.tar.gz"
|
||||
const rendererArchivePath = join(input.projectDir, "dist", filename)
|
||||
|
||||
if (!existsSync(rendererArchivePath)) {
|
||||
throw new Error(`Missing desktop renderer archive at ${rendererArchivePath}`)
|
||||
}
|
||||
|
||||
return {
|
||||
version: rendererManifest.version,
|
||||
commit: rendererManifest.commit,
|
||||
manifest: {
|
||||
name: "manifest.yml",
|
||||
downloadUrl: buildGitHubAssetUrl({
|
||||
owner: input.owner,
|
||||
repo: input.repo,
|
||||
tag: input.gitTag,
|
||||
filename: "manifest.yml",
|
||||
}),
|
||||
},
|
||||
launchAsset: await resolveFileAsset({
|
||||
sourcePath: rendererArchivePath,
|
||||
metadataPath: filename,
|
||||
}),
|
||||
assets: [],
|
||||
}
|
||||
}
|
||||
|
||||
async function collectDesktopAppPayload(input) {
|
||||
const makeDir = join(input.projectDir, "out", "make")
|
||||
|
||||
if (!existsSync(makeDir)) {
|
||||
return null
|
||||
}
|
||||
|
||||
const platformEntries = await collectDesktopPlatformEntries({
|
||||
makeDir,
|
||||
owner: input.owner,
|
||||
repo: input.repo,
|
||||
gitTag: input.gitTag,
|
||||
})
|
||||
|
||||
if (Object.keys(platformEntries).length === 0) {
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
platforms: platformEntries,
|
||||
}
|
||||
}
|
||||
|
||||
async function collectDesktopPlatformEntries(input) {
|
||||
/** @type {Record<string, any>} */
|
||||
const result = {}
|
||||
|
||||
for (const manifestPath of walkFiles(input.makeDir)) {
|
||||
const fileName = manifestPath.split("/").at(-1)
|
||||
if (!fileName || !DESKTOP_MANIFEST_FILE_NAMES.has(fileName)) {
|
||||
continue
|
||||
}
|
||||
|
||||
const manifest = parseYamlFile(manifestPath)
|
||||
const platformKey = inferDesktopPlatformKey(manifestPath, fileName)
|
||||
|
||||
if (!platformKey || !DESKTOP_PLATFORMS.has(platformKey)) {
|
||||
continue
|
||||
}
|
||||
|
||||
const files = normalizeDesktopManifestFiles(manifest.files, manifestPath)
|
||||
if (files.length === 0) {
|
||||
continue
|
||||
}
|
||||
|
||||
const nextEntry = {
|
||||
platform: inferDesktopPlatformIdentifier(platformKey, manifestPath),
|
||||
releaseDate: normalizeDesktopReleaseDate(manifest.releaseDate),
|
||||
manifest: {
|
||||
name: fileName,
|
||||
path: fileName,
|
||||
downloadUrl: buildGitHubAssetUrl({
|
||||
owner: input.owner,
|
||||
repo: input.repo,
|
||||
tag: input.gitTag,
|
||||
filename: fileName,
|
||||
}),
|
||||
},
|
||||
files: files.map((file) => ({
|
||||
filename: file.url,
|
||||
sha512: file.sha512,
|
||||
size: file.size,
|
||||
downloadUrl: buildGitHubAssetUrl({
|
||||
owner: input.owner,
|
||||
repo: input.repo,
|
||||
tag: input.gitTag,
|
||||
filename: file.url,
|
||||
}),
|
||||
})),
|
||||
}
|
||||
|
||||
result[platformKey] = result[platformKey]
|
||||
? mergeDesktopPlatformEntries(result[platformKey], nextEntry)
|
||||
: nextEntry
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
function inferDesktopPlatformKey(manifestPath, fileName) {
|
||||
const normalized = manifestPath.replaceAll("\\", "/").toLowerCase()
|
||||
|
||||
if (
|
||||
fileName === "latest-mac.yml" ||
|
||||
normalized.includes("/darwin") ||
|
||||
normalized.includes("/mac")
|
||||
) {
|
||||
return "macos"
|
||||
}
|
||||
|
||||
if (fileName === "latest-linux.yml" || normalized.includes("/linux")) {
|
||||
return "linux"
|
||||
}
|
||||
|
||||
if (
|
||||
fileName === "latest.yml" ||
|
||||
normalized.includes("/windows") ||
|
||||
normalized.includes("/squirrel.windows")
|
||||
) {
|
||||
return "windows"
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
function inferDesktopPlatformIdentifier(platformKey, manifestPath) {
|
||||
const normalized = manifestPath.replaceAll("\\", "/").toLowerCase()
|
||||
const arch = normalized.includes("/arm64") ? "arm64" : normalized.includes("/x64") ? "x64" : null
|
||||
|
||||
if (!arch) {
|
||||
return platformKey
|
||||
}
|
||||
|
||||
return `${platformKey}-${arch}`
|
||||
}
|
||||
|
||||
function normalizeDesktopManifestFiles(files, manifestPath) {
|
||||
if (!Array.isArray(files)) {
|
||||
throw new TypeError(`Desktop manifest at ${manifestPath} is missing files`)
|
||||
}
|
||||
|
||||
return files.map((file, index) => {
|
||||
const url = typeof file?.url === "string" ? file.url : null
|
||||
const sha512 = typeof file?.sha512 === "string" ? file.sha512 : null
|
||||
const size =
|
||||
typeof file?.size === "number" ? file.size : Number.parseInt(String(file?.size ?? 0), 10)
|
||||
|
||||
if (!url || !sha512 || !Number.isFinite(size) || size < 0) {
|
||||
throw new Error(`Desktop manifest at ${manifestPath} has invalid files[${index}] entry`)
|
||||
}
|
||||
|
||||
return {
|
||||
url,
|
||||
sha512,
|
||||
size,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function normalizeDesktopReleaseDate(value) {
|
||||
if (typeof value === "string") {
|
||||
return value
|
||||
}
|
||||
|
||||
if (value instanceof Date) {
|
||||
return value.toISOString()
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
function mergeDesktopPlatformEntries(currentEntry, nextEntry) {
|
||||
const fileByName = new Map(currentEntry.files.map((file) => [file.filename, file]))
|
||||
|
||||
for (const file of nextEntry.files) {
|
||||
fileByName.set(file.filename, file)
|
||||
}
|
||||
|
||||
const mergedReleaseDate = pickLatestReleaseDate(currentEntry.releaseDate, nextEntry.releaseDate)
|
||||
|
||||
return {
|
||||
platform:
|
||||
currentEntry.platform === nextEntry.platform
|
||||
? currentEntry.platform
|
||||
: (currentEntry.platform.split("-")[0] ?? currentEntry.platform),
|
||||
releaseDate: mergedReleaseDate,
|
||||
manifest: currentEntry.manifest,
|
||||
files: [...fileByName.values()],
|
||||
}
|
||||
}
|
||||
|
||||
function pickLatestReleaseDate(currentValue, nextValue) {
|
||||
const currentTime = currentValue ? Date.parse(currentValue) : Number.NaN
|
||||
const nextTime = nextValue ? Date.parse(nextValue) : Number.NaN
|
||||
|
||||
if (Number.isFinite(currentTime) && Number.isFinite(nextTime)) {
|
||||
return currentTime >= nextTime ? currentValue : nextValue
|
||||
}
|
||||
|
||||
return nextValue ?? currentValue ?? null
|
||||
}
|
||||
|
||||
function parseYamlFile(path) {
|
||||
try {
|
||||
const content = readFileSync(path, "utf8")
|
||||
return yaml.load(String(content)) ?? {}
|
||||
} catch (error) {
|
||||
const reason = error instanceof Error ? error.message : String(error)
|
||||
throw new Error(`Failed to parse YAML at ${path}: ${reason}`)
|
||||
}
|
||||
}
|
||||
|
||||
async function resolveFileAsset(input) {
|
||||
const buffer = await readFile(input.sourcePath)
|
||||
return {
|
||||
path: normalizeAssetPath(input.metadataPath),
|
||||
sha256: createHash("sha256").update(buffer).digest("hex"),
|
||||
contentType: resolveContentType({ path: input.metadataPath }),
|
||||
}
|
||||
}
|
||||
|
||||
function buildGitHubAssetUrl({ owner, repo, tag, filename }) {
|
||||
return `https://github.com/${owner}/${repo}/releases/download/${tag}/${filename}`
|
||||
}
|
||||
|
||||
function resolveRepository(options) {
|
||||
if (options.owner && options.repo) {
|
||||
return [options.owner, options.repo]
|
||||
}
|
||||
|
||||
const repository = process.env.GITHUB_REPOSITORY
|
||||
if (repository && repository.includes("/")) {
|
||||
return repository.split("/", 2)
|
||||
}
|
||||
|
||||
return ["RSSNext", "Folo"]
|
||||
}
|
||||
|
||||
function walkFiles(rootDir) {
|
||||
/** @type {string[]} */
|
||||
const results = []
|
||||
/** @type {string[]} */
|
||||
const pending = [rootDir]
|
||||
|
||||
while (pending.length > 0) {
|
||||
const current = pending.pop()
|
||||
if (!current) continue
|
||||
|
||||
for (const entryName of readdirSync(current)) {
|
||||
const entry = join(current, entryName)
|
||||
if (!existsSync(entry)) continue
|
||||
|
||||
if (statSync(entry).isDirectory()) {
|
||||
pending.push(entry)
|
||||
} else {
|
||||
results.push(entry)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results.sort()
|
||||
}
|
||||
|
||||
function parseBooleanEnv(name, defaultValue) {
|
||||
const value = process.env[name]
|
||||
|
||||
if (value == null) {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
if (value === "1" || value.toLowerCase() === "true") {
|
||||
return true
|
||||
}
|
||||
|
||||
if (value === "0" || value.toLowerCase() === "false") {
|
||||
return false
|
||||
}
|
||||
|
||||
throw new Error(`${name} must be "true", "false", "1", or "0"`)
|
||||
}
|
||||
|
||||
function parseNullableEnv(name) {
|
||||
const value = process.env[name]
|
||||
|
||||
if (value == null || value.length === 0) {
|
||||
return null
|
||||
}
|
||||
|
||||
return value
|
||||
}
|
||||
|
||||
function once(callback) {
|
||||
let called = false
|
||||
|
||||
return (...args) => {
|
||||
if (called) {
|
||||
return
|
||||
}
|
||||
|
||||
called = true
|
||||
callback(...args)
|
||||
}
|
||||
}
|
||||
|
||||
if (process.argv[1] && fileURLToPath(import.meta.url) === resolve(process.argv[1])) {
|
||||
await main()
|
||||
}
|
||||
@@ -0,0 +1,640 @@
|
||||
import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises"
|
||||
import { tmpdir } from "node:os"
|
||||
|
||||
import { join } from "pathe"
|
||||
import { afterEach, describe, expect, it } from "vitest"
|
||||
|
||||
type InputAsset = string | { path: string; ext?: string }
|
||||
|
||||
const tempDirs: string[] = []
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
tempDirs.splice(0).map((directory) => rm(directory, { recursive: true, force: true })),
|
||||
)
|
||||
delete process.env.OTA_RELEASE_KIND
|
||||
delete process.env.OTA_RELEASE_VERSION
|
||||
delete process.env.OTA_RUNTIME_VERSION
|
||||
delete process.env.OTA_CHANNEL
|
||||
delete process.env.OTA_PRODUCT
|
||||
delete process.env.OTA_GIT_TAG
|
||||
delete process.env.OTA_GIT_COMMIT
|
||||
delete process.env.OTA_PUBLISHED_AT
|
||||
delete process.env.OTA_STORE_REQUIRED
|
||||
delete process.env.GITHUB_REPOSITORY
|
||||
})
|
||||
|
||||
describe("buildOtaMetadata", () => {
|
||||
it("preserves releaseVersion, runtimeVersion, and scoped git tag", async () => {
|
||||
const { buildOtaMetadata } = await import("./build-ota-release.mjs")
|
||||
|
||||
const result = await buildOtaMetadata({
|
||||
product: "mobile",
|
||||
channel: "production",
|
||||
releaseVersion: "0.4.2",
|
||||
releaseKind: "ota",
|
||||
runtimeVersion: "0.4.1",
|
||||
gitTag: "mobile/v0.4.2",
|
||||
gitCommit: "abcdef1234567890",
|
||||
publishedAt: "2026-04-10T12:00:00.000Z",
|
||||
policy: {
|
||||
storeRequired: false,
|
||||
minSupportedBinaryVersion: "0.4.1",
|
||||
message: null,
|
||||
},
|
||||
metadata: {
|
||||
fileMetadata: {
|
||||
ios: {
|
||||
bundle: "_expo/static/js/ios/main.hbc",
|
||||
assets: [],
|
||||
},
|
||||
android: {
|
||||
bundle: "_expo/static/js/android/main.hbc",
|
||||
assets: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
resolveAsset: async (asset: InputAsset) => {
|
||||
const assetPath = typeof asset === "string" ? asset : asset.path
|
||||
|
||||
return {
|
||||
path: assetPath,
|
||||
sha256: `${assetPath}-sha256`.padEnd(64, "0").slice(0, 64),
|
||||
contentType: "application/octet-stream",
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
expect(result.releaseVersion).toBe("0.4.2")
|
||||
expect(result.runtimeVersion).toBe("0.4.1")
|
||||
expect(result.git.tag).toBe("mobile/v0.4.2")
|
||||
expect(result.updateId).toMatch(
|
||||
/^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/,
|
||||
)
|
||||
})
|
||||
|
||||
it("uses asset ext metadata when exported asset paths have no suffix", async () => {
|
||||
const { buildOtaMetadata } = await import("./build-ota-release.mjs")
|
||||
|
||||
const result = await buildOtaMetadata({
|
||||
product: "mobile",
|
||||
channel: "production",
|
||||
releaseVersion: "0.4.2",
|
||||
releaseKind: "ota",
|
||||
runtimeVersion: "0.4.1",
|
||||
gitTag: "mobile/v0.4.2",
|
||||
gitCommit: "abcdef1234567890",
|
||||
publishedAt: "2026-04-10T12:00:00.000Z",
|
||||
policy: {
|
||||
storeRequired: false,
|
||||
minSupportedBinaryVersion: "0.4.1",
|
||||
message: null,
|
||||
},
|
||||
metadata: {
|
||||
fileMetadata: {
|
||||
ios: {
|
||||
bundle: "_expo/static/js/ios/main.hbc",
|
||||
assets: [{ path: "assets/splash", ext: "png" }],
|
||||
},
|
||||
android: {
|
||||
bundle: "_expo/static/js/android/main.hbc",
|
||||
assets: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
resolveAsset: async (asset: InputAsset) => {
|
||||
const assetPath = typeof asset === "string" ? asset : asset.path
|
||||
const ext = typeof asset === "string" ? undefined : asset.ext
|
||||
|
||||
return {
|
||||
path: assetPath,
|
||||
sha256: `${assetPath}-sha256`.padEnd(64, "0").slice(0, 64),
|
||||
contentType: ext === "png" ? "image/png" : "application/octet-stream",
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
expect(result.platforms.ios.assets).toEqual([
|
||||
expect.objectContaining({
|
||||
path: "assets/splash",
|
||||
contentType: "image/png",
|
||||
}),
|
||||
])
|
||||
})
|
||||
|
||||
it("fails when a platform bundle is missing from export metadata", async () => {
|
||||
const { buildOtaMetadata } = await import("./build-ota-release.mjs")
|
||||
|
||||
await expect(
|
||||
buildOtaMetadata({
|
||||
product: "mobile",
|
||||
channel: "production",
|
||||
releaseVersion: "0.4.2",
|
||||
releaseKind: "ota",
|
||||
runtimeVersion: "0.4.1",
|
||||
gitTag: "mobile/v0.4.2",
|
||||
gitCommit: "abcdef1234567890",
|
||||
publishedAt: "2026-04-10T12:00:00.000Z",
|
||||
policy: {
|
||||
storeRequired: false,
|
||||
minSupportedBinaryVersion: "0.4.1",
|
||||
message: null,
|
||||
},
|
||||
metadata: {
|
||||
fileMetadata: {
|
||||
ios: {
|
||||
bundle: "_expo/static/js/ios/main.hbc",
|
||||
assets: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
resolveAsset: async (asset: InputAsset) => {
|
||||
const assetPath = typeof asset === "string" ? asset : asset.path
|
||||
|
||||
return {
|
||||
path: assetPath,
|
||||
sha256: `${assetPath}-sha256`.padEnd(64, "0").slice(0, 64),
|
||||
contentType: "application/octet-stream",
|
||||
}
|
||||
},
|
||||
}),
|
||||
).rejects.toThrow(/android/i)
|
||||
})
|
||||
|
||||
it("fails when a platform assets array is missing from export metadata", async () => {
|
||||
const { buildOtaMetadata } = await import("./build-ota-release.mjs")
|
||||
|
||||
await expect(
|
||||
buildOtaMetadata({
|
||||
product: "mobile",
|
||||
channel: "production",
|
||||
releaseVersion: "0.4.2",
|
||||
releaseKind: "ota",
|
||||
runtimeVersion: "0.4.1",
|
||||
gitTag: "mobile/v0.4.2",
|
||||
gitCommit: "abcdef1234567890",
|
||||
publishedAt: "2026-04-10T12:00:00.000Z",
|
||||
policy: {
|
||||
storeRequired: false,
|
||||
minSupportedBinaryVersion: "0.4.1",
|
||||
message: null,
|
||||
},
|
||||
metadata: {
|
||||
fileMetadata: {
|
||||
ios: {
|
||||
bundle: "_expo/static/js/ios/main.hbc",
|
||||
},
|
||||
android: {
|
||||
bundle: "_expo/static/js/android/main.hbc",
|
||||
assets: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
resolveAsset: async (asset: InputAsset) => {
|
||||
const assetPath = typeof asset === "string" ? asset : asset.path
|
||||
|
||||
return {
|
||||
path: assetPath,
|
||||
sha256: `${assetPath}-sha256`.padEnd(64, "0").slice(0, 64),
|
||||
contentType: "application/octet-stream",
|
||||
}
|
||||
},
|
||||
}),
|
||||
).rejects.toThrow(/ios.*assets/i)
|
||||
})
|
||||
|
||||
it("deduplicates repeated asset entries after path normalization", async () => {
|
||||
const { buildOtaMetadata } = await import("./build-ota-release.mjs")
|
||||
|
||||
const resolvedAssets: InputAsset[] = []
|
||||
|
||||
const result = await buildOtaMetadata({
|
||||
product: "mobile",
|
||||
channel: "production",
|
||||
releaseVersion: "0.4.2",
|
||||
releaseKind: "ota",
|
||||
runtimeVersion: "0.4.1",
|
||||
gitTag: "mobile/v0.4.2",
|
||||
gitCommit: "abcdef1234567890",
|
||||
publishedAt: "2026-04-10T12:00:00.000Z",
|
||||
policy: {
|
||||
storeRequired: false,
|
||||
minSupportedBinaryVersion: "0.4.1",
|
||||
message: null,
|
||||
},
|
||||
metadata: {
|
||||
fileMetadata: {
|
||||
ios: {
|
||||
bundle: "_expo/static/js/ios/main.hbc",
|
||||
assets: ["./assets/icon.png", { path: "assets/icon.png" }],
|
||||
},
|
||||
android: {
|
||||
bundle: "_expo/static/js/android/main.hbc",
|
||||
assets: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
resolveAsset: async (asset: InputAsset) => {
|
||||
resolvedAssets.push(asset)
|
||||
const assetPath = typeof asset === "string" ? asset : asset.path
|
||||
|
||||
return {
|
||||
path: assetPath,
|
||||
sha256: `${assetPath}-sha256`.padEnd(64, "0").slice(0, 64),
|
||||
contentType: "image/png",
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
expect(result.platforms.ios.assets).toHaveLength(1)
|
||||
expect(
|
||||
resolvedAssets.filter((asset) => {
|
||||
const assetPath = typeof asset === "string" ? asset : asset.path
|
||||
|
||||
return assetPath === "assets/icon.png"
|
||||
}),
|
||||
).toHaveLength(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe("buildReleaseAssets", () => {
|
||||
it("builds metadata-only assets for store releases without Expo export output", async () => {
|
||||
const { buildReleaseAssets } = await import("./build-ota-release.mjs")
|
||||
|
||||
const projectDir = await mkdtemp(join(tmpdir(), "build-ota-release-store-test-"))
|
||||
tempDirs.push(projectDir)
|
||||
|
||||
await writeFile(
|
||||
join(projectDir, "package.json"),
|
||||
JSON.stringify({ name: "@follow/mobile-test", version: "0.4.3" }),
|
||||
"utf8",
|
||||
)
|
||||
|
||||
process.env.OTA_RELEASE_KIND = "store"
|
||||
process.env.OTA_RELEASE_VERSION = "0.4.3"
|
||||
process.env.OTA_RUNTIME_VERSION = "0.4.3"
|
||||
process.env.OTA_CHANNEL = "production"
|
||||
process.env.OTA_STORE_REQUIRED = "true"
|
||||
|
||||
const result = await buildReleaseAssets({ projectDir })
|
||||
|
||||
expect(result.otaMetadata.releaseKind).toBe("store")
|
||||
expect(result.otaMetadata.policy.storeRequired).toBe(true)
|
||||
expect(result.otaMetadata.platforms).toEqual({})
|
||||
expect(result.archivePath).toBeNull()
|
||||
})
|
||||
|
||||
it("includes the JSON file path when export metadata cannot be parsed", async () => {
|
||||
const { buildReleaseAssets } = await import("./build-ota-release.mjs")
|
||||
|
||||
const projectDir = await mkdtemp(join(tmpdir(), "build-ota-release-test-"))
|
||||
const distDir = join(projectDir, "dist")
|
||||
const metadataPath = join(distDir, "metadata.json")
|
||||
tempDirs.push(projectDir)
|
||||
|
||||
await mkdir(distDir, { recursive: true })
|
||||
await writeFile(
|
||||
join(projectDir, "package.json"),
|
||||
JSON.stringify({ name: "@follow/mobile-test", version: "0.4.2" }),
|
||||
"utf8",
|
||||
)
|
||||
await writeFile(metadataPath, "{invalid", "utf8")
|
||||
|
||||
await expect(buildReleaseAssets({ projectDir })).rejects.toThrow(metadataPath)
|
||||
})
|
||||
})
|
||||
|
||||
describe("buildDesktopReleaseAssets", () => {
|
||||
it("builds schemaVersion 2 desktop build metadata with direct app payloads only", async () => {
|
||||
const { buildDesktopReleaseAssets } = await import("./build-ota-release.mjs")
|
||||
const projectDir = await createDesktopProjectFixture({
|
||||
version: "1.5.1",
|
||||
releaseConfig: {
|
||||
version: "1.5.1",
|
||||
mode: "build",
|
||||
runtimeVersion: null,
|
||||
channel: null,
|
||||
},
|
||||
manifests: [
|
||||
{
|
||||
relativeDir: join("out", "make", "squirrel.windows", "x64"),
|
||||
manifestName: "latest.yml",
|
||||
contents: `
|
||||
version: 1.5.1
|
||||
files:
|
||||
- url: Folo-1.5.1-windows-x64.exe
|
||||
sha512: ${"a".repeat(88)}
|
||||
size: 123456
|
||||
releaseDate: 2026-04-11T10:00:00.000Z
|
||||
`,
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const result = await buildDesktopReleaseAssets({
|
||||
projectDir,
|
||||
owner: "RSSNext",
|
||||
repo: "Folo",
|
||||
})
|
||||
|
||||
expect(result.otaMetadata.schemaVersion).toBe(2)
|
||||
expect(result.otaMetadata.product).toBe("desktop")
|
||||
expect(result.otaMetadata.releaseKind).toBe("binary")
|
||||
expect(result.otaMetadata.runtimeVersion).toBeNull()
|
||||
expect(result.otaMetadata.channel).toBe("stable")
|
||||
expect(result.otaMetadata.desktop.renderer).toBeNull()
|
||||
expect(result.otaMetadata.policy.distributions).toEqual({})
|
||||
expect(result.otaMetadata.desktop.app.platforms.windows).toEqual(
|
||||
expect.objectContaining({
|
||||
platform: "windows-x64",
|
||||
releaseDate: "2026-04-11T10:00:00.000Z",
|
||||
manifest: {
|
||||
name: "latest.yml",
|
||||
path: "latest.yml",
|
||||
downloadUrl: expect.stringContaining("/desktop/v1.5.1/latest.yml"),
|
||||
},
|
||||
files: [
|
||||
expect.objectContaining({
|
||||
filename: "Folo-1.5.1-windows-x64.exe",
|
||||
sha512: "a".repeat(88),
|
||||
size: 123456,
|
||||
downloadUrl: expect.stringContaining("/desktop/v1.5.1/Folo-1.5.1-windows-x64.exe"),
|
||||
}),
|
||||
],
|
||||
}),
|
||||
)
|
||||
expect(result.archivePath).toBeNull()
|
||||
|
||||
const written = JSON.parse(await readFile(result.outputPath, "utf8"))
|
||||
expect(written.schemaVersion).toBe(2)
|
||||
expect(written.desktop.renderer).toBeNull()
|
||||
})
|
||||
|
||||
it("builds schemaVersion 2 desktop ota metadata with renderer and direct app payloads", async () => {
|
||||
const { buildDesktopReleaseAssets } = await import("./build-ota-release.mjs")
|
||||
const projectDir = await createDesktopProjectFixture({
|
||||
version: "1.5.1",
|
||||
releaseConfig: {
|
||||
version: "1.5.1",
|
||||
mode: "ota",
|
||||
runtimeVersion: "1.5.0",
|
||||
channel: "stable",
|
||||
},
|
||||
rendererArchiveContents: "renderer archive",
|
||||
rendererManifestContents: `
|
||||
version: 1.5.1
|
||||
hash: ${"b".repeat(64)}
|
||||
mainHash: ${"c".repeat(40)}
|
||||
commit: abcdef1234567890
|
||||
filename: custom-renderer.tar.gz
|
||||
`,
|
||||
manifests: [
|
||||
{
|
||||
relativeDir: join("out", "make", "squirrel.windows", "x64"),
|
||||
manifestName: "latest.yml",
|
||||
contents: `
|
||||
version: 1.5.1
|
||||
files:
|
||||
- url: Folo-1.5.1-windows-x64.exe
|
||||
sha512: ${"d".repeat(88)}
|
||||
size: 654321
|
||||
releaseDate: 2026-04-11T10:00:00.000Z
|
||||
`,
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const result = await buildDesktopReleaseAssets({
|
||||
projectDir,
|
||||
owner: "RSSNext",
|
||||
repo: "Folo",
|
||||
})
|
||||
|
||||
expect(result.otaMetadata.schemaVersion).toBe(2)
|
||||
expect(result.otaMetadata.releaseKind).toBe("ota")
|
||||
expect(result.otaMetadata.runtimeVersion).toBe("1.5.0")
|
||||
expect(result.otaMetadata.channel).toBe("stable")
|
||||
expect(result.otaMetadata.desktop.renderer).toEqual(
|
||||
expect.objectContaining({
|
||||
version: "1.5.1",
|
||||
commit: "abcdef1234567890",
|
||||
manifest: {
|
||||
name: "manifest.yml",
|
||||
downloadUrl:
|
||||
"https://github.com/RSSNext/Folo/releases/download/desktop/v1.5.1/manifest.yml",
|
||||
},
|
||||
launchAsset: expect.objectContaining({
|
||||
path: "custom-renderer.tar.gz",
|
||||
contentType: "application/gzip",
|
||||
}),
|
||||
}),
|
||||
)
|
||||
expect(result.otaMetadata.desktop.renderer.launchAsset.sha256).toHaveLength(64)
|
||||
expect(result.otaMetadata.desktop.app.platforms.windows.files[0]?.downloadUrl).toContain(
|
||||
"/desktop/v1.5.1/Folo-1.5.1-windows-x64.exe",
|
||||
)
|
||||
expect(result.archivePath).not.toBeNull()
|
||||
})
|
||||
|
||||
it("fails when a desktop manifest contains an invalid file entry", async () => {
|
||||
const { buildDesktopReleaseAssets } = await import("./build-ota-release.mjs")
|
||||
const projectDir = await createDesktopProjectFixture({
|
||||
version: "1.5.1",
|
||||
releaseConfig: {
|
||||
version: "1.5.1",
|
||||
mode: "build",
|
||||
runtimeVersion: null,
|
||||
channel: null,
|
||||
},
|
||||
manifests: [
|
||||
{
|
||||
relativeDir: join("out", "make", "squirrel.windows", "x64"),
|
||||
manifestName: "latest.yml",
|
||||
contents: `
|
||||
version: 1.5.1
|
||||
files:
|
||||
- url: Folo-1.5.1-windows-x64.exe
|
||||
size: 123456
|
||||
releaseDate: 2026-04-11T10:00:00.000Z
|
||||
`,
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
await expect(
|
||||
buildDesktopReleaseAssets({
|
||||
projectDir,
|
||||
owner: "RSSNext",
|
||||
repo: "Folo",
|
||||
}),
|
||||
).rejects.toThrow(/invalid files\[0\] entry/i)
|
||||
})
|
||||
|
||||
it("fails for build mode when direct installer manifests are missing", async () => {
|
||||
const { buildDesktopReleaseAssets } = await import("./build-ota-release.mjs")
|
||||
const projectDir = await createDesktopProjectFixture({
|
||||
version: "1.5.1",
|
||||
releaseConfig: {
|
||||
version: "1.5.1",
|
||||
mode: "build",
|
||||
runtimeVersion: null,
|
||||
channel: null,
|
||||
},
|
||||
})
|
||||
|
||||
await expect(
|
||||
buildDesktopReleaseAssets({
|
||||
projectDir,
|
||||
owner: "RSSNext",
|
||||
repo: "Folo",
|
||||
}),
|
||||
).rejects.toThrow(/requires direct installer manifests/i)
|
||||
})
|
||||
|
||||
it("fails for ota mode when direct installer manifests are missing", async () => {
|
||||
const { buildDesktopReleaseAssets } = await import("./build-ota-release.mjs")
|
||||
const projectDir = await createDesktopProjectFixture({
|
||||
version: "1.5.1",
|
||||
releaseConfig: {
|
||||
version: "1.5.1",
|
||||
mode: "ota",
|
||||
runtimeVersion: "1.5.0",
|
||||
channel: "stable",
|
||||
},
|
||||
rendererArchiveContents: "renderer archive",
|
||||
rendererManifestContents: `
|
||||
version: 1.5.1
|
||||
hash: ${"2".repeat(64)}
|
||||
mainHash: ${"3".repeat(40)}
|
||||
commit: abcdef1234567890
|
||||
filename: custom-renderer.tar.gz
|
||||
`,
|
||||
})
|
||||
|
||||
await expect(
|
||||
buildDesktopReleaseAssets({
|
||||
projectDir,
|
||||
owner: "RSSNext",
|
||||
repo: "Folo",
|
||||
}),
|
||||
).rejects.toThrow(/requires direct installer manifests/i)
|
||||
})
|
||||
|
||||
it("merges duplicate desktop platform manifests instead of overwriting them", async () => {
|
||||
const { buildDesktopReleaseAssets } = await import("./build-ota-release.mjs")
|
||||
const projectDir = await createDesktopProjectFixture({
|
||||
version: "1.5.1",
|
||||
releaseConfig: {
|
||||
version: "1.5.1",
|
||||
mode: "build",
|
||||
runtimeVersion: null,
|
||||
channel: null,
|
||||
},
|
||||
manifests: [
|
||||
{
|
||||
relativeDir: join("out", "make", "squirrel.windows", "x64"),
|
||||
manifestName: "latest.yml",
|
||||
contents: `
|
||||
version: 1.5.1
|
||||
files:
|
||||
- url: Folo-1.5.1-windows-x64.exe
|
||||
sha512: ${"e".repeat(88)}
|
||||
size: 123456
|
||||
releaseDate: 2026-04-11T10:00:00.000Z
|
||||
`,
|
||||
},
|
||||
{
|
||||
relativeDir: join("out", "make", "squirrel.windows", "arm64"),
|
||||
manifestName: "latest.yml",
|
||||
contents: `
|
||||
version: 1.5.1
|
||||
files:
|
||||
- url: Folo-1.5.1-windows-arm64.exe
|
||||
sha512: ${"f".repeat(88)}
|
||||
size: 234567
|
||||
releaseDate: 2026-04-11T11:00:00.000Z
|
||||
`,
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const result = await buildDesktopReleaseAssets({
|
||||
projectDir,
|
||||
owner: "RSSNext",
|
||||
repo: "Folo",
|
||||
})
|
||||
|
||||
expect(result.otaMetadata.desktop.app.platforms.windows.files).toHaveLength(2)
|
||||
expect(result.otaMetadata.desktop.app.platforms.windows.releaseDate).toBe(
|
||||
"2026-04-11T11:00:00.000Z",
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
async function createDesktopProjectFixture(input: {
|
||||
version: string
|
||||
releaseConfig: {
|
||||
version: string
|
||||
mode: "build" | "ota"
|
||||
runtimeVersion: string | null
|
||||
channel: "stable" | "beta" | "alpha" | null
|
||||
}
|
||||
manifests?: Array<{
|
||||
relativeDir: string
|
||||
manifestName: string
|
||||
contents: string
|
||||
}>
|
||||
rendererArchiveContents?: string
|
||||
rendererManifestContents?: string
|
||||
}) {
|
||||
const projectDir = await mkdtemp(join(tmpdir(), "build-ota-release-desktop-test-"))
|
||||
tempDirs.push(projectDir)
|
||||
|
||||
await writeFile(
|
||||
join(projectDir, "package.json"),
|
||||
JSON.stringify({ name: "@follow/desktop-test", version: input.version }),
|
||||
"utf8",
|
||||
)
|
||||
await writeFile(
|
||||
join(projectDir, "release.json"),
|
||||
`${JSON.stringify(input.releaseConfig, null, 2)}\n`,
|
||||
"utf8",
|
||||
)
|
||||
|
||||
if (input.rendererArchiveContents != null || input.rendererManifestContents != null) {
|
||||
await mkdir(join(projectDir, "dist"), { recursive: true })
|
||||
}
|
||||
|
||||
if (input.rendererArchiveContents != null) {
|
||||
await writeFile(
|
||||
join(
|
||||
projectDir,
|
||||
"dist",
|
||||
input.rendererManifestContents?.includes("custom-renderer.tar.gz")
|
||||
? "custom-renderer.tar.gz"
|
||||
: "render-asset.tar.gz",
|
||||
),
|
||||
input.rendererArchiveContents,
|
||||
"utf8",
|
||||
)
|
||||
}
|
||||
|
||||
if (input.rendererManifestContents != null) {
|
||||
await writeFile(
|
||||
join(projectDir, "dist", "manifest.yml"),
|
||||
input.rendererManifestContents.trimStart(),
|
||||
"utf8",
|
||||
)
|
||||
}
|
||||
|
||||
for (const manifest of input.manifests ?? []) {
|
||||
await mkdir(join(projectDir, manifest.relativeDir), { recursive: true })
|
||||
await writeFile(
|
||||
join(projectDir, manifest.relativeDir, manifest.manifestName),
|
||||
manifest.contents.trimStart(),
|
||||
"utf8",
|
||||
)
|
||||
}
|
||||
|
||||
return projectDir
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { appendFileSync } from "node:fs"
|
||||
import { readFile } from "node:fs/promises"
|
||||
import { pathToFileURL } from "node:url"
|
||||
|
||||
const SEMVER_PATTERN = /^\d+\.\d+\.\d+$/
|
||||
const VALID_MODES = new Set(["build", "ota"])
|
||||
const VALID_CHANNELS = new Set(["stable", "beta", "alpha"])
|
||||
|
||||
export function resolveDesktopReleaseConfig(input) {
|
||||
const normalizedReleaseVersion = input.releaseVersion.replace(/^v/, "")
|
||||
const config = input.releaseConfig
|
||||
|
||||
if (config.version !== normalizedReleaseVersion) {
|
||||
throw new Error(
|
||||
`apps/desktop/release.json version ${config.version} does not match release version ${normalizedReleaseVersion}.`,
|
||||
)
|
||||
}
|
||||
|
||||
if (!VALID_MODES.has(config.mode)) {
|
||||
throw new Error("apps/desktop/release.json mode must be build or ota.")
|
||||
}
|
||||
|
||||
if (config.mode === "build") {
|
||||
if (config.runtimeVersion !== null || config.channel !== null) {
|
||||
throw new Error("desktop build mode must not set runtimeVersion or channel")
|
||||
}
|
||||
|
||||
return {
|
||||
triggerDirectBuild: true,
|
||||
triggerStoreBuilds: true,
|
||||
runtimeVersion: null,
|
||||
channel: null,
|
||||
releaseVersion: normalizedReleaseVersion,
|
||||
}
|
||||
}
|
||||
|
||||
if (config.mode === "ota") {
|
||||
if (!config.runtimeVersion || !SEMVER_PATTERN.test(config.runtimeVersion)) {
|
||||
throw new Error("apps/desktop/release.json runtimeVersion must be a plain x.y.z version.")
|
||||
}
|
||||
|
||||
if (!config.channel || !VALID_CHANNELS.has(config.channel)) {
|
||||
throw new Error("apps/desktop/release.json channel must be stable, beta, or alpha.")
|
||||
}
|
||||
|
||||
return {
|
||||
triggerDirectBuild: true,
|
||||
triggerStoreBuilds: true,
|
||||
runtimeVersion: config.runtimeVersion,
|
||||
channel: config.channel,
|
||||
releaseVersion: normalizedReleaseVersion,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function readReleaseConfig(path) {
|
||||
const raw = await readFile(path, "utf8")
|
||||
return JSON.parse(raw)
|
||||
}
|
||||
|
||||
function setGitHubOutput(key, value) {
|
||||
if (!process.env.GITHUB_OUTPUT) {
|
||||
return
|
||||
}
|
||||
|
||||
const delimiter = `__GITHUB_OUTPUT_${key}_${Date.now()}_${Math.random().toString(16).slice(2)}__`
|
||||
appendFileSync(process.env.GITHUB_OUTPUT, `${key}<<${delimiter}\n${value}\n${delimiter}\n`)
|
||||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
const configPath = process.env.RELEASE_CONFIG_PATH ?? "apps/desktop/release.json"
|
||||
const releaseConfig = await readReleaseConfig(configPath)
|
||||
const result = resolveDesktopReleaseConfig({
|
||||
releaseVersion: process.env.RELEASE_VERSION ?? "",
|
||||
releaseConfig,
|
||||
})
|
||||
|
||||
setGitHubOutput("triggerDirectBuild", String(result.triggerDirectBuild))
|
||||
setGitHubOutput("triggerStoreBuilds", String(result.triggerStoreBuilds))
|
||||
setGitHubOutput("runtimeVersion", result.runtimeVersion ?? "")
|
||||
setGitHubOutput("channel", result.channel ?? "")
|
||||
setGitHubOutput("releaseVersion", result.releaseVersion)
|
||||
} catch (error) {
|
||||
console.error(error instanceof Error ? error.message : String(error))
|
||||
process.exitCode = 1
|
||||
}
|
||||
}
|
||||
|
||||
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
||||
await main()
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
import { execFile } from "node:child_process"
|
||||
import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises"
|
||||
import { tmpdir } from "node:os"
|
||||
import { promisify } from "node:util"
|
||||
|
||||
import { join } from "pathe"
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
const execFileAsync = promisify(execFile)
|
||||
|
||||
describe("resolveDesktopReleaseConfig", () => {
|
||||
it("triggers direct and store builds for build mode", async () => {
|
||||
const { resolveDesktopReleaseConfig } = await import("./resolve-desktop-release-config.mjs")
|
||||
|
||||
expect(
|
||||
resolveDesktopReleaseConfig({
|
||||
releaseVersion: "v1.5.1",
|
||||
releaseConfig: {
|
||||
version: "1.5.1",
|
||||
mode: "build",
|
||||
runtimeVersion: null,
|
||||
channel: null,
|
||||
},
|
||||
}),
|
||||
).toEqual({
|
||||
triggerDirectBuild: true,
|
||||
triggerStoreBuilds: true,
|
||||
runtimeVersion: null,
|
||||
channel: null,
|
||||
releaseVersion: "1.5.1",
|
||||
})
|
||||
})
|
||||
|
||||
it("triggers direct and store builds for ota mode", async () => {
|
||||
const { resolveDesktopReleaseConfig } = await import("./resolve-desktop-release-config.mjs")
|
||||
|
||||
expect(
|
||||
resolveDesktopReleaseConfig({
|
||||
releaseVersion: "v1.5.1",
|
||||
releaseConfig: {
|
||||
version: "1.5.1",
|
||||
mode: "ota",
|
||||
runtimeVersion: "1.5.0",
|
||||
channel: "stable",
|
||||
},
|
||||
}),
|
||||
).toEqual({
|
||||
triggerDirectBuild: true,
|
||||
triggerStoreBuilds: true,
|
||||
runtimeVersion: "1.5.0",
|
||||
channel: "stable",
|
||||
releaseVersion: "1.5.1",
|
||||
})
|
||||
})
|
||||
|
||||
it("rejects a release config that does not match the release version", async () => {
|
||||
const { resolveDesktopReleaseConfig } = await import("./resolve-desktop-release-config.mjs")
|
||||
|
||||
expect(() =>
|
||||
resolveDesktopReleaseConfig({
|
||||
releaseVersion: "v1.5.2",
|
||||
releaseConfig: {
|
||||
version: "1.5.1",
|
||||
mode: "build",
|
||||
runtimeVersion: null,
|
||||
channel: null,
|
||||
},
|
||||
}),
|
||||
).toThrow(/does not match release version/i)
|
||||
})
|
||||
|
||||
it("rejects build mode when runtimeVersion or channel is set", async () => {
|
||||
const { resolveDesktopReleaseConfig } = await import("./resolve-desktop-release-config.mjs")
|
||||
|
||||
expect(() =>
|
||||
resolveDesktopReleaseConfig({
|
||||
releaseVersion: "v1.5.2",
|
||||
releaseConfig: {
|
||||
version: "1.5.2",
|
||||
mode: "build",
|
||||
runtimeVersion: "1.5.1",
|
||||
channel: "stable",
|
||||
},
|
||||
}),
|
||||
).toThrow(/must not set runtimeVersion or channel/i)
|
||||
})
|
||||
|
||||
it("writes GitHub outputs for ota mode", async () => {
|
||||
const projectDir = await mkdtemp(join(tmpdir(), "desktop-release-config-output-"))
|
||||
|
||||
try {
|
||||
const releaseConfigPath = join(projectDir, "release.json")
|
||||
const githubOutputPath = join(projectDir, "github-output.txt")
|
||||
|
||||
await writeFile(
|
||||
releaseConfigPath,
|
||||
`${JSON.stringify(
|
||||
{
|
||||
version: "1.5.2",
|
||||
mode: "ota",
|
||||
runtimeVersion: "1.5.1",
|
||||
channel: "beta",
|
||||
},
|
||||
null,
|
||||
2,
|
||||
)}\n`,
|
||||
"utf8",
|
||||
)
|
||||
|
||||
await execFileAsync("node", [".github/scripts/resolve-desktop-release-config.mjs"], {
|
||||
cwd: process.cwd(),
|
||||
env: {
|
||||
...process.env,
|
||||
RELEASE_VERSION: "1.5.2",
|
||||
RELEASE_CONFIG_PATH: releaseConfigPath,
|
||||
GITHUB_OUTPUT: githubOutputPath,
|
||||
},
|
||||
})
|
||||
|
||||
const output = await readFile(githubOutputPath, "utf8")
|
||||
|
||||
expect(output).toContain("triggerDirectBuild=true")
|
||||
expect(output).toContain("triggerStoreBuilds=true")
|
||||
expect(output).toContain("runtimeVersion<<")
|
||||
expect(output).toContain("1.5.1")
|
||||
expect(output).toContain("channel<<")
|
||||
expect(output).toContain("beta")
|
||||
} finally {
|
||||
await rm(projectDir, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { appendFileSync } from "node:fs"
|
||||
import { readFile } from "node:fs/promises"
|
||||
import { pathToFileURL } from "node:url"
|
||||
|
||||
const SEMVER_PATTERN = /^\d+\.\d+\.\d+$/
|
||||
const VALID_MODES = new Set(["store", "ota"])
|
||||
const VALID_CHANNELS = new Set(["production", "preview"])
|
||||
|
||||
export function resolveMobileReleaseConfig(input) {
|
||||
const normalizedReleaseVersion = input.releaseVersion.replace(/^v/, "")
|
||||
const config = input.releaseConfig
|
||||
|
||||
if (config.version !== normalizedReleaseVersion) {
|
||||
throw new Error(
|
||||
`apps/mobile/release.json version ${config.version} does not match release version ${normalizedReleaseVersion}.`,
|
||||
)
|
||||
}
|
||||
|
||||
if (!VALID_MODES.has(config.mode)) {
|
||||
throw new Error("apps/mobile/release.json mode must be store or ota.")
|
||||
}
|
||||
|
||||
if (config.mode === "store") {
|
||||
return {
|
||||
triggerStoreBuilds: true,
|
||||
triggerOtaPublish: false,
|
||||
runtimeVersion: null,
|
||||
channel: null,
|
||||
releaseVersion: normalizedReleaseVersion,
|
||||
}
|
||||
}
|
||||
|
||||
if (!config.runtimeVersion || !SEMVER_PATTERN.test(config.runtimeVersion)) {
|
||||
throw new Error("apps/mobile/release.json runtimeVersion must be a plain x.y.z version.")
|
||||
}
|
||||
|
||||
if (!config.channel || !VALID_CHANNELS.has(config.channel)) {
|
||||
throw new Error("apps/mobile/release.json channel must be production or preview.")
|
||||
}
|
||||
|
||||
return {
|
||||
triggerStoreBuilds: false,
|
||||
triggerOtaPublish: true,
|
||||
runtimeVersion: config.runtimeVersion,
|
||||
channel: config.channel,
|
||||
releaseVersion: normalizedReleaseVersion,
|
||||
}
|
||||
}
|
||||
|
||||
async function readReleaseConfig(path) {
|
||||
const raw = await readFile(path, "utf8")
|
||||
return JSON.parse(raw)
|
||||
}
|
||||
|
||||
function setGitHubOutput(key, value) {
|
||||
if (!process.env.GITHUB_OUTPUT) {
|
||||
return
|
||||
}
|
||||
|
||||
appendFileSync(process.env.GITHUB_OUTPUT, `${key}=${value}\n`)
|
||||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
const configPath = process.env.RELEASE_CONFIG_PATH ?? "apps/mobile/release.json"
|
||||
const releaseConfig = await readReleaseConfig(configPath)
|
||||
const result = resolveMobileReleaseConfig({
|
||||
releaseVersion: process.env.RELEASE_VERSION ?? "",
|
||||
releaseConfig,
|
||||
})
|
||||
|
||||
setGitHubOutput("trigger_store_builds", String(result.triggerStoreBuilds))
|
||||
setGitHubOutput("trigger_ota_publish", String(result.triggerOtaPublish))
|
||||
setGitHubOutput("runtime_version", result.runtimeVersion ?? "")
|
||||
setGitHubOutput("channel", result.channel ?? "")
|
||||
setGitHubOutput("release_version", result.releaseVersion)
|
||||
} catch (error) {
|
||||
console.error(error instanceof Error ? error.message : String(error))
|
||||
process.exitCode = 1
|
||||
}
|
||||
}
|
||||
|
||||
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
||||
await main()
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
import { describe, expect, it } from "vitest"
|
||||
|
||||
describe("resolveMobileReleaseConfig", () => {
|
||||
it("defaults to store builds when release.json mode is store", async () => {
|
||||
const { resolveMobileReleaseConfig } = await import("./resolve-mobile-release-config.mjs")
|
||||
|
||||
expect(
|
||||
resolveMobileReleaseConfig({
|
||||
releaseVersion: "v0.4.2",
|
||||
releaseConfig: {
|
||||
version: "0.4.2",
|
||||
mode: "store",
|
||||
runtimeVersion: null,
|
||||
channel: null,
|
||||
},
|
||||
}),
|
||||
).toEqual({
|
||||
triggerStoreBuilds: true,
|
||||
triggerOtaPublish: false,
|
||||
runtimeVersion: null,
|
||||
channel: null,
|
||||
releaseVersion: "0.4.2",
|
||||
})
|
||||
})
|
||||
|
||||
it("triggers OTA publish only for ota mode", async () => {
|
||||
const { resolveMobileReleaseConfig } = await import("./resolve-mobile-release-config.mjs")
|
||||
|
||||
expect(
|
||||
resolveMobileReleaseConfig({
|
||||
releaseVersion: "v0.4.2",
|
||||
releaseConfig: {
|
||||
version: "0.4.2",
|
||||
mode: "ota",
|
||||
runtimeVersion: "0.4.1",
|
||||
channel: "production",
|
||||
},
|
||||
}),
|
||||
).toEqual({
|
||||
triggerStoreBuilds: false,
|
||||
triggerOtaPublish: true,
|
||||
runtimeVersion: "0.4.1",
|
||||
channel: "production",
|
||||
releaseVersion: "0.4.2",
|
||||
})
|
||||
})
|
||||
|
||||
it("rejects a release config that does not match the release version", async () => {
|
||||
const { resolveMobileReleaseConfig } = await import("./resolve-mobile-release-config.mjs")
|
||||
|
||||
expect(() =>
|
||||
resolveMobileReleaseConfig({
|
||||
releaseVersion: "v0.4.4",
|
||||
releaseConfig: {
|
||||
version: "0.4.3",
|
||||
mode: "store",
|
||||
runtimeVersion: null,
|
||||
channel: null,
|
||||
},
|
||||
}),
|
||||
).toThrow(/does not match release version/i)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,95 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import { pathToFileURL } from "node:url"
|
||||
|
||||
/**
|
||||
* @typedef {{
|
||||
* baseUrl: string
|
||||
* token: string
|
||||
* headerName: string
|
||||
* timeoutMs?: number
|
||||
* }} TriggerOtaSyncOptions
|
||||
*/
|
||||
|
||||
const DEFAULT_TIMEOUT_MS = 10_000
|
||||
|
||||
/**
|
||||
* @param {TriggerOtaSyncOptions} options
|
||||
*/
|
||||
export async function triggerOtaSync({
|
||||
baseUrl,
|
||||
token,
|
||||
headerName,
|
||||
timeoutMs = DEFAULT_TIMEOUT_MS,
|
||||
}) {
|
||||
if (!baseUrl) {
|
||||
throw new TypeError("OTA base URL is required")
|
||||
}
|
||||
|
||||
if (!token) {
|
||||
throw new TypeError("OTA sync token is required")
|
||||
}
|
||||
|
||||
if (!headerName) {
|
||||
throw new TypeError("OTA sync header name is required")
|
||||
}
|
||||
|
||||
if (!Number.isInteger(timeoutMs) || timeoutMs <= 0) {
|
||||
throw new TypeError("OTA sync timeout must be a positive integer")
|
||||
}
|
||||
|
||||
const normalizedBaseUrl = baseUrl.replace(/\/+$/, "")
|
||||
const controller = new AbortController()
|
||||
const timeoutError = new Error(`Timed out while triggering OTA sync after ${timeoutMs}ms`)
|
||||
const timeoutId = setTimeout(() => {
|
||||
controller.abort(timeoutError)
|
||||
}, timeoutMs)
|
||||
|
||||
try {
|
||||
const response = await fetch(`${normalizedBaseUrl}/internal/sync`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
[headerName]: token,
|
||||
},
|
||||
signal: controller.signal,
|
||||
})
|
||||
|
||||
if (!response.ok) {
|
||||
const responseText = await response.text()
|
||||
const detail = responseText ? `: ${responseText}` : ""
|
||||
|
||||
throw new Error(
|
||||
`Failed to trigger OTA sync (${response.status} ${response.statusText})${detail}`,
|
||||
)
|
||||
}
|
||||
|
||||
return response
|
||||
} catch (error) {
|
||||
if (controller.signal.aborted && controller.signal.reason === timeoutError) {
|
||||
throw timeoutError
|
||||
}
|
||||
|
||||
throw error
|
||||
} finally {
|
||||
clearTimeout(timeoutId)
|
||||
}
|
||||
}
|
||||
|
||||
async function main() {
|
||||
try {
|
||||
await triggerOtaSync({
|
||||
baseUrl: process.env.OTA_BASE_URL ?? "",
|
||||
token: process.env.OTA_SYNC_TOKEN ?? "",
|
||||
headerName: process.env.OTA_SYNC_TOKEN_HEADER ?? "",
|
||||
})
|
||||
|
||||
console.info("Triggered OTA sync successfully")
|
||||
} catch (error) {
|
||||
console.error(error instanceof Error ? error.message : String(error))
|
||||
process.exitCode = 1
|
||||
}
|
||||
}
|
||||
|
||||
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
||||
await main()
|
||||
}
|
||||
@@ -0,0 +1,136 @@
|
||||
import { createServer } from "node:http"
|
||||
|
||||
import { afterEach, describe, expect, it } from "vitest"
|
||||
|
||||
const activeServers = new Set<ReturnType<typeof createServer>>()
|
||||
|
||||
afterEach(async () => {
|
||||
await Promise.all(
|
||||
Array.from(
|
||||
activeServers,
|
||||
(server) =>
|
||||
new Promise<void>((resolve, reject) => {
|
||||
server.close((error) => {
|
||||
if (error) {
|
||||
reject(error)
|
||||
return
|
||||
}
|
||||
|
||||
resolve()
|
||||
})
|
||||
}),
|
||||
),
|
||||
)
|
||||
activeServers.clear()
|
||||
})
|
||||
|
||||
describe("triggerOtaSync", () => {
|
||||
it("POSTs to /internal/sync with the configured auth header", async () => {
|
||||
const requests: Array<{ method?: string; url?: string; headerValue?: string }> = []
|
||||
const headerName = "x-ota-sync-token"
|
||||
const token = "sync-token-value"
|
||||
|
||||
const server = createServer((request, response) => {
|
||||
requests.push({
|
||||
method: request.method,
|
||||
url: request.url,
|
||||
headerValue: request.headers[headerName],
|
||||
})
|
||||
|
||||
response.writeHead(204)
|
||||
response.end()
|
||||
})
|
||||
|
||||
activeServers.add(server)
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
server.once("error", reject)
|
||||
server.listen(0, "127.0.0.1", resolve)
|
||||
})
|
||||
|
||||
const address = server.address()
|
||||
if (!address || typeof address === "string") {
|
||||
throw new TypeError("Expected the test server to bind to an ephemeral TCP port")
|
||||
}
|
||||
|
||||
const { triggerOtaSync } = await import("./trigger-ota-sync.mjs")
|
||||
|
||||
await triggerOtaSync({
|
||||
baseUrl: `http://127.0.0.1:${address.port}`,
|
||||
token,
|
||||
headerName,
|
||||
})
|
||||
|
||||
expect(requests).toEqual([
|
||||
{
|
||||
method: "POST",
|
||||
url: "/internal/sync",
|
||||
headerValue: token,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it("throws when the sync endpoint responds with a non-OK status", async () => {
|
||||
const headerName = "x-ota-sync-token"
|
||||
const token = "sync-token-value"
|
||||
|
||||
const server = createServer((_request, response) => {
|
||||
response.writeHead(503, { "content-type": "text/plain" })
|
||||
response.end("service unavailable")
|
||||
})
|
||||
|
||||
activeServers.add(server)
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
server.once("error", reject)
|
||||
server.listen(0, "127.0.0.1", resolve)
|
||||
})
|
||||
|
||||
const address = server.address()
|
||||
if (!address || typeof address === "string") {
|
||||
throw new TypeError("Expected the test server to bind to an ephemeral TCP port")
|
||||
}
|
||||
|
||||
const { triggerOtaSync } = await import("./trigger-ota-sync.mjs")
|
||||
|
||||
await expect(
|
||||
triggerOtaSync({
|
||||
baseUrl: `http://127.0.0.1:${address.port}`,
|
||||
token,
|
||||
headerName,
|
||||
}),
|
||||
).rejects.toThrow("Failed to trigger OTA sync (503 Service Unavailable): service unavailable")
|
||||
})
|
||||
|
||||
it("aborts the request when the timeout is exceeded", async () => {
|
||||
const headerName = "x-ota-sync-token"
|
||||
const token = "sync-token-value"
|
||||
|
||||
const server = createServer((_request, _response) => {
|
||||
// Intentionally never respond so the client must rely on the timeout.
|
||||
})
|
||||
|
||||
activeServers.add(server)
|
||||
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
server.once("error", reject)
|
||||
server.listen(0, "127.0.0.1", resolve)
|
||||
})
|
||||
|
||||
const address = server.address()
|
||||
if (!address || typeof address === "string") {
|
||||
throw new TypeError("Expected the test server to bind to an ephemeral TCP port")
|
||||
}
|
||||
|
||||
const { triggerOtaSync } = await import("./trigger-ota-sync.mjs")
|
||||
|
||||
await expect(
|
||||
triggerOtaSync({
|
||||
baseUrl: `http://127.0.0.1:${address.port}`,
|
||||
token,
|
||||
headerName,
|
||||
timeoutMs: 25,
|
||||
}),
|
||||
).rejects.toThrow("Timed out while triggering OTA sync after 25ms")
|
||||
})
|
||||
})
|
||||
Executable
+98
@@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
pkg_path="${1:-}"
|
||||
|
||||
if [[ -z "$pkg_path" ]]; then
|
||||
echo "Usage: $0 <pkg-path>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -f "$pkg_path" ]]; then
|
||||
echo "Mac App Store package not found: $pkg_path" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if ! command -v xcrun >/dev/null 2>&1; then
|
||||
echo "xcrun is required to upload a Mac App Store package." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
upload_cmd=(
|
||||
xcrun
|
||||
altool
|
||||
--upload-package
|
||||
"$pkg_path"
|
||||
--wait
|
||||
--show-progress
|
||||
--output-format
|
||||
json
|
||||
)
|
||||
|
||||
if [[ -z "${APPLE_ID:-}" || -z "${APPLE_PASSWORD:-}" ]]; then
|
||||
echo "APPLE_ID and APPLE_PASSWORD must be set." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
upload_cmd+=(
|
||||
-u
|
||||
"$APPLE_ID"
|
||||
-p
|
||||
"@env:APPLE_PASSWORD"
|
||||
)
|
||||
|
||||
run_upload() {
|
||||
local output
|
||||
local exit_code
|
||||
|
||||
set +e
|
||||
output="$("${upload_cmd[@]}" 2>&1)"
|
||||
exit_code=$?
|
||||
set -e
|
||||
|
||||
printf '%s\n' "$output"
|
||||
return "$exit_code"
|
||||
}
|
||||
|
||||
echo "Uploading Mac App Store package with Apple ID: ${pkg_path}"
|
||||
if run_upload; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Upload failed without provider selection. Checking App Store Connect providers..."
|
||||
set +e
|
||||
providers_output="$(
|
||||
xcrun altool --list-providers -u "$APPLE_ID" -p "@env:APPLE_PASSWORD" 2>&1
|
||||
)"
|
||||
providers_exit=$?
|
||||
set -e
|
||||
|
||||
printf '%s\n' "$providers_output"
|
||||
|
||||
if [[ $providers_exit -ne 0 ]]; then
|
||||
echo "Failed to list providers after upload failure." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mapfile -t provider_ids < <(
|
||||
printf '%s\n' "$providers_output" \
|
||||
| perl -ne 'print "$1\n" if /publicid[^[:alnum:]]+([[:alnum:]-]+)/i' \
|
||||
| awk '!seen[$0]++'
|
||||
)
|
||||
|
||||
if [[ ${#provider_ids[@]} -ne 1 ]]; then
|
||||
cat >&2 <<'EOF'
|
||||
Unable to infer a single App Store Connect provider for this Apple ID.
|
||||
Use an Apple ID that only belongs to one provider, or upload once manually to confirm which provider should receive the build.
|
||||
EOF
|
||||
exit 1
|
||||
fi
|
||||
|
||||
upload_cmd+=(
|
||||
--provider-public-id
|
||||
"${provider_ids[0]}"
|
||||
)
|
||||
|
||||
echo "Retrying upload with detected provider: ${provider_ids[0]}"
|
||||
run_upload
|
||||
Reference in New Issue
Block a user