Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(android): provision signing during release builds (#7336)
Peter Chinman068ed17090a7
diff --git a/apps/web/justfile b/apps/web/justfileindex 52c28e5b05..d758abc2a4 100644--- a/apps/web/justfile+++ b/apps/web/justfile@@ -1,6 +1,6 @@set positional-arguments-# Android: the launcher fetches pinned Firebase config from Doppler by default.+# Android: fetch pinned Firebase config and provision missing release signing from Doppler.android-dev *ARGS:bash scripts/android.sh dev "$@"diff --git a/apps/web/scripts/android-launcher.test.ts b/apps/web/scripts/android-launcher.test.tsindex bafe4ea5e6..b55608495b 100644--- a/apps/web/scripts/android-launcher.test.ts+++ b/apps/web/scripts/android-launcher.test.ts@@ -44,7 +44,13 @@ describe('Android launcher arguments', () => {for (const command of ['bun', 'cargo']) {writeFileSync(join(root, 'bin', command),- `#!/bin/sh\nprintf '%s\\0' "$@" > "$CAPTURE_${command.toUpperCase()}"\n`,+ `#!/bin/sh+if [ "$1" = scripts/android-release.ts ]; then+ printf '%s\\0' "$@" > "$CAPTURE_SIGNING"+ exit "\${SIGNING_EXIT_CODE:-0}"+fi+printf '%s\\0' "$@" > "$CAPTURE_${command.toUpperCase()}"+`,{ mode: 0o700 });}@@ -57,6 +63,8 @@ describe('Android launcher arguments', () => {NDK_HOME: join(root, 'ndk'),CAPTURE_BUN: join(root, 'bun.args'),CAPTURE_CARGO: join(root, 'cargo.args'),+ CAPTURE_SIGNING: join(root, 'signing.args'),+ SIGNING_EXIT_CODE: '0',};});@@ -65,6 +73,42 @@ describe('Android launcher arguments', () => {const captured = (path: string) =>readFileSync(path, 'utf8').split('\0').slice(0, -1);+ it.each([+ ['build', [], true],+ ['build', ['--debug'], false],+ ['build', ['-d'], false],+ ['build', ['--help'], false],+ ['build', ['--', '--debug'], true],+ ['dev', [], false],+ ])('prepares signing for %s %j: %s', (action, args, needsSigning) => {+ const result = spawnSync(+ 'bash',+ [join(app, 'scripts/android.sh'), action, ...args],+ { cwd: caller, env }+ );+ expect(result.status, result.stderr.toString()).toBe(0);+ if (needsSigning) {+ expect(captured(join(root, 'signing.args'))).toEqual([+ 'scripts/android-release.ts',+ 'ensure-signing',+ join(process.env.HOME!, '.macro-android-signing'),+ 'tauri/src-tauri/gen/android/keystore.properties',+ ]);+ } else {+ expect(() => captured(join(root, 'signing.args'))).toThrow();+ }+ });++ it('does not invoke Cargo when signing setup fails', () => {+ const result = spawnSync(+ 'bash',+ [join(app, 'scripts/android.sh'), 'build'],+ { cwd: caller, env: { ...env, SIGNING_EXIT_CODE: '1' } }+ );+ expect(result.status).toBe(1);+ expect(() => captured(join(root, 'cargo.args'))).toThrow();+ });+for (const action of ['dev', 'build']) {it(`fetches pinned config for android-${action} even when local files exist`, () => {for (const directory of [diff --git a/apps/web/scripts/android-release.test.ts b/apps/web/scripts/android-release.test.tsindex 6b392aa3bb..3fcf762473 100644--- a/apps/web/scripts/android-release.test.ts+++ b/apps/web/scripts/android-release.test.ts@@ -1,12 +1,22 @@import { execFileSync } from 'node:child_process';import { createHash } from 'node:crypto';-import { mkdtemp, readFile, rm, stat, writeFile } from 'node:fs/promises';+import {+ mkdir,+ mkdtemp,+ readFile,+ readlink,+ rm,+ stat,+ symlink,+ writeFile,+} from 'node:fs/promises';import { tmpdir } from 'node:os';import { join } from 'node:path';import { afterEach, describe, expect, it, vi } from 'vitest';import {androidPackage,androidReleaseMetadata,+ ensureAndroidSigning,parseAndroidSigning,propertyValue,provisionAndroidSigning,@@ -60,6 +70,92 @@ describe('Android release versions', () => {});describe('Android signing provisioning', () => {+ it('fetches once, preserves configured builds, and reuses signing across worktrees', async () => {+ const root = await mkdtemp(join(tmpdir(), 'android-signing-test-'));+ try {+ const directory = join(root, 'private');+ const properties = join(root, 'keystore.properties');+ vi.mocked(execFileSync).mockReturnValue(JSON.stringify(signing));+ await ensureAndroidSigning(directory, properties);+ await ensureAndroidSigning(directory, properties);+ const otherProperties = join(root, 'other.properties');+ await ensureAndroidSigning(directory, otherProperties);+ expect(execFileSync).toHaveBeenCalledTimes(1);+ expect(execFileSync).toHaveBeenCalledWith(+ 'doppler',+ expect.arrayContaining([+ 'ANDROID_UPLOAD_SIGNING_JSON',+ 'android-release',+ 'prd',+ ]),+ expect.objectContaining({ stdio: ['ignore', 'pipe', 'pipe'] })+ );+ expect(await readFile(otherProperties, 'utf8')).toBe(+ await readFile(properties, 'utf8')+ );+ expect((await stat(directory)).mode & 0o777).toBe(0o700);+ expect((await stat(properties)).mode & 0o777).toBe(0o600);+ } finally {+ await rm(root, { recursive: true, force: true });+ }+ });++ it('preserves explicit configuration without fetching credentials', async () => {+ const root = await mkdtemp(join(tmpdir(), 'android-signing-test-'));+ try {+ const properties = join(root, 'keystore.properties');+ await writeFile(properties, 'existing CI signing configuration');+ await ensureAndroidSigning(join(root, 'unused'), properties);+ expect(execFileSync).not.toHaveBeenCalled();+ expect(await readFile(properties, 'utf8')).toBe(+ 'existing CI signing configuration'+ );+ } finally {+ await rm(root, { recursive: true, force: true });+ }+ });++ it('preserves broken symlinks and incomplete cached signing without fetching', async () => {+ const root = await mkdtemp(join(tmpdir(), 'android-signing-test-'));+ try {+ const directory = join(root, 'private');+ const properties = join(root, 'keystore.properties');+ const missing = join(root, 'missing.properties');+ await symlink(missing, properties);+ await expect(+ ensureAndroidSigning(directory, properties)+ ).rejects.toThrow(/broken symlink/);+ expect(await readlink(properties)).toBe(missing);+ await mkdir(directory);+ await expect(+ ensureAndroidSigning(directory, join(root, 'other.properties'))+ ).rejects.toThrow(/incomplete/);+ expect(execFileSync).not.toHaveBeenCalled();+ } finally {+ await rm(root, { recursive: true, force: true });+ }+ });++ it('reports missing Doppler access without leaking secrets or leaving files', async () => {+ const root = await mkdtemp(join(tmpdir(), 'android-signing-test-'));+ try {+ const directory = join(root, 'private');+ const properties = join(root, 'keystore.properties');+ vi.mocked(execFileSync).mockImplementation(() => {+ throw new Error('secret-password');+ });+ await expect(+ ensureAndroidSigning(directory, properties)+ ).rejects.toThrow(+ 'Unable to fetch Android signing credentials. Install the Doppler CLI and authenticate with read access to android-release/prd (CI: DOPPLER_TOKEN). See docs/ANDROID_DEVELOPMENT.md.'+ );+ await expect(stat(directory)).rejects.toMatchObject({ code: 'ENOENT' });+ await expect(stat(properties)).rejects.toMatchObject({ code: 'ENOENT' });+ } finally {+ await rm(root, { recursive: true, force: true });+ }+ });+it('rejects malformed secrets and incorrect keystore checksums without exposing values', () => {for (const contents of ['{secret-password',diff --git a/apps/web/scripts/android-release.ts b/apps/web/scripts/android-release.tsindex 4e551290ff..2ae56be2df 100644--- a/apps/web/scripts/android-release.ts+++ b/apps/web/scripts/android-release.ts@@ -1,5 +1,6 @@import { execFileSync } from 'node:child_process';import { createHash } from 'node:crypto';+import { existsSync, lstatSync } from 'node:fs';import { mkdir, readFile, symlink, writeFile } from 'node:fs/promises';import { join, resolve } from 'node:path';import { z } from 'zod';@@ -120,11 +121,41 @@ function fetchSigning() {);} catch {throw new Error(- 'Unable to fetch Android signing credentials. DOPPLER_TOKEN must have read access to android-release/prd.'+ 'Unable to fetch Android signing credentials. Install the Doppler CLI and authenticate with read access to android-release/prd (CI: DOPPLER_TOKEN). See docs/ANDROID_DEVELOPMENT.md.');}}+export async function ensureAndroidSigning(+ directory: string,+ propertiesPath: string+) {+ // Explicit local/CI configuration takes precedence over the shared local cache.+ if (existsSync(propertiesPath)) return;+ if (lstatSync(propertiesPath, { throwIfNoEntry: false })) {+ throw new Error(+ 'Android keystore.properties is a broken symlink. Restore its signing files; see docs/ANDROID_DEVELOPMENT.md.'+ );+ }++ if (lstatSync(directory, { throwIfNoEntry: false })) {+ const properties = join(directory, 'keystore.properties');+ if (+ !existsSync(properties) ||+ !existsSync(join(directory, 'upload-keystore.jks'))+ ) {+ throw new Error(+ `Android signing directory ${directory} is incomplete. Restore its signing files or provision signing manually; see docs/ANDROID_DEVELOPMENT.md.`+ );+ }+ await symlink(resolve(properties), propertiesPath);+ return;+ }++ console.log(`Provisioning Android release signing in ${directory}`);+ await provisionAndroidSigning(fetchSigning(), directory, propertiesPath);+}+export function verifyAndroidApk(apk: string,buildTools: string,@@ -183,6 +214,8 @@ if (import.meta.main) {console.log(metadata.filename);} else if (command === 'signing' && args.length === 2) {await provisionAndroidSigning(fetchSigning(), args[0], args[1]);+ } else if (command === 'ensure-signing' && args.length === 2) {+ await ensureAndroidSigning(args[0], args[1]);} else if (command === 'verify' && args.length === 4) {const [tag, apk, buildTools, certificateFile] = args;verifyAndroidApk(@@ -193,7 +226,7 @@ if (import.meta.main) {);} else {throw new Error(- 'Usage: android-release.ts metadata TAG CONFIG | signing DIRECTORY PROPERTIES | verify TAG APK BUILD_TOOLS CERTIFICATE_FILE'+ 'Usage: android-release.ts metadata TAG CONFIG | signing DIRECTORY PROPERTIES | ensure-signing DIRECTORY PROPERTIES | verify TAG APK BUILD_TOOLS CERTIFICATE_FILE');}} catch (error) {diff --git a/apps/web/scripts/android.sh b/apps/web/scripts/android.shindex fed32dc468..f6f26d30eb 100644--- a/apps/web/scripts/android.sh+++ b/apps/web/scripts/android.sh@@ -25,6 +25,18 @@ fifirebase_destination=tauri/src-tauri/gen/android/app/google-services.jsonbun scripts/android-firebase.ts "$action" "${firebase_config:---doppler}" "$firebase_destination"+# Only release builds need the upload key. Stop parsing at Cargo's separator.+release_build=true+for arg in "$@"; do+ case "$arg" in+ --) break ;;+ --debug|-d|--help|-h|--version|-V) release_build=false ;;+ esac+done+if [[ "$action" == "build" && "$release_build" == true ]]; then+ bun scripts/android-release.ts ensure-signing "$HOME/.macro-android-signing" tauri/src-tauri/gen/android/keystore.properties+fi+if [[ "$(uname)" == "Darwin" ]]; thenexport ANDROID_HOME="${ANDROID_HOME:-$HOME/Library/Android/sdk}"if [[ -z "${JAVA_HOME:-}" && -d /opt/homebrew/opt/openjdk@21/libexec/openjdk.jdk/Contents/Home ]]; thendiff --git a/docs/ANDROID_DEVELOPMENT.md b/docs/ANDROID_DEVELOPMENT.mdindex 2318406fbe..4140109797 100644--- a/docs/ANDROID_DEVELOPMENT.md+++ b/docs/ANDROID_DEVELOPMENT.md@@ -49,7 +49,8 @@ That address is emulator-only; the host-side server check must be skipped.Build commands embed the production frontend. Outputs are under`tauri/src-tauri/gen/android/app/build/outputs/`. The launcher defaults to ARM64.-Release builds require the signing configuration below and produce signed artifacts.+Release builds automatically prepare the signing configuration below and produce+signed artifacts. Debug builds do not fetch release signing credentials.## Release signing@@ -61,8 +62,18 @@ and provision them securely for CI.Coordinate key replacement with Play Console; do not generate a new key forroutine builds.-With Doppler access, provision signing from `apps/web` (the private destination-directory must not already exist):+`just android-build` preserves existing `gen/android/keystore.properties`+configuration, including CI-provisioned signing. When it is missing, the launcher+reuses signing files in `~/.macro-android-signing`, or fetches the existing key+from Doppler and creates that private directory on the first release build.+Other worktrees reuse the same directory through their own properties symlink.+Install the Doppler CLI and authenticate with read access to `android-release/prd`+(CI can use `DOPPLER_TOKEN`). Missing access fails before compilation.+Broken symlinks or incomplete signing directories fail without replacing files;+restore the files or manually provision to a new private directory.++To use a different private location, provision signing from `apps/web` (the+private destination directory must not already exist):```shbun scripts/android-release.ts signing /absolute/private/path/android-signing tauri/src-tauri/gen/android/keystore.properties