diff --git a/.agents/skills/mobile-release/SKILL.md b/.agents/skills/mobile-release/SKILL.md index 308abb965..240a2055f 100644 --- a/.agents/skills/mobile-release/SKILL.md +++ b/.agents/skills/mobile-release/SKILL.md @@ -1,132 +1,235 @@ --- name: mobile-release -description: Perform a regular mobile release from the dev branch. Gathers commits since last release, updates changelog, bumps version, updates iOS Info.plist, and creates release PR to mobile-main. +description: Use when preparing a mobile release from the dev branch and deciding whether changes should ship through the app stores or through the OTA pipeline before creating the release PR to mobile-main. disable-model-invocation: true allowed-tools: Bash, Read, Write, Edit, Glob, Grep --- -# Mobile Regular Release +# Mobile Release -Perform a regular mobile release. This skill handles the full release workflow from the `dev` branch. +Perform a mobile release from `dev`, with an explicit release-mode decision before the bump. + +The skill must recommend one of these modes, explain why, ask the user to confirm, and then write `apps/mobile/release-plan.json` before running the bump: + +- `store`: normal App Store / Google Play release +- `ota`: OTA-only publish, no store builds +- `store-policy`: metadata-only publish for `/policy`, no store builds + +The CI release flow is file-driven: + +- `apps/mobile/release-plan.json` is the editable plan on `dev` +- `pnpm bump` runs `apps/mobile/scripts/apply-release-config.ts` +- that script writes `apps/mobile/release.json` for the new version and resets the plan back to a safe default +- GitHub Actions reads `apps/mobile/release.json` after merge to decide which pipelines to trigger ## Pre-flight checks 1. Confirm the current branch is `dev`. If not, abort with a warning. -2. Run `git pull --rebase` in the repo root to ensure the local branch is up to date. -3. Read `apps/mobile/package.json` to get the current `version`. +2. Run `git pull --rebase` in the repo root. +3. Read: + - `apps/mobile/package.json` + - `apps/mobile/release-plan.json` + - `.github/workflows/tag.yml` + - `.github/workflows/publish-ota.yml` ## Step 1: Gather changes since last release -1. Find the last release tag (both old `mobile@` and new `mobile/v` prefixes exist): +1. Find the last mobile tag: ```bash git tag --sort=-creatordate | grep -E '^mobile[@/]' | head -1 ``` -2. If no tag found, find the last release commit by matching only the subject line: +2. If no tag exists, fall back to the last release commit subject: ```bash - git log --format="%H %s" | grep "^[a-f0-9]* release(mobile): release v" | head -1 | awk '{print $1}' + git log --format="%H %s" | grep "^[a-f0-9]* release(mobile): Release v" | head -1 | awk '{print $1}' ``` -3. Get all commits since the last release on the current branch: +3. Collect commits since that point: ```bash git log ..HEAD --oneline --no-merges ``` -4. Categorize commits into: - - **Shiny new things** (feat: commits, new features) - - **Improvements** (refactor:, perf:, chore: improvements, dependency updates) - - **No longer broken** (fix: commits, bug fixes) - - **Thanks** (identify external contributor GitHub usernames from commits) +4. Collect changed files: + ```bash + git diff --name-only ..HEAD + ``` +5. Categorize commits into: + - `Shiny new things` + - `Improvements` + - `No longer broken` + - `Thanks` -## Step 2: Update changelog +## Step 2: Recommend a release mode + +### Recommend `store` when: + +- any native or binary-affecting paths changed, for example: + - `apps/mobile/ios/**` + - `apps/mobile/android/**` + - `apps/mobile/native/**` + - `apps/mobile/package.json` + - `apps/mobile/app.config.ts` + - `apps/mobile/app.config.base.ts` + - `apps/mobile/eas.json` + - `apps/mobile/ios/Folo/Info.plist` + - `.github/workflows/build-ios.yml` + - `.github/workflows/build-android.yml` +- Expo / React Native / native dependency changes require a new binary +- permissions, entitlements, icons, splash, Firebase config, or build configuration changed + +### Recommend `ota` when: + +- changes are limited to JS/TS/assets that the current binary can already run +- no native or runtime-affecting paths changed +- the goal is to ship without store review + +### Recommend `store-policy` only when: + +- the user explicitly wants `/policy` to prompt or block older binaries +- no new store binary should be built + +Do not recommend `store-policy` by default for ordinary releases. + +### Determine the target runtime + +If recommending `ota` or `store-policy`, derive the target store binary version from recent `origin/mobile-main` releases and propose it as the `runtimeVersion`. + +If you cannot determine the runtime confidently, stop and ask the user to confirm it. + +### Confirmation gate + +Present: + +- the recommended mode +- rationale based on changed files and commits +- for `ota` or `store-policy`, the proposed `runtimeVersion` +- for `ota` or `store-policy`, the proposed `channel` +- for `store-policy`, whether `/policy` should block (`storeRequired=true`) or just prompt (`storeRequired=false`) + +Wait for explicit user confirmation before continuing. + +## Step 3: Write the release plan file + +Update `apps/mobile/release-plan.json` to match the confirmed mode. + +Examples: + +### Store release + +```json +{ + "mode": "store", + "runtimeVersion": null, + "channel": null, + "storeRequired": false, + "message": null +} +``` + +### OTA release + +```json +{ + "mode": "ota", + "runtimeVersion": "0.4.1", + "channel": "production", + "storeRequired": false, + "message": null +} +``` + +### Store policy release + +```json +{ + "mode": "store-policy", + "runtimeVersion": "0.4.3", + "channel": "production", + "storeRequired": true, + "message": "Install 0.4.3 from the store." +} +``` + +## Step 4: Update changelog 1. Read `apps/mobile/changelog/next.md`. -2. Present the categorized changes to the user and draft the changelog content. +2. Present the categorized changes and draft changelog content. 3. Wait for user confirmation or edits before writing. -4. Write the final content to `apps/mobile/changelog/next.md`, following the template format: +4. Write the final content to `apps/mobile/changelog/next.md`. - ```markdown - # What's New in vNEXT_VERSION +## Step 5: Commit pre-bump files before bump - ## Shiny new things +`nbump` requires a clean working tree. - - description of new feature - - ## Improvements - - - description of improvement - - ## No longer broken - - - description of fix - - ## Thanks - - Special thanks to volunteer contributors @username for their valuable contributions - ``` - -5. Keep `NEXT_VERSION` as the placeholder - it will be replaced by `apply-changelog.ts` during bump. - -## Step 3: Commit changelog updates before bump - -`nbump` requires a clean working tree. Commit changelog edits before running bump. - -1. Stage the changelog update: +1. Stage: ```bash - git add apps/mobile/changelog/next.md + git add apps/mobile/changelog/next.md apps/mobile/release-plan.json ``` -2. Commit it on `dev`: +2. Commit: ```bash - git commit -m "docs(mobile): prepare release changelog" + git commit -m "docs(mobile): prepare release metadata" ``` -3. If there are no changes to commit, continue without creating an extra commit. +3. If nothing changed, continue. -## Step 4: Execute bump +## Step 6: Execute bump -1. Verify working tree is clean before bump: +1. Verify the working tree is clean: ```bash git status --short ``` -2. Change directory to `apps/mobile/` and run the bump: +2. Run: ```bash cd apps/mobile && pnpm bump ``` -3. This is an interactive `nbump` command that prompts for version selection. It will: - - Pull latest changes - - Apply changelog (rename next.md to {version}.md, create new next.md from template) - - Format package.json with eslint + prettier - - Bump version in `package.json` - - Update `ios/Folo/Info.plist`: - - Set `CFBundleShortVersionString` to the new version - - Increment `CFBundleVersion` (build number) by 1 - - Commit with message `release(mobile): release v{NEW_VERSION}` - - Create branch `release/mobile/{NEW_VERSION}` - - Push branch and create PR to `mobile-main` +3. `pnpm bump` will: + - apply changelog + - bump `package.json` + - update `ios/Folo/Info.plist` + - run `tsx scripts/apply-release-config.ts ${NEW_VERSION}` + - write `apps/mobile/release.json` + - reset `apps/mobile/release-plan.json` back to the safe default `store` + - create the release branch + - push the branch + - open a PR to `mobile-main` -## Step 5: Verify +## Step 7: Verify and report -1. Confirm the PR was created successfully by checking the output. -2. Report the new version number and PR URL to the user. -3. Summarize: - - New version: v{NEW_VERSION} - - Changelog highlights +1. Confirm the PR was created successfully. +2. Read `apps/mobile/release.json` on the release branch and report: + - new version + - final release mode + - runtimeVersion and channel if present + - storeRequired and message for `store-policy` - PR URL +3. Summarize expected post-merge automation: -## Post-release (manual steps, inform user) +### `mode=store` -After the release PR is merged to `mobile-main`: +- create mobile tag +- trigger preview Android build +- trigger production Android build +- trigger production iOS build +- no OTA publish -1. **Trigger production builds** via GitHub Actions `workflow_dispatch`: - - Go to "Build iOS" workflow, select `mobile-main` branch, profile = `production` - - Go to "Build Android" workflow, select `mobile-main` branch, profile = `production` -2. Production builds auto-submit to App Store (via `eas submit`) and Google Play (as draft). -3. After submission, go to App Store Connect and Google Play Console to complete the review/release process. +### `mode=ota` -## Reference +- create mobile tag +- trigger OTA publish only +- no store builds + +### `mode=store-policy` + +- create mobile tag +- trigger metadata-only OTA publish +- no store builds + +## References - Bump config: `apps/mobile/bump.config.ts` +- Release plan: `apps/mobile/release-plan.json` +- Release config: `apps/mobile/release.json` +- Apply release config script: `apps/mobile/scripts/apply-release-config.ts` - Changelog dir: `apps/mobile/changelog/` -- Changelog template: `apps/mobile/changelog/next.template.md` - Apply changelog script: `apps/mobile/scripts/apply-changelog.ts` -- EAS config: `apps/mobile/eas.json` +- Release config resolver: `.github/scripts/resolve-mobile-release-config.mjs` +- Tag orchestration: `.github/workflows/tag.yml` +- OTA publish workflow: `.github/workflows/publish-ota.yml` - App config: `apps/mobile/app.config.ts` - iOS Info.plist: `apps/mobile/ios/Folo/Info.plist` -- CI build iOS: `.github/workflows/build-ios.yml` -- CI build Android: `.github/workflows/build-android.yml` diff --git a/.github/scripts/build-ota-release.mjs b/.github/scripts/build-ota-release.mjs index 210273035..fcb6dc258 100644 --- a/.github/scripts/build-ota-release.mjs +++ b/.github/scripts/build-ota-release.mjs @@ -3,7 +3,7 @@ import { spawn, spawnSync } from "node:child_process" import { createHash } from "node:crypto" import { existsSync } from "node:fs" -import { readFile, writeFile } from "node:fs/promises" +import { mkdir, readFile, writeFile } from "node:fs/promises" import { fileURLToPath } from "node:url" import { dirname, extname, join, resolve } from "pathe" @@ -95,16 +95,19 @@ const CONTENT_TYPES = new Map([ export async function buildOtaMetadata(input) { /** @type {Record} */ const platforms = {} - 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) + if (input.releaseKind === "ota") { + const fileMetadata = resolveExportFileMetadata(input.metadata) - platforms[platform] = { - launchAsset: await input.resolveAsset(launchAsset), - assets: await Promise.all(assets.map((asset) => input.resolveAsset(asset))), + 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))), + } } } @@ -149,12 +152,7 @@ export async function buildReleaseAssets(options = {}) { const projectDir = resolveMobileProjectDir(options.projectDir) const distDir = join(projectDir, "dist") const metadataPath = join(distDir, "metadata.json") - - if (!existsSync(metadataPath)) { - throw new Error( - `Missing Expo export metadata at ${metadataPath}. Run "pnpm --dir apps/mobile run update:export" first.`, - ) - } + const archivePath = join(projectDir, "dist.tar.zst") const packageJson = await readJson(join(projectDir, "package.json")) const product = process.env.OTA_PRODUCT ?? "mobile" @@ -165,7 +163,14 @@ export async function buildReleaseAssets(options = {}) { 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 metadata = await readJson(metadataPath) + + 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, @@ -204,17 +209,20 @@ export async function buildReleaseAssets(options = {}) { }) const outputPath = join(distDir, "ota-release.json") - const archivePath = join(projectDir, "dist.tar.zst") + await mkdir(distDir, { recursive: true }) await writeFile(outputPath, `${JSON.stringify(otaMetadata, null, 2)}\n`, "utf8") - await createTarZstArchive({ distDir, archivePath }) + + if (releaseKind === "ota") { + await createTarZstArchive({ distDir, archivePath }) + } return { projectDir, distDir, metadataPath, outputPath, - archivePath, + archivePath: releaseKind === "ota" ? archivePath : null, otaMetadata, } } @@ -224,7 +232,9 @@ async function main() { const result = await buildReleaseAssets() console.info(`Wrote OTA metadata: ${result.outputPath}`) - console.info(`Wrote OTA archive: ${result.archivePath}`) + if (result.archivePath) { + console.info(`Wrote OTA archive: ${result.archivePath}`) + } } catch (error) { console.error(error instanceof Error ? error.message : String(error)) process.exitCode = 1 diff --git a/.github/scripts/build-ota-release.test.ts b/.github/scripts/build-ota-release.test.ts index 4ee98eb85..d873891d2 100644 --- a/.github/scripts/build-ota-release.test.ts +++ b/.github/scripts/build-ota-release.test.ts @@ -12,6 +12,11 @@ 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_STORE_REQUIRED }) describe("buildOtaMetadata", () => { @@ -236,6 +241,32 @@ describe("buildOtaMetadata", () => { }) 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") diff --git a/.github/scripts/resolve-mobile-release-config.mjs b/.github/scripts/resolve-mobile-release-config.mjs new file mode 100644 index 000000000..e41b9526f --- /dev/null +++ b/.github/scripts/resolve-mobile-release-config.mjs @@ -0,0 +1,96 @@ +#!/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", "store-policy"]) +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, ota, or store-policy.") + } + + if (config.mode === "store") { + return { + triggerStoreBuilds: true, + triggerOtaPublish: false, + releaseKind: null, + runtimeVersion: null, + channel: null, + storeRequired: null, + policyMessage: 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, + releaseKind: config.mode === "ota" ? "ota" : "store", + runtimeVersion: config.runtimeVersion, + channel: config.channel, + storeRequired: config.mode === "store-policy" ? String(config.storeRequired ?? false) : "false", + policyMessage: config.mode === "store-policy" ? (config.message ?? "") : "", + 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("release_kind", result.releaseKind ?? "") + setGitHubOutput("runtime_version", result.runtimeVersion ?? "") + setGitHubOutput("channel", result.channel ?? "") + setGitHubOutput("store_required", result.storeRequired ?? "") + setGitHubOutput("policy_message", result.policyMessage ?? "") + 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() +} diff --git a/.github/scripts/resolve-mobile-release-config.test.ts b/.github/scripts/resolve-mobile-release-config.test.ts new file mode 100644 index 000000000..ab780fa3f --- /dev/null +++ b/.github/scripts/resolve-mobile-release-config.test.ts @@ -0,0 +1,102 @@ +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, + storeRequired: false, + message: null, + }, + }), + ).toEqual({ + triggerStoreBuilds: true, + triggerOtaPublish: false, + releaseKind: null, + runtimeVersion: null, + channel: null, + storeRequired: null, + policyMessage: 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", + storeRequired: false, + message: null, + }, + }), + ).toEqual({ + triggerStoreBuilds: false, + triggerOtaPublish: true, + releaseKind: "ota", + runtimeVersion: "0.4.1", + channel: "production", + storeRequired: "false", + policyMessage: "", + releaseVersion: "0.4.2", + }) + }) + + it("triggers metadata-only publish for store-policy mode", async () => { + const { resolveMobileReleaseConfig } = await import("./resolve-mobile-release-config.mjs") + + expect( + resolveMobileReleaseConfig({ + releaseVersion: "v0.4.3", + releaseConfig: { + version: "0.4.3", + mode: "store-policy", + runtimeVersion: "0.4.3", + channel: "production", + storeRequired: true, + message: "Install 0.4.3 from the store.", + }, + }), + ).toEqual({ + triggerStoreBuilds: false, + triggerOtaPublish: true, + releaseKind: "store", + runtimeVersion: "0.4.3", + channel: "production", + storeRequired: "true", + policyMessage: "Install 0.4.3 from the store.", + releaseVersion: "0.4.3", + }) + }) + + 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, + storeRequired: false, + message: null, + }, + }), + ).toThrow(/does not match release version/i) + }) +}) diff --git a/.github/workflows/publish-ota.yml b/.github/workflows/publish-ota.yml index efe3801ec..a270d50bd 100644 --- a/.github/workflows/publish-ota.yml +++ b/.github/workflows/publish-ota.yml @@ -25,6 +25,18 @@ on: - production - preview description: "OTA channel embedded in ota-release.json" + store_required: + type: choice + required: false + options: + - "false" + - "true" + default: "false" + description: "Whether /policy should block and require a store update" + policy_message: + type: string + required: false + description: "Optional /policy message for store metadata releases" permissions: contents: write @@ -39,6 +51,8 @@ jobs: OTA_RELEASE_KIND: ${{ inputs.release_kind }} OTA_RUNTIME_VERSION: ${{ inputs.runtime_version }} OTA_CHANNEL: ${{ inputs.channel }} + OTA_STORE_REQUIRED: ${{ inputs.store_required }} + OTA_POLICY_MESSAGE: ${{ inputs.policy_message }} OTA_GIT_TAG: mobile/v${{ inputs.release_version }} steps: @@ -72,6 +86,7 @@ jobs: run: pnpm install --frozen-lockfile - name: Export OTA bundle assets + if: inputs.release_kind == 'ota' working-directory: apps/mobile run: pnpm run update:export @@ -85,10 +100,11 @@ jobs: run: | tag_name="mobile/v${OTA_RELEASE_VERSION}" release_title="Mobile v${OTA_RELEASE_VERSION}" - ota_files=( - "apps/mobile/dist/ota-release.json" - "apps/mobile/dist.tar.zst" - ) + ota_files=("apps/mobile/dist/ota-release.json") + + if [ -f "apps/mobile/dist.tar.zst" ]; then + ota_files+=("apps/mobile/dist.tar.zst") + fi if gh release view "$tag_name" >/dev/null 2>&1; then gh release upload "$tag_name" "${ota_files[@]}" --clobber diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml index a20a8387d..25cf17972 100644 --- a/.github/workflows/tag.yml +++ b/.github/workflows/tag.yml @@ -73,87 +73,17 @@ jobs: runs-on: ubuntu-latest steps: - - name: Extract OTA release trailers - id: ota_release + - name: Checkout repository + if: needs.create_tag.outputs.platform == 'mobile' && needs.create_tag.outputs.ref_name == 'mobile-main' + uses: actions/checkout@v6 + + - name: Resolve Mobile Release Config + id: release_mode if: needs.create_tag.outputs.platform == 'mobile' && needs.create_tag.outputs.ref_name == 'mobile-main' env: - COMMIT_MESSAGE: ${{ github.event.head_commit.message }} RELEASE_VERSION: ${{ needs.create_tag.outputs.version }} - run: | - ota_trailers="$(printf '%s\n' "$COMMIT_MESSAGE" | sed -nE '/^OTA_/p')" - normalized_release_version="${RELEASE_VERSION#v}" - - if [ -z "$ota_trailers" ]; then - echo "enabled=false" >> "$GITHUB_OUTPUT" - echo "release_kind=" >> "$GITHUB_OUTPUT" - echo "runtime_version=" >> "$GITHUB_OUTPUT" - echo "channel=" >> "$GITHUB_OUTPUT" - echo "release_version=${normalized_release_version}" >> "$GITHUB_OUTPUT" - exit 0 - fi - - invalid_trailers="$(printf '%s\n' "$ota_trailers" | sed -nE '/^OTA_(RELEASE_KIND|RUNTIME_VERSION|CHANNEL)=/!p')" - if [ -n "$invalid_trailers" ]; then - echo "::error::Unsupported OTA trailer lines detected:" - printf '%s\n' "$invalid_trailers" - exit 1 - fi - - release_kind_lines="$(printf '%s\n' "$COMMIT_MESSAGE" | sed -n '/^OTA_RELEASE_KIND=/p')" - runtime_version_lines="$(printf '%s\n' "$COMMIT_MESSAGE" | sed -n '/^OTA_RUNTIME_VERSION=/p')" - channel_lines="$(printf '%s\n' "$COMMIT_MESSAGE" | sed -n '/^OTA_CHANNEL=/p')" - - count_lines() { - local lines="$1" - - if [ -z "$lines" ]; then - echo 0 - return - fi - - printf '%s\n' "$lines" | wc -l | tr -d ' ' - } - - release_kind_count="$(count_lines "$release_kind_lines")" - runtime_version_count="$(count_lines "$runtime_version_lines")" - channel_count="$(count_lines "$channel_lines")" - - if [ "$release_kind_count" -ne 1 ] || [ "$runtime_version_count" -ne 1 ] || [ "$channel_count" -ne 1 ]; then - echo "::error::OTA trailers are incomplete or duplicated. Expected exactly one OTA_RELEASE_KIND, OTA_RUNTIME_VERSION, and OTA_CHANNEL trailer when any OTA_ trailer is present." - printf '%s\n' "$ota_trailers" - exit 1 - fi - - release_kind="$(printf '%s\n' "$release_kind_lines" | sed -nE 's/^OTA_RELEASE_KIND=(.*)$/\1/p' | tail -n 1)" - runtime_version="$(printf '%s\n' "$runtime_version_lines" | sed -nE 's/^OTA_RUNTIME_VERSION=(.*)$/\1/p' | tail -n 1)" - channel="$(printf '%s\n' "$channel_lines" | sed -nE 's/^OTA_CHANNEL=(.*)$/\1/p' | tail -n 1)" - - case "$release_kind" in - ota|store) ;; - *) - echo "::error::OTA_RELEASE_KIND must be either ota or store." - exit 1 - ;; - esac - - if [ -z "$runtime_version" ]; then - echo "::error::OTA_RUNTIME_VERSION must not be empty." - exit 1 - fi - - case "$channel" in - production|preview) ;; - *) - echo "::error::OTA_CHANNEL must be either production or preview." - exit 1 - ;; - esac - - echo "enabled=true" >> "$GITHUB_OUTPUT" - echo "release_kind=${release_kind}" >> "$GITHUB_OUTPUT" - echo "runtime_version=${runtime_version}" >> "$GITHUB_OUTPUT" - echo "channel=${channel}" >> "$GITHUB_OUTPUT" - echo "release_version=${normalized_release_version}" >> "$GITHUB_OUTPUT" + RELEASE_CONFIG_PATH: apps/mobile/release.json + run: node .github/scripts/resolve-mobile-release-config.mjs - name: Checkout repository if: needs.create_tag.outputs.platform == 'desktop' && needs.create_tag.outputs.ref_name == 'main' @@ -230,7 +160,7 @@ jobs: console.log('Desktop store build triggered successfully'); - name: Trigger Mobile Preview Release Build - if: needs.create_tag.outputs.platform == 'mobile' && needs.create_tag.outputs.ref_name == 'mobile-main' + if: needs.create_tag.outputs.platform == 'mobile' && needs.create_tag.outputs.ref_name == 'mobile-main' && steps.release_mode.outputs.trigger_store_builds == 'true' uses: actions/github-script@v9 with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -248,7 +178,7 @@ jobs: console.log('Mobile preview release build triggered successfully'); - name: Trigger Mobile Production Android Build - if: needs.create_tag.outputs.platform == 'mobile' && needs.create_tag.outputs.ref_name == 'mobile-main' + if: needs.create_tag.outputs.platform == 'mobile' && needs.create_tag.outputs.ref_name == 'mobile-main' && steps.release_mode.outputs.trigger_store_builds == 'true' uses: actions/github-script@v9 with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -266,7 +196,7 @@ jobs: console.log('Mobile production Android build triggered successfully'); - name: Trigger Mobile Production iOS Build - if: needs.create_tag.outputs.platform == 'mobile' && needs.create_tag.outputs.ref_name == 'mobile-main' + if: needs.create_tag.outputs.platform == 'mobile' && needs.create_tag.outputs.ref_name == 'mobile-main' && steps.release_mode.outputs.trigger_store_builds == 'true' uses: actions/github-script@v9 with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -283,7 +213,7 @@ jobs: console.log('Mobile production iOS build triggered successfully'); - name: Trigger Mobile OTA Publish - if: needs.create_tag.outputs.platform == 'mobile' && needs.create_tag.outputs.ref_name == 'mobile-main' && steps.ota_release.outputs.enabled == 'true' + if: needs.create_tag.outputs.platform == 'mobile' && needs.create_tag.outputs.ref_name == 'mobile-main' && steps.release_mode.outputs.trigger_ota_publish == 'true' uses: actions/github-script@v9 with: github-token: ${{ secrets.GITHUB_TOKEN }} @@ -294,10 +224,12 @@ jobs: workflow_id: 'publish-ota.yml', ref: '${{ needs.create_tag.outputs.tag_version }}', inputs: { - release_version: '${{ steps.ota_release.outputs.release_version }}', - release_kind: '${{ steps.ota_release.outputs.release_kind }}', - runtime_version: '${{ steps.ota_release.outputs.runtime_version }}', - channel: '${{ steps.ota_release.outputs.channel }}' + release_version: '${{ steps.release_mode.outputs.release_version }}', + release_kind: '${{ steps.release_mode.outputs.release_kind }}', + runtime_version: '${{ steps.release_mode.outputs.runtime_version }}', + channel: '${{ steps.release_mode.outputs.channel }}', + store_required: '${{ steps.release_mode.outputs.store_required }}', + policy_message: '${{ steps.release_mode.outputs.policy_message }}' } }); console.log('Mobile OTA publish workflow triggered successfully'); diff --git a/apps/mobile/bump.config.ts b/apps/mobile/bump.config.ts index 0e2492383..94daf0ca6 100644 --- a/apps/mobile/bump.config.ts +++ b/apps/mobile/bump.config.ts @@ -13,7 +13,9 @@ export default defineConfig({ trailing: [ "plutil -replace CFBundleShortVersionString -string ${NEW_VERSION} ios/Folo/Info.plist", "CURRENT_BUILD=$(plutil -extract CFBundleVersion raw ios/Folo/Info.plist) && plutil -replace CFBundleVersion -string $((CURRENT_BUILD + 1)) ios/Folo/Info.plist", + "tsx scripts/apply-release-config.ts ${NEW_VERSION}", "git add ios/Folo/Info.plist", + "git add release.json release-plan.json", "git checkout -b release/mobile/${NEW_VERSION}", ], finally: [ diff --git a/apps/mobile/release-plan.json b/apps/mobile/release-plan.json new file mode 100644 index 000000000..8f9267f24 --- /dev/null +++ b/apps/mobile/release-plan.json @@ -0,0 +1,7 @@ +{ + "mode": "store", + "runtimeVersion": null, + "channel": null, + "storeRequired": false, + "message": null +} diff --git a/apps/mobile/release.json b/apps/mobile/release.json new file mode 100644 index 000000000..48bfb88f3 --- /dev/null +++ b/apps/mobile/release.json @@ -0,0 +1,8 @@ +{ + "version": "0.4.1", + "mode": "store", + "runtimeVersion": null, + "channel": null, + "storeRequired": false, + "message": null +} diff --git a/apps/mobile/scripts/apply-release-config.impl.ts b/apps/mobile/scripts/apply-release-config.impl.ts new file mode 100644 index 000000000..703cc582f --- /dev/null +++ b/apps/mobile/scripts/apply-release-config.impl.ts @@ -0,0 +1,75 @@ +import { readFile, writeFile } from "node:fs/promises" + +import { join } from "pathe" + +const semverPattern = /^\d+\.\d+\.\d+$/ + +export interface ReleasePlan { + mode: "store" | "ota" | "store-policy" + runtimeVersion: string | null + channel: "production" | "preview" | null + storeRequired: boolean + message: string | null +} + +export async function applyReleaseConfig(input: { projectDir: string; version: string }) { + if (!input.version || !semverPattern.test(input.version)) { + throw new Error("Expected a plain x.y.z version argument") + } + + const releasePlanPath = join(input.projectDir, "release-plan.json") + const releaseConfigPath = join(input.projectDir, "release.json") + const plan = await readReleasePlan(releasePlanPath) + validateReleasePlan(plan) + + await writeFile( + releaseConfigPath, + `${JSON.stringify( + { + version: input.version, + ...plan, + }, + null, + 2, + )}\n`, + "utf8", + ) + + await writeFile( + releasePlanPath, + `${JSON.stringify(createDefaultReleasePlan(), null, 2)}\n`, + "utf8", + ) +} + +async function readReleasePlan(path: string): Promise { + return JSON.parse(await readFile(path, "utf8")) as ReleasePlan +} + +function validateReleasePlan(plan: ReleasePlan) { + if (plan.mode !== "store" && plan.mode !== "ota" && plan.mode !== "store-policy") { + throw new Error("release-plan.json mode must be store, ota, or store-policy") + } + + if (plan.mode === "store") { + return + } + + if (!plan.runtimeVersion || !semverPattern.test(plan.runtimeVersion)) { + throw new Error("release-plan.json runtimeVersion must be a plain x.y.z version") + } + + if (plan.channel !== "production" && plan.channel !== "preview") { + throw new Error("release-plan.json channel must be production or preview") + } +} + +export function createDefaultReleasePlan(): ReleasePlan { + return { + mode: "store", + runtimeVersion: null, + channel: null, + storeRequired: false, + message: null, + } +} diff --git a/apps/mobile/scripts/apply-release-config.test.ts b/apps/mobile/scripts/apply-release-config.test.ts new file mode 100644 index 000000000..1bd726972 --- /dev/null +++ b/apps/mobile/scripts/apply-release-config.test.ts @@ -0,0 +1,53 @@ +import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises" +import { tmpdir } from "node:os" + +import { join } from "pathe" +import { afterEach, describe, expect, it } from "vitest" + +const tempDirs: string[] = [] + +afterEach(async () => { + await Promise.all( + tempDirs.splice(0).map((directory) => rm(directory, { recursive: true, force: true })), + ) +}) + +describe("apply-release-config", () => { + it("writes release.json for the new version and resets release-plan.json", async () => { + const projectDir = await mkdtemp(join(tmpdir(), "apply-release-config-test-")) + tempDirs.push(projectDir) + + await writeFile( + join(projectDir, "release-plan.json"), + JSON.stringify( + { + mode: "ota", + runtimeVersion: "0.4.1", + channel: "production", + storeRequired: false, + message: null, + }, + null, + 2, + ), + "utf8", + ) + + const { applyReleaseConfig } = await import("./apply-release-config.impl.ts") + + await applyReleaseConfig({ + projectDir, + version: "0.4.2", + }) + + await expect(readFile(join(projectDir, "release.json"), "utf8")).resolves.toContain( + '"version": "0.4.2"', + ) + await expect(readFile(join(projectDir, "release.json"), "utf8")).resolves.toContain( + '"mode": "ota"', + ) + await expect(readFile(join(projectDir, "release-plan.json"), "utf8")).resolves.toContain( + '"mode": "store"', + ) + }) +}) diff --git a/apps/mobile/scripts/apply-release-config.ts b/apps/mobile/scripts/apply-release-config.ts new file mode 100644 index 000000000..1f8fa4b16 --- /dev/null +++ b/apps/mobile/scripts/apply-release-config.ts @@ -0,0 +1,16 @@ +import { fileURLToPath } from "node:url" + +import { dirname } from "pathe" + +import { applyReleaseConfig } from "./apply-release-config.impl" + +const projectDir = dirname(dirname(fileURLToPath(import.meta.url))) + +async function main() { + await applyReleaseConfig({ + projectDir, + version: process.argv[2] ?? "", + }) +} + +void main() diff --git a/apps/mobile/vitest.config.ts b/apps/mobile/vitest.config.ts index 85a9e5f47..67a05e8de 100644 --- a/apps/mobile/vitest.config.ts +++ b/apps/mobile/vitest.config.ts @@ -4,6 +4,11 @@ export default defineConfig({ root: import.meta.dirname, test: { environment: "node", - include: ["src/**/*.test.ts", "src/**/*.spec.ts", "../../.github/scripts/**/*.test.ts"], + include: [ + "src/**/*.test.ts", + "src/**/*.spec.ts", + "scripts/**/*.test.ts", + "../../.github/scripts/**/*.test.ts", + ], }, }) diff --git a/apps/ota/src/__tests__/schema.test.ts b/apps/ota/src/__tests__/schema.test.ts index 05386357e..ae0ce70c2 100644 --- a/apps/ota/src/__tests__/schema.test.ts +++ b/apps/ota/src/__tests__/schema.test.ts @@ -38,7 +38,7 @@ describe("otaReleaseSchema", () => { expect(Object.keys(parsed.platforms)).toEqual(["ios"]) }) - it("rejects metadata with no platforms", () => { + it("rejects ota metadata with no platforms", () => { expect(() => otaReleaseSchema.parse({ schemaVersion: 1, @@ -62,6 +62,31 @@ describe("otaReleaseSchema", () => { ).toThrow("At least one platform must be provided") }) + it("accepts store metadata with no platforms", () => { + const parsed = otaReleaseSchema.parse({ + schemaVersion: 1, + product: "mobile", + channel: "production", + releaseVersion: "0.4.3", + releaseKind: "store", + runtimeVersion: "0.4.3", + publishedAt: "2026-04-10T12:00:00Z", + git: { + tag: "mobile/v0.4.3", + commit: "abcdef1234567890", + }, + policy: { + storeRequired: true, + minSupportedBinaryVersion: "0.4.3", + message: "Install 0.4.3 from the store.", + }, + platforms: {}, + }) + + expect(parsed.releaseKind).toBe("store") + expect(parsed.platforms).toEqual({}) + }) + it("rejects metadata when platform keys exist without a real payload", () => { const result = otaReleaseSchema.safeParse({ schemaVersion: 1, diff --git a/apps/ota/src/__tests__/sync.test.ts b/apps/ota/src/__tests__/sync.test.ts index 13105dc44..d33d28d29 100644 --- a/apps/ota/src/__tests__/sync.test.ts +++ b/apps/ota/src/__tests__/sync.test.ts @@ -143,7 +143,7 @@ describe("listPublishedOtaReleases", () => { ) }) - it("filters out releases missing required assets", async () => { + it("filters out releases missing metadata assets", async () => { vi.stubGlobal( "fetch", vi.fn().mockResolvedValue( @@ -155,8 +155,8 @@ describe("listPublishedOtaReleases", () => { prerelease: false, assets: [ { - name: "ota-release.json", - browser_download_url: "https://example.com/desktop-ota-release.json", + name: "dist.tar.zst", + browser_download_url: "https://example.com/desktop-dist.tar.zst", }, ], }, @@ -180,6 +180,49 @@ describe("listPublishedOtaReleases", () => { }) }) + it("includes metadata-only releases so store policy publishes can sync", async () => { + vi.stubGlobal( + "fetch", + vi.fn().mockResolvedValue( + new Response( + JSON.stringify([ + { + tag_name: "mobile/v0.4.3", + draft: false, + prerelease: false, + assets: [ + { + name: "ota-release.json", + browser_download_url: "https://example.com/store-ota-release.json", + }, + ], + }, + ]), + { status: 200 }, + ), + ), + ) + + const result = await listPublishedOtaReleases({ + owner: "RSSNext", + repo: "Folo", + token: "token", + etag: null, + }) + + expect(result).toEqual({ + kind: "ok", + etag: null, + releases: [ + { + tag: "mobile/v0.4.3", + metadataUrl: "https://example.com/store-ota-release.json", + archiveUrl: null, + }, + ], + }) + }) + it("sends a user agent header required by the GitHub releases API", async () => { const fetchMock = vi.fn().mockResolvedValue( new Response(JSON.stringify([]), { @@ -597,6 +640,66 @@ describe("syncGitHubReleases", () => { expect(kvEntries.get(KV_KEYS.syncLastSuccessAt)).toEqual(expect.any(String)) }) + it("syncs store releases without requiring archive assets", async () => { + const kvEntries = new Map() + const storeRelease = await createReleaseMetadata({ + releaseVersion: "0.4.3", + releaseKind: "store", + runtimeVersion: "0.4.3", + publishedAt: "2026-04-10T16:00:00Z", + git: { + tag: "mobile/v0.4.3", + commit: "abcdef1234567895", + }, + policy: { + storeRequired: true, + minSupportedBinaryVersion: "0.4.3", + message: "Install 0.4.3 from the store.", + }, + platforms: {}, + }) + + vi.stubGlobal( + "fetch", + vi.fn(async (input: string | URL | Request) => { + const url = String(input) + + if (url === "https://api.github.com/repos/RSSNext/Folo/releases") { + return new Response( + JSON.stringify([ + createGitHubReleaseAssetSet("mobile/v0.4.3", "https://example.com/store.json", null), + ]), + { status: 200 }, + ) + } + + if (url === "https://example.com/store.json") { + return new Response(JSON.stringify(storeRelease), { + headers: { + "Content-Type": "application/json", + }, + }) + } + + throw new Error(`Unhandled fetch URL: ${url}`) + }), + ) + + await syncGitHubReleases( + createEnv({ + kvEntries, + envOverrides: { + GITHUB_OWNER: "RSSNext", + GITHUB_REPO: "Folo", + GITHUB_TOKEN: "token", + }, + }), + ) + + expect(kvEntries.get(KV_KEYS.policy("mobile", "production"))).toBe(JSON.stringify(storeRelease)) + expect(kvEntries.get(KV_KEYS.release("mobile", "0.4.3"))).toBe(JSON.stringify(storeRelease)) + }) + it("downloads private release assets through authenticated GitHub asset API requests", async () => { const kvEntries = new Map() const bucketEntries = new Map }>() @@ -1258,7 +1361,7 @@ async function createReleaseMetadata(overrides: Partial = {}): Promi function createGitHubReleaseAssetSet( tag: string, metadataUrl: string, - archiveUrl: string, + archiveUrl: string | null, options?: { metadataApiUrl?: string archiveApiUrl?: string @@ -1274,11 +1377,15 @@ function createGitHubReleaseAssetSet( url: options?.metadataApiUrl ?? metadataUrl, browser_download_url: metadataUrl, }, - { - name: "dist.tar.zst", - url: options?.archiveApiUrl ?? archiveUrl, - browser_download_url: archiveUrl, - }, + ...(archiveUrl + ? [ + { + name: "dist.tar.zst", + url: options?.archiveApiUrl ?? archiveUrl, + browser_download_url: archiveUrl, + }, + ] + : []), ], } } diff --git a/apps/ota/src/lib/github.ts b/apps/ota/src/lib/github.ts index 587e80377..77991fcf4 100644 --- a/apps/ota/src/lib/github.ts +++ b/apps/ota/src/lib/github.ts @@ -14,7 +14,7 @@ interface GitHubRelease { export interface GitHubReleaseSummary { tag: string metadataUrl: string - archiveUrl: string + archiveUrl: string | null } export type GitHubReleaseListResult = @@ -83,14 +83,14 @@ export async function listPublishedOtaReleases(input: { const metadata = release.assets.find((asset) => asset.name === "ota-release.json") const archive = release.assets.find((asset) => asset.name === "dist.tar.zst") - if (!metadata || !archive) { + if (!metadata) { return null } return { tag: release.tag_name, metadataUrl: metadata.url ?? metadata.browser_download_url, - archiveUrl: archive.url ?? archive.browser_download_url, + archiveUrl: archive ? (archive.url ?? archive.browser_download_url) : null, } }) .filter((value): value is GitHubReleaseSummary => value !== null), diff --git a/apps/ota/src/lib/schema.ts b/apps/ota/src/lib/schema.ts index dc6018056..fff259ce1 100644 --- a/apps/ota/src/lib/schema.ts +++ b/apps/ota/src/lib/schema.ts @@ -23,30 +23,37 @@ const platformsSchema = z linux: platformSchema.optional(), }) .strict() - .refine((platforms) => Object.values(platforms).some(Boolean), { - message: "At least one platform must be provided", - }) -export const otaReleaseSchema = z.object({ - schemaVersion: z.literal(1), - updateId: z.string().uuid().optional(), - product: z.enum(["mobile", "desktop"]), - channel: z.string().min(1), - releaseVersion: semver, - releaseKind: z.enum(["ota", "store"]), - runtimeVersion: semver, - publishedAt: z.string().datetime(), - git: z.object({ - tag: z.string().min(1), - commit: z.string().min(7), - }), - policy: z.object({ - storeRequired: z.boolean(), - minSupportedBinaryVersion: semver, - message: z.string().nullable(), - }), - platforms: platformsSchema, -}) +export const otaReleaseSchema = z + .object({ + schemaVersion: z.literal(1), + updateId: z.string().uuid().optional(), + product: z.enum(["mobile", "desktop"]), + channel: z.string().min(1), + releaseVersion: semver, + releaseKind: z.enum(["ota", "store"]), + runtimeVersion: semver, + publishedAt: z.string().datetime(), + git: z.object({ + tag: z.string().min(1), + commit: z.string().min(7), + }), + policy: z.object({ + storeRequired: z.boolean(), + minSupportedBinaryVersion: semver, + message: z.string().nullable(), + }), + platforms: platformsSchema, + }) + .superRefine((release, ctx) => { + if (release.releaseKind === "ota" && !Object.values(release.platforms).some(Boolean)) { + ctx.addIssue({ + code: z.ZodIssueCode.custom, + message: "At least one platform must be provided", + path: ["platforms"], + }) + } + }) export type OtaPlatform = "ios" | "android" | "macos" | "windows" | "linux" export type OtaRelease = z.infer diff --git a/apps/ota/src/lib/sync.ts b/apps/ota/src/lib/sync.ts index 694c431a4..c823fa839 100644 --- a/apps/ota/src/lib/sync.ts +++ b/apps/ota/src/lib/sync.ts @@ -48,6 +48,12 @@ async function runSyncGitHubReleases(env: Env) { const release = await fetchReleaseMetadata(releaseSummary.metadataUrl, env) if (release.releaseKind === "ota") { + if (!releaseSummary.archiveUrl) { + throw new Error( + `Missing OTA archive asset for ${release.product} release ${release.releaseVersion}`, + ) + } + const archiveBuffer = await fetchArchiveBuffer(releaseSummary.archiveUrl, env) const files = await extractMirroredFiles({ release, diff --git a/apps/ota/src/routes/policy.ts b/apps/ota/src/routes/policy.ts index 05a6b3384..3f85a64ca 100644 --- a/apps/ota/src/routes/policy.ts +++ b/apps/ota/src/routes/policy.ts @@ -5,13 +5,16 @@ import type { Env } from "../env" import { KV_KEYS } from "../lib/constants" import { evaluateStorePolicy } from "../lib/policy" import type { OtaRelease } from "../lib/schema" -import { otaReleaseSchema } from "../lib/schema" -const storePolicyReleaseSchema = otaReleaseSchema.pick({ - releaseVersion: true, - releaseKind: true, - runtimeVersion: true, - policy: true, +const storePolicyReleaseSchema = z.object({ + releaseVersion: z.string().regex(/^\d+\.\d+\.\d+$/), + releaseKind: z.enum(["ota", "store"]), + runtimeVersion: z.string().regex(/^\d+\.\d+\.\d+$/), + policy: z.object({ + storeRequired: z.boolean(), + minSupportedBinaryVersion: z.string().regex(/^\d+\.\d+\.\d+$/), + message: z.string().nullable(), + }), }) type StorePolicyRelease = z.infer const OTA_PRODUCTS = ["mobile", "desktop"] as const