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(ci): keep a conflict from blocking a release and say why one failed (#8445)
Peter Chinman8ba9ddd608c0
diff --git a/.github/workflows/android-play-release.yml b/.github/workflows/android-play-release.ymlindex 93996a0954..a71bcf5eb8 100644--- a/.github/workflows/android-play-release.yml+++ b/.github/workflows/android-play-release.yml@@ -11,6 +11,7 @@ jobs:name: Android Play Releaseruns-on: ubuntu-24.04permissions:+ actions: readcontents: readpull-requests: writechecks: read@@ -21,6 +22,7 @@ jobs:GH_TOKEN: ${{ github.token }}GH_REPO: ${{ github.repository }}PR_NUMBER: ${{ github.event.pull_request.number }}+ BASE_BRANCH: ${{ github.event.pull_request.base.ref }}timeout-minutes: 90steps:- name: Checkout PR head@@ -35,6 +37,8 @@ jobs:- id: preconditionsname: Require the PR to be ready to mergerun: |+ printf '%s\n' "$LOGGED_STEP" > "$RUNNER_TEMP/last-step.name"+ exec > >(tee "$RUNNER_TEMP/last-step.log") 2>&1# --- authenticated fetch ------------------------------------------------------# gh_fetch <sha|ref>: make a commit that is not in this checkout (the base# commit, a moved PR head, GitHub's test merge commit) available. Checkouts@@ -65,11 +69,11 @@ jobs:return 0fiif [[ "$mergeable" == "CONFLICTING" ]]; then- echo "::error::PR #${PR_NUMBER} conflicts with its base branch, so there is no merge result to check; resolve the conflicts first." >&2+ echo "PR #${PR_NUMBER} conflicts with its base branch, so GitHub has no merge result for it." >&2return 1fiif (( $(date +%s) > deadline )); then- echo "::error::GitHub has not computed PR #${PR_NUMBER}'s merge commit yet (mergeable=${mergeable}); retry in a minute." >&2+ echo "GitHub has not computed PR #${PR_NUMBER}'s merge commit yet (mergeable=${mergeable})." >&2return 1fiecho "Merge commit not computed yet (mergeable=${mergeable}); waiting." >&2@@ -77,6 +81,76 @@ jobs:done}# ------------------------------------------------------------------------------+ # --- merge result native check ------------------------------------------------+ # merge_result_native_check <hash> <listing> <fetch>: is the native code of+ # PR #PR_NUMBER's merge result the native code of HEAD, the code this run+ # built or is about to build? The merge gate hashes the merge result, so a+ # build that differs from it could never pass the gate. <hash> / <listing>+ # print a commit's native hash / the listing behind it; <fetch> makes a+ # commit available (the iOS and Android helpers differ). Needs GH_TOKEN,+ # GH_REPO, PR_NUMBER, BASE_BRANCH, and pr_merge_commit.+ #+ # GitHub's test merge commit answers directly when it exists. It doesn't for+ # a PR that conflicts with its base, but the question still has an answer:+ # if the base's native code hasn't moved since the PR branched, merging can+ # only carry HEAD's native code, whatever files the conflicts are in. A+ # refusal lists the native files the base changed.+ merge_result_native_check() {+ local hash=$1 listing=$2 fetch=$3 built built_hash merge merge_hash compare tip \+ merge_base tip_hash base_hash why files+ # Callers run this under `if !`, which turns off `set -e` here, so every+ # lookup is checked: an empty commit hashes the same on both sides and would+ # pass an unchecked comparison.+ built=$(git rev-parse HEAD)+ if ! built_hash=$($hash "$built"); then+ echo "Could not hash this build's native code (${built:0:10})." >&2+ return 1+ fi+ merge=""+ if merge=$(pr_merge_commit); then+ if ! $fetch "$merge" || ! merge_hash=$($hash "$merge"); then+ echo "Could not fetch or hash PR #${PR_NUMBER}'s merge result (${merge:0:10})." >&2+ return 1+ fi+ if [[ "$merge_hash" == "$built_hash" ]]; then+ echo "Native code matches the merge result ${merge:0:10}."+ return 0+ fi+ why="PR #${PR_NUMBER}'s merge result (${merge:0:10}) has native code this build (${built:0:10}) lacks"+ fi+ if ! compare=$(gh api "repos/${GH_REPO}/compare/${BASE_BRANCH}...${built}" \+ --jq '"\(.base_commit.sha) \(.merge_base_commit.sha)"'); then+ echo "Could not compare ${BASE_BRANCH} with ${built:0:10}, so the merge result's native code is unverified." >&2+ return 1+ fi+ read -r tip merge_base <<<"$compare"+ if [[ -z "$tip" || -z "$merge_base" ]] || ! $fetch "$tip" || ! $fetch "$merge_base"; then+ echo "Could not fetch ${BASE_BRANCH} (${tip:0:10}) or the PR's branch point (${merge_base:0:10})." >&2+ return 1+ fi+ if [[ -z "$merge" ]]; then+ if ! tip_hash=$($hash "$tip") || ! base_hash=$($hash "$merge_base"); then+ echo "Could not hash ${BASE_BRANCH} (${tip:0:10}) or the PR's branch point (${merge_base:0:10})." >&2+ return 1+ fi+ if [[ "$tip_hash" == "$base_hash" ]]; then+ echo "PR #${PR_NUMBER} has no merge result (conflicts, or GitHub has not computed it), but ${BASE_BRANCH} (${tip:0:10})" \+ "still has the native code the PR branched from (${merge_base:0:10}), so merging can only carry this build's native code."+ return 0+ fi+ why="PR #${PR_NUMBER} has no merge result (conflicts, or GitHub has not computed it), and ${BASE_BRANCH} changed native code since the PR branched"+ fi+ # Listing lines are `<mode> <type> <sha>\t<path>` or `cache-wasm-version <v>`.+ # awk splits on the tab portably; BSD sed has no `\t` in a bracket.+ files=$({ diff <($listing "$merge_base") <($listing "$tip") || true; } \+ | awk -F'\t' '/^[<>] cache-wasm-version / { print " " substr($0, 3); next }+ /^[<>] / && NF > 1 { print " " $2 }' | sort -u)+ echo "${why}. Native changes on ${BASE_BRANCH} since ${merge_base:0:10}" \+ "(https://github.com/${GH_REPO}/compare/${merge_base:0:10}...${tip:0:10}):" >&2+ echo "${files:- (none listed: an excluded path?)}" >&2+ return 1+ }+ # ------------------------------------------------------------------------------set -euo pipefail# The android-update label means "release this and merge it when it is live",# so refuse to start unless the PR is in a mergeable state: not a draft, the@@ -118,15 +192,13 @@ jobs:# result, not of its head. A head that lacks Android native code main gained# since the PR branched would be released but could never pass the gate — and# a Play release cannot be withdrawn. Refuse before the build instead.- merge=$(pr_merge_commit)- gh_fetch "$merge"- if [[ "$(bun scripts/android-native.mjs hash "$merge")" != "$(bun scripts/android-native.mjs hash HEAD)" ]]; then- echo "PR #${PR_NUMBER}'s merge result (${merge:0:10}) has Android native code this head lacks: main changed native code since the PR branched." \- "Merge main into the PR, bump (cd apps/web && just android-bump), commit, and re-add android-update." >&2+ if ! merge_result_native_check "bun scripts/android-native.mjs hash" "bun scripts/android-native.mjs listing" gh_fetch; then+ echo "A bundle from this head could never pass the merge gate. Merge ${BASE_BRANCH} into the PR," \+ "bump (cd apps/web && just android-bump), commit, and re-add android-update." >&2exit 1fiecho "version_code=${version_code}" >> "$GITHUB_OUTPUT"- echo "Releasing Android version code ${version_code} (native hash matches the merge result ${merge:0:10})."+ echo "Releasing Android version code ${version_code}."# (`gh pr checks` names are job names, not workflow names.)ours='^(Android Native Check|Android Play Release|Re-run the native check|Web App Status Check|Android Release Drift|iOS Native Check)'@@ -153,6 +225,7 @@ jobs:doneshell: bashenv:+ LOGGED_STEP: Require the PR to be ready to mergeHEAD_SHA: ${{ github.event.pull_request.head.sha }}WAIT_MINUTES: '30'working-directory: apps/web@@ -222,6 +295,8 @@ jobs:- id: artifactname: Verify and collect App Bundlerun: |+ printf '%s\n' "$LOGGED_STEP" > "$RUNNER_TEMP/last-step.name"+ exec > >(tee "$RUNNER_TEMP/last-step.log") 2>&1set -euo pipefailcurl --fail --location --retry 3 \https://github.com/google/bundletool/releases/download/1.18.3/bundletool-all-1.18.3.jar \@@ -253,11 +328,14 @@ jobs:echo "mapping=$GITHUB_WORKSPACE/android-artifacts/$mapping_filename" >> "$GITHUB_OUTPUT"shell: bashenv:+ LOGGED_STEP: Verify and collect App BundleVERSION_CODE: ${{ steps.preconditions.outputs.version_code }}RELEASE_FILENAME: ${{ steps.metadata.outputs.filename }}working-directory: apps/web- name: Require the PR's Android native code to be unchanged since the buildrun: |+ printf '%s\n' "$LOGGED_STEP" > "$RUNNER_TEMP/last-step.name"+ exec > >(tee "$RUNNER_TEMP/last-step.log") 2>&1# --- authenticated fetch ------------------------------------------------------# gh_fetch <sha|ref>: make a commit that is not in this checkout (the base# commit, a moved PR head, GitHub's test merge commit) available. Checkouts@@ -288,11 +366,11 @@ jobs:return 0fiif [[ "$mergeable" == "CONFLICTING" ]]; then- echo "::error::PR #${PR_NUMBER} conflicts with its base branch, so there is no merge result to check; resolve the conflicts first." >&2+ echo "PR #${PR_NUMBER} conflicts with its base branch, so GitHub has no merge result for it." >&2return 1fiif (( $(date +%s) > deadline )); then- echo "::error::GitHub has not computed PR #${PR_NUMBER}'s merge commit yet (mergeable=${mergeable}); retry in a minute." >&2+ echo "GitHub has not computed PR #${PR_NUMBER}'s merge commit yet (mergeable=${mergeable})." >&2return 1fiecho "Merge commit not computed yet (mergeable=${mergeable}); waiting." >&2@@ -300,6 +378,76 @@ jobs:done}# ------------------------------------------------------------------------------+ # --- merge result native check ------------------------------------------------+ # merge_result_native_check <hash> <listing> <fetch>: is the native code of+ # PR #PR_NUMBER's merge result the native code of HEAD, the code this run+ # built or is about to build? The merge gate hashes the merge result, so a+ # build that differs from it could never pass the gate. <hash> / <listing>+ # print a commit's native hash / the listing behind it; <fetch> makes a+ # commit available (the iOS and Android helpers differ). Needs GH_TOKEN,+ # GH_REPO, PR_NUMBER, BASE_BRANCH, and pr_merge_commit.+ #+ # GitHub's test merge commit answers directly when it exists. It doesn't for+ # a PR that conflicts with its base, but the question still has an answer:+ # if the base's native code hasn't moved since the PR branched, merging can+ # only carry HEAD's native code, whatever files the conflicts are in. A+ # refusal lists the native files the base changed.+ merge_result_native_check() {+ local hash=$1 listing=$2 fetch=$3 built built_hash merge merge_hash compare tip \+ merge_base tip_hash base_hash why files+ # Callers run this under `if !`, which turns off `set -e` here, so every+ # lookup is checked: an empty commit hashes the same on both sides and would+ # pass an unchecked comparison.+ built=$(git rev-parse HEAD)+ if ! built_hash=$($hash "$built"); then+ echo "Could not hash this build's native code (${built:0:10})." >&2+ return 1+ fi+ merge=""+ if merge=$(pr_merge_commit); then+ if ! $fetch "$merge" || ! merge_hash=$($hash "$merge"); then+ echo "Could not fetch or hash PR #${PR_NUMBER}'s merge result (${merge:0:10})." >&2+ return 1+ fi+ if [[ "$merge_hash" == "$built_hash" ]]; then+ echo "Native code matches the merge result ${merge:0:10}."+ return 0+ fi+ why="PR #${PR_NUMBER}'s merge result (${merge:0:10}) has native code this build (${built:0:10}) lacks"+ fi+ if ! compare=$(gh api "repos/${GH_REPO}/compare/${BASE_BRANCH}...${built}" \+ --jq '"\(.base_commit.sha) \(.merge_base_commit.sha)"'); then+ echo "Could not compare ${BASE_BRANCH} with ${built:0:10}, so the merge result's native code is unverified." >&2+ return 1+ fi+ read -r tip merge_base <<<"$compare"+ if [[ -z "$tip" || -z "$merge_base" ]] || ! $fetch "$tip" || ! $fetch "$merge_base"; then+ echo "Could not fetch ${BASE_BRANCH} (${tip:0:10}) or the PR's branch point (${merge_base:0:10})." >&2+ return 1+ fi+ if [[ -z "$merge" ]]; then+ if ! tip_hash=$($hash "$tip") || ! base_hash=$($hash "$merge_base"); then+ echo "Could not hash ${BASE_BRANCH} (${tip:0:10}) or the PR's branch point (${merge_base:0:10})." >&2+ return 1+ fi+ if [[ "$tip_hash" == "$base_hash" ]]; then+ echo "PR #${PR_NUMBER} has no merge result (conflicts, or GitHub has not computed it), but ${BASE_BRANCH} (${tip:0:10})" \+ "still has the native code the PR branched from (${merge_base:0:10}), so merging can only carry this build's native code."+ return 0+ fi+ why="PR #${PR_NUMBER} has no merge result (conflicts, or GitHub has not computed it), and ${BASE_BRANCH} changed native code since the PR branched"+ fi+ # Listing lines are `<mode> <type> <sha>\t<path>` or `cache-wasm-version <v>`.+ # awk splits on the tab portably; BSD sed has no `\t` in a bracket.+ files=$({ diff <($listing "$merge_base") <($listing "$tip") || true; } \+ | awk -F'\t' '/^[<>] cache-wasm-version / { print " " substr($0, 3); next }+ /^[<>] / && NF > 1 { print " " $2 }' | sort -u)+ echo "${why}. Native changes on ${BASE_BRANCH} since ${merge_base:0:10}" \+ "(https://github.com/${GH_REPO}/compare/${merge_base:0:10}...${tip:0:10}):" >&2+ echo "${files:- (none listed: an excluded path?)}" >&2+ return 1+ }+ # ------------------------------------------------------------------------------set -euo pipefail# Last check before uploading: the bundle must still describe the native code# the merge gate will hash — that of the PR's merge result — or it could never@@ -322,26 +470,29 @@ jobs:fiecho "PR head moved to ${head_sha:0:10} but its Android native code is unchanged (${built:0:10})."fi- merge=$(pr_merge_commit)- gh_fetch "$merge"- merged=$(bun scripts/android-native.mjs hash "$merge")- if [[ "$merged" != "$built" ]]; then- echo "Android native code landed on main while this release was building: the merge result" \- "(${merge:0:10}) hashes ${merged:0:10}, the bundle ${built:0:10}. Not uploading a bundle the merge gate could never accept." >&2- echo "Merge main into the PR, bump (cd apps/web && just android-bump), commit, and re-add the android-update label." >&2+ if ! merge_result_native_check "bun scripts/android-native.mjs hash" "bun scripts/android-native.mjs listing" gh_fetch; then+ echo "Android native code landed on ${BASE_BRANCH} while this release was building. Not uploading the bundle" \+ "(native hash ${built:0:10}): the merge gate could never accept it." >&2+ echo "Merge ${BASE_BRANCH} into the PR, bump (cd apps/web && just android-bump), commit, and re-add the android-update label." >&2exit 1fi- echo "Merge result ${merge:0:10} matches the built native code (${built:0:10}); uploading."+ echo "Uploading the bundle (native hash ${built:0:10})."shell: bash+ env:+ LOGGED_STEP: Require the PR's Android native code to be unchanged since the buildworking-directory: apps/web- name: Write the provenance stamp as release notesrun: |+ printf '%s\n' "$LOGGED_STEP" > "$RUNNER_TEMP/last-step.name"+ exec > >(tee "$RUNNER_TEMP/last-step.log") 2>&1set -euo pipefailhash=$(bun scripts/android-native.mjs hash HEAD)mkdir -p "$RUNNER_TEMP/whatsnew"printf 'native tree %s for PR #%s\n' "$hash" "$PR_NUMBER" > "$RUNNER_TEMP/whatsnew/whatsnew-en-US"echo "Stamp: native tree ${hash} for PR #${PR_NUMBER}"shell: bash+ env:+ LOGGED_STEP: Write the provenance stamp as release notesworking-directory: apps/web- name: Upload verified Android artifactuses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02@@ -372,6 +523,8 @@ jobs:whatsNewDirectory: ${{ runner.temp }}/whatsnew- name: Promote to productionrun: |+ printf '%s\n' "$LOGGED_STEP" > "$RUNNER_TEMP/last-step.name"+ exec > >(tee "$RUNNER_TEMP/last-step.log") 2>&1set -euo pipefailfor attempt in 1 2 3 4 5; doif node scripts/android-play-promote.mjs; then@@ -384,6 +537,7 @@ jobs:exit 1shell: bashenv:+ LOGGED_STEP: Promote to productionGOOGLE_PLAY_ACCESS_TOKEN: ${{ steps.auth.outputs.access_token }}VERSION_CODE: ${{ steps.preconditions.outputs.version_code }}CHANGES_NOT_SENT_FOR_REVIEW: 'false'@@ -401,28 +555,62 @@ jobs:with:github-token: ${{ secrets.GITHUB_TOKEN }}script: |+ const fs = require('fs');+ const path = require('path');const versionCode = '${{ steps.preconditions.outputs.version_code }}' || '?';const releaseName = '${{ steps.metadata.outputs.release_name }}' || `version code ${versionCode}`;const runUrl =`${context.serverUrl}/${context.repo.owner}/${context.repo.repo}` +`/actions/runs/${context.runId}`;const success = '${{ job.status }}' === 'success';- const body = success- ? [- `🤖 Android ${releaseName} was uploaded to Google Play internal testing and submitted for a full production rollout.`,- '',- 'When Google approves it, the version goes live, the **Android Release Watch** workflow',- 're-runs the **Android Native Check** on this PR within half an hour of that, and the PR',- 'becomes mergeable. To merge it the moment that happens, click **Enable auto-merge** on this PR now (squash).',- 'After merge, the next prod deploy applies the Android native build floor committed in `min-native-build.json`.',- '',- `[Workflow run](${runUrl})`,- ].join('\n')- : [- `🤖 Android Play release for ${releaseName} **failed** — see the [workflow run](${runUrl}).`,- '',- 'Fix the problem, then remove and re-add the `android-update` label to retry.',- ].join('\n');+ const SUCCESS_BODY = [+ `🤖 Android ${releaseName} was uploaded to Google Play internal testing and submitted for a full production rollout.`,+ '',+ 'When Google approves it, the version goes live, the **Android Release Watch** workflow',+ 're-runs the **Android Native Check** on this PR within half an hour of that, and the PR',+ 'becomes mergeable. To merge it the moment that happens, click **Enable auto-merge** on this PR now (squash).',+ 'After merge, the next prod deploy applies the Android native build floor committed in `min-native-build.json`.',+ '',+ `[Workflow run](${runUrl})`,+ ].join('\n');+ let body;+ if (success) {+ body = SUCCESS_BODY;+ } else {+ // Name the failed step and, when it is one that logs its+ // output (steps::logged_run), quote the end of that output.+ let failedStep = null;+ try {+ const { data } = await github.rest.actions.listJobsForWorkflowRunAttempt({+ owner: context.repo.owner,+ repo: context.repo.repo,+ run_id: context.runId,+ attempt_number: Number(process.env.GITHUB_RUN_ATTEMPT),+ });+ const job = data.jobs.find((j) => j.name === 'Android Play Release');+ failedStep = job?.steps.find((s) => s.conclusion === 'failure')?.name ?? null;+ } catch (error) {+ core.warning(`Could not list this job's steps: ${error.message}`);+ }+ const read = (file) => {+ try {+ return fs.readFileSync(path.join(process.env.RUNNER_TEMP, file), 'utf8');+ } catch {+ return '';+ }+ };+ let tail = '';+ if (failedStep && read('last-step.name').trim() === failedStep) {+ const lines = read('last-step.log').replace(/\x1b\[[0-9;]*m/g, '').trimEnd().split('\n');+ tail = lines.slice(-30).join('\n').slice(-3000);+ }+ body = [+ `🤖 Android Play release for ${releaseName} **failed**${failedStep ? ` at **${failedStep}**` : ''} — see the [workflow run](${runUrl}).`,+ ...(tail ? ['', '```text', tail, '```'] : []),+ '',+ 'Fix the problem, then remove and re-add the `android-update` label to retry.',+ ].join('\n');+ }await github.rest.issues.createComment({owner: context.repo.owner,repo: context.repo.repo,diff --git a/.github/workflows/ios-app-store-release.yml b/.github/workflows/ios-app-store-release.ymlindex 018e272865..5d060f469b 100644--- a/.github/workflows/ios-app-store-release.yml+++ b/.github/workflows/ios-app-store-release.yml@@ -11,6 +11,7 @@ jobs:name: iOS App Store Releaseruns-on: nscloud-macos-sequoia-arm64-6x14permissions:+ actions: readcontents: readpull-requests: writechecks: read@@ -19,6 +20,7 @@ jobs:GH_TOKEN: ${{ github.token }}GH_REPO: ${{ github.repository }}PR_NUMBER: ${{ github.event.pull_request.number }}+ BASE_BRANCH: ${{ github.event.pull_request.base.ref }}timeout-minutes: 90steps:- name: Checkout PR head@@ -29,6 +31,8 @@ jobs:persist-credentials: 'false'- name: Ensure gh and jq are installedrun: |+ printf '%s\n' "$LOGGED_STEP" > "$RUNNER_TEMP/last-step.name"+ exec > >(tee "$RUNNER_TEMP/last-step.log") 2>&1set -euo pipefailfor tool in gh jq; doif ! command -v "$tool" >/dev/null; then@@ -39,8 +43,12 @@ jobs:gh --version | head -1jq --versionshell: bash+ env:+ LOGGED_STEP: Ensure gh and jq are installed- name: Require the PR to be ready to mergerun: |+ printf '%s\n' "$LOGGED_STEP" > "$RUNNER_TEMP/last-step.name"+ exec > >(tee "$RUNNER_TEMP/last-step.log") 2>&1# --- native tree ------------------------------------------------------------# Hash identifying "the iOS native code" at a commit: every tracked blob under# apps/web/tauri except the paths that never reach the iOS binary, recognised@@ -67,16 +75,23 @@ jobs:CACHE_WASM_MANIFEST=crates/client/cache-wasm/Cargo.tomlexport NATIVE_TREE_EXCLUDE='(^|/)(android|macos|linux|windows|desktop)([_./-]|$)|\.(android|macos|linux|windows)\.|\.md$|^desktop-release\.json$|^\.helix/'- # native_tree_hash <commit>: prints the hash, fails if the path is missing.+ # native_tree_listing <commit>: what the hash covers — the filtered ls-tree+ # lines plus the cache wasm version — fails if the path is missing.# (--full-tree: ls-tree otherwise narrows its output to the current directory,# which would silently hash nothing when run from apps/web.)- native_tree_hash() {+ native_tree_listing() {git rev-parse -q --verify "$1:${NATIVE_TREE_PATH}" >/dev/null || return 1- {- git ls-tree -r --full-tree "$1:${NATIVE_TREE_PATH}" \- | awk -F'\t' '$2 !~ ENVIRON["NATIVE_TREE_EXCLUDE"]'- echo "cache-wasm-version $(cache_wasm_version "$1")"- } | git hash-object --stdin+ git ls-tree -r --full-tree "$1:${NATIVE_TREE_PATH}" \+ | awk -F'\t' '$2 !~ ENVIRON["NATIVE_TREE_EXCLUDE"]'+ echo "cache-wasm-version $(cache_wasm_version "$1")"+ }++ # native_tree_hash <commit>: prints the hash of the listing, and fails when the+ # listing does (a pipe would hash nothing and succeed).+ native_tree_hash() {+ local listing+ listing=$(native_tree_listing "$1") || return 1+ git hash-object --stdin <<<"$listing"}# cache_wasm_version <commit>: the `version` of the client cache wasm package@@ -117,11 +132,11 @@ jobs:return 0fiif [[ "$mergeable" == "CONFLICTING" ]]; then- echo "::error::PR #${PR_NUMBER} conflicts with its base branch, so there is no merge result to check; resolve the conflicts first." >&2+ echo "PR #${PR_NUMBER} conflicts with its base branch, so GitHub has no merge result for it." >&2return 1fiif (( $(date +%s) > deadline )); then- echo "::error::GitHub has not computed PR #${PR_NUMBER}'s merge commit yet (mergeable=${mergeable}); retry in a minute." >&2+ echo "GitHub has not computed PR #${PR_NUMBER}'s merge commit yet (mergeable=${mergeable})." >&2return 1fiecho "Merge commit not computed yet (mergeable=${mergeable}); waiting." >&2@@ -129,6 +144,76 @@ jobs:done}# ------------------------------------------------------------------------------+ # --- merge result native check ------------------------------------------------+ # merge_result_native_check <hash> <listing> <fetch>: is the native code of+ # PR #PR_NUMBER's merge result the native code of HEAD, the code this run+ # built or is about to build? The merge gate hashes the merge result, so a+ # build that differs from it could never pass the gate. <hash> / <listing>+ # print a commit's native hash / the listing behind it; <fetch> makes a+ # commit available (the iOS and Android helpers differ). Needs GH_TOKEN,+ # GH_REPO, PR_NUMBER, BASE_BRANCH, and pr_merge_commit.+ #+ # GitHub's test merge commit answers directly when it exists. It doesn't for+ # a PR that conflicts with its base, but the question still has an answer:+ # if the base's native code hasn't moved since the PR branched, merging can+ # only carry HEAD's native code, whatever files the conflicts are in. A+ # refusal lists the native files the base changed.+ merge_result_native_check() {+ local hash=$1 listing=$2 fetch=$3 built built_hash merge merge_hash compare tip \+ merge_base tip_hash base_hash why files+ # Callers run this under `if !`, which turns off `set -e` here, so every+ # lookup is checked: an empty commit hashes the same on both sides and would+ # pass an unchecked comparison.+ built=$(git rev-parse HEAD)+ if ! built_hash=$($hash "$built"); then+ echo "Could not hash this build's native code (${built:0:10})." >&2+ return 1+ fi+ merge=""+ if merge=$(pr_merge_commit); then+ if ! $fetch "$merge" || ! merge_hash=$($hash "$merge"); then+ echo "Could not fetch or hash PR #${PR_NUMBER}'s merge result (${merge:0:10})." >&2+ return 1+ fi+ if [[ "$merge_hash" == "$built_hash" ]]; then+ echo "Native code matches the merge result ${merge:0:10}."+ return 0+ fi+ why="PR #${PR_NUMBER}'s merge result (${merge:0:10}) has native code this build (${built:0:10}) lacks"+ fi+ if ! compare=$(gh api "repos/${GH_REPO}/compare/${BASE_BRANCH}...${built}" \+ --jq '"\(.base_commit.sha) \(.merge_base_commit.sha)"'); then+ echo "Could not compare ${BASE_BRANCH} with ${built:0:10}, so the merge result's native code is unverified." >&2+ return 1+ fi+ read -r tip merge_base <<<"$compare"+ if [[ -z "$tip" || -z "$merge_base" ]] || ! $fetch "$tip" || ! $fetch "$merge_base"; then+ echo "Could not fetch ${BASE_BRANCH} (${tip:0:10}) or the PR's branch point (${merge_base:0:10})." >&2+ return 1+ fi+ if [[ -z "$merge" ]]; then+ if ! tip_hash=$($hash "$tip") || ! base_hash=$($hash "$merge_base"); then+ echo "Could not hash ${BASE_BRANCH} (${tip:0:10}) or the PR's branch point (${merge_base:0:10})." >&2+ return 1+ fi+ if [[ "$tip_hash" == "$base_hash" ]]; then+ echo "PR #${PR_NUMBER} has no merge result (conflicts, or GitHub has not computed it), but ${BASE_BRANCH} (${tip:0:10})" \+ "still has the native code the PR branched from (${merge_base:0:10}), so merging can only carry this build's native code."+ return 0+ fi+ why="PR #${PR_NUMBER} has no merge result (conflicts, or GitHub has not computed it), and ${BASE_BRANCH} changed native code since the PR branched"+ fi+ # Listing lines are `<mode> <type> <sha>\t<path>` or `cache-wasm-version <v>`.+ # awk splits on the tab portably; BSD sed has no `\t` in a bracket.+ files=$({ diff <($listing "$merge_base") <($listing "$tip") || true; } \+ | awk -F'\t' '/^[<>] cache-wasm-version / { print " " substr($0, 3); next }+ /^[<>] / && NF > 1 { print " " $2 }' | sort -u)+ echo "${why}. Native changes on ${BASE_BRANCH} since ${merge_base:0:10}" \+ "(https://github.com/${GH_REPO}/compare/${merge_base:0:10}...${tip:0:10}):" >&2+ echo "${files:- (none listed: an excluded path?)}" >&2+ return 1+ }+ # ------------------------------------------------------------------------------set -euo pipefail# The ios-update label means "release this and merge it when Apple approves",# so refuse to start unless the PR is in a mergeable state: not a draft, and@@ -157,14 +242,11 @@ jobs:# The gate compares the build's stamp with the native tree of the PR's merge# result, not of its head. A head that lacks iOS native code main gained since# the PR branched would go through App Review but could never pass the gate.- merge=$(pr_merge_commit)- native_tree_fetch "$merge"- if [[ "$(native_tree_hash "$merge")" != "$(native_tree_hash HEAD)" ]]; then- echo "PR #${PR_NUMBER}'s merge result (${merge:0:10}) has iOS native code this head lacks: main changed native code since the PR branched." \- "Merge main into the PR, bump (doppler run --project ios-release --config prd -- just ios-bump), commit, and re-add ios-update." >&2+ if ! merge_result_native_check native_tree_hash native_tree_listing native_tree_fetch; then+ echo "A build from this head could never pass the merge gate. Merge ${BASE_BRANCH} into the PR," \+ "bump (doppler run --project ios-release --config prd -- just ios-bump), commit, and re-add ios-update." >&2exit 1fi- echo "Native tree matches the merge result ${merge:0:10}."# Web App Status Check aggregates the gate, so it is red whenever the gate is;# its other inputs (Typecheck, Test, Build, ...) are separate checks and stay.@@ -193,6 +275,7 @@ jobs:doneshell: bashenv:+ LOGGED_STEP: Require the PR to be ready to mergeHEAD_SHA: ${{ github.event.pull_request.head.sha }}WAIT_MINUTES: '30'- name: Install Nix@@ -214,12 +297,15 @@ jobs:shell: bash- name: Verify iOS release numbers were bumpedrun: |-+ printf '%s\n' "$LOGGED_STEP" > "$RUNNER_TEMP/last-step.name"+ exec > >(tee "$RUNNER_TEMP/last-step.log") 2>&1nix develop --command bash -euo pipefail -c 'cd apps/webbun scripts/ios-verify-native-bump.mjs'shell: bashenv:+ LOGGED_STEP: Verify iOS release numbers were bumpedBASE_REF: origin/${{ github.event.pull_request.base.ref }}- name: Fetch App Store Connect credentials from Dopplerrun: |@@ -289,11 +375,15 @@ jobs:- id: build-checkname: Check the build number is unused in App Store Connectrun: |-+ printf '%s\n' "$LOGGED_STEP" > "$RUNNER_TEMP/last-step.name"+ exec > >(tee "$RUNNER_TEMP/last-step.log") 2>&1nix develop --command bash -euo pipefail -c 'cd apps/webbun scripts/ios-app-store.mjs status --require-unused-build'shell: bash+ env:+ LOGGED_STEP: Check the build number is unused in App Store Connect- name: Configure signing identityrun: |set -euo pipefail@@ -344,6 +434,8 @@ jobs:IOS_RELEASE_PR: ${{ github.event.pull_request.number }}- name: Require the PR's native code to be unchanged since the buildrun: |+ printf '%s\n' "$LOGGED_STEP" > "$RUNNER_TEMP/last-step.name"+ exec > >(tee "$RUNNER_TEMP/last-step.log") 2>&1# --- native tree ------------------------------------------------------------# Hash identifying "the iOS native code" at a commit: every tracked blob under# apps/web/tauri except the paths that never reach the iOS binary, recognised@@ -370,16 +462,23 @@ jobs:CACHE_WASM_MANIFEST=crates/client/cache-wasm/Cargo.tomlexport NATIVE_TREE_EXCLUDE='(^|/)(android|macos|linux|windows|desktop)([_./-]|$)|\.(android|macos|linux|windows)\.|\.md$|^desktop-release\.json$|^\.helix/'- # native_tree_hash <commit>: prints the hash, fails if the path is missing.+ # native_tree_listing <commit>: what the hash covers — the filtered ls-tree+ # lines plus the cache wasm version — fails if the path is missing.# (--full-tree: ls-tree otherwise narrows its output to the current directory,# which would silently hash nothing when run from apps/web.)- native_tree_hash() {+ native_tree_listing() {git rev-parse -q --verify "$1:${NATIVE_TREE_PATH}" >/dev/null || return 1- {- git ls-tree -r --full-tree "$1:${NATIVE_TREE_PATH}" \- | awk -F'\t' '$2 !~ ENVIRON["NATIVE_TREE_EXCLUDE"]'- echo "cache-wasm-version $(cache_wasm_version "$1")"- } | git hash-object --stdin+ git ls-tree -r --full-tree "$1:${NATIVE_TREE_PATH}" \+ | awk -F'\t' '$2 !~ ENVIRON["NATIVE_TREE_EXCLUDE"]'+ echo "cache-wasm-version $(cache_wasm_version "$1")"+ }++ # native_tree_hash <commit>: prints the hash of the listing, and fails when the+ # listing does (a pipe would hash nothing and succeed).+ native_tree_hash() {+ local listing+ listing=$(native_tree_listing "$1") || return 1+ git hash-object --stdin <<<"$listing"}# cache_wasm_version <commit>: the `version` of the client cache wasm package@@ -420,11 +519,11 @@ jobs:return 0fiif [[ "$mergeable" == "CONFLICTING" ]]; then- echo "::error::PR #${PR_NUMBER} conflicts with its base branch, so there is no merge result to check; resolve the conflicts first." >&2+ echo "PR #${PR_NUMBER} conflicts with its base branch, so GitHub has no merge result for it." >&2return 1fiif (( $(date +%s) > deadline )); then- echo "::error::GitHub has not computed PR #${PR_NUMBER}'s merge commit yet (mergeable=${mergeable}); retry in a minute." >&2+ echo "GitHub has not computed PR #${PR_NUMBER}'s merge commit yet (mergeable=${mergeable})." >&2return 1fiecho "Merge commit not computed yet (mergeable=${mergeable}); waiting." >&2@@ -432,6 +531,76 @@ jobs:done}# ------------------------------------------------------------------------------+ # --- merge result native check ------------------------------------------------+ # merge_result_native_check <hash> <listing> <fetch>: is the native code of+ # PR #PR_NUMBER's merge result the native code of HEAD, the code this run+ # built or is about to build? The merge gate hashes the merge result, so a+ # build that differs from it could never pass the gate. <hash> / <listing>+ # print a commit's native hash / the listing behind it; <fetch> makes a+ # commit available (the iOS and Android helpers differ). Needs GH_TOKEN,+ # GH_REPO, PR_NUMBER, BASE_BRANCH, and pr_merge_commit.+ #+ # GitHub's test merge commit answers directly when it exists. It doesn't for+ # a PR that conflicts with its base, but the question still has an answer:+ # if the base's native code hasn't moved since the PR branched, merging can+ # only carry HEAD's native code, whatever files the conflicts are in. A+ # refusal lists the native files the base changed.+ merge_result_native_check() {+ local hash=$1 listing=$2 fetch=$3 built built_hash merge merge_hash compare tip \+ merge_base tip_hash base_hash why files+ # Callers run this under `if !`, which turns off `set -e` here, so every+ # lookup is checked: an empty commit hashes the same on both sides and would+ # pass an unchecked comparison.+ built=$(git rev-parse HEAD)+ if ! built_hash=$($hash "$built"); then+ echo "Could not hash this build's native code (${built:0:10})." >&2+ return 1+ fi+ merge=""+ if merge=$(pr_merge_commit); then+ if ! $fetch "$merge" || ! merge_hash=$($hash "$merge"); then+ echo "Could not fetch or hash PR #${PR_NUMBER}'s merge result (${merge:0:10})." >&2+ return 1+ fi+ if [[ "$merge_hash" == "$built_hash" ]]; then+ echo "Native code matches the merge result ${merge:0:10}."+ return 0+ fi+ why="PR #${PR_NUMBER}'s merge result (${merge:0:10}) has native code this build (${built:0:10}) lacks"+ fi+ if ! compare=$(gh api "repos/${GH_REPO}/compare/${BASE_BRANCH}...${built}" \+ --jq '"\(.base_commit.sha) \(.merge_base_commit.sha)"'); then+ echo "Could not compare ${BASE_BRANCH} with ${built:0:10}, so the merge result's native code is unverified." >&2+ return 1+ fi+ read -r tip merge_base <<<"$compare"+ if [[ -z "$tip" || -z "$merge_base" ]] || ! $fetch "$tip" || ! $fetch "$merge_base"; then+ echo "Could not fetch ${BASE_BRANCH} (${tip:0:10}) or the PR's branch point (${merge_base:0:10})." >&2+ return 1+ fi+ if [[ -z "$merge" ]]; then+ if ! tip_hash=$($hash "$tip") || ! base_hash=$($hash "$merge_base"); then+ echo "Could not hash ${BASE_BRANCH} (${tip:0:10}) or the PR's branch point (${merge_base:0:10})." >&2+ return 1+ fi+ if [[ "$tip_hash" == "$base_hash" ]]; then+ echo "PR #${PR_NUMBER} has no merge result (conflicts, or GitHub has not computed it), but ${BASE_BRANCH} (${tip:0:10})" \+ "still has the native code the PR branched from (${merge_base:0:10}), so merging can only carry this build's native code."+ return 0+ fi+ why="PR #${PR_NUMBER} has no merge result (conflicts, or GitHub has not computed it), and ${BASE_BRANCH} changed native code since the PR branched"+ fi+ # Listing lines are `<mode> <type> <sha>\t<path>` or `cache-wasm-version <v>`.+ # awk splits on the tab portably; BSD sed has no `\t` in a bracket.+ files=$({ diff <($listing "$merge_base") <($listing "$tip") || true; } \+ | awk -F'\t' '/^[<>] cache-wasm-version / { print " " substr($0, 3); next }+ /^[<>] / && NF > 1 { print " " $2 }' | sort -u)+ echo "${why}. Native changes on ${BASE_BRANCH} since ${merge_base:0:10}" \+ "(https://github.com/${GH_REPO}/compare/${merge_base:0:10}...${tip:0:10}):" >&2+ echo "${files:- (none listed: an excluded path?)}" >&2+ return 1+ }+ # ------------------------------------------------------------------------------set -euo pipefail# Last check before submitting for review: the uploaded build must still# describe the native tree the merge gate will hash — that of the PR's merge@@ -456,25 +625,27 @@ jobs:fiecho "PR head moved to ${head_sha:0:10} but its native tree is still ${built_tree:0:10}."fi- merge=$(pr_merge_commit)- native_tree_fetch "$merge"- merged_tree=$(native_tree_hash "$merge")- if [[ "$merged_tree" != "$built_tree" ]]; then- echo "iOS native code landed on main while this release was building: the merge result" \- "(${merge:0:10}) hashes ${merged_tree:0:10}, build ${built} ${built_tree:0:10}. Not submitting a build the merge gate could never accept." >&2- echo "Merge main into the PR, bump (${bump}), commit, and re-add the ios-update label." >&2+ if ! merge_result_native_check native_tree_hash native_tree_listing native_tree_fetch; then+ echo "iOS native code landed on ${BASE_BRANCH} while this release was building. Not submitting build ${built}" \+ "(native tree ${built_tree:0:10}): the merge gate could never accept it." >&2+ echo "Merge ${BASE_BRANCH} into the PR, bump (${bump}), commit, and re-add the ios-update label." >&2exit 1fi- echo "Merge result ${merge:0:10} matches the built native tree (${built_tree:0:10}); submitting."+ echo "Submitting build ${built} (native tree ${built_tree:0:10})."shell: bash+ env:+ LOGGED_STEP: Require the PR's native code to be unchanged since the build- name: Submit for App Reviewrun: |-+ printf '%s\n' "$LOGGED_STEP" > "$RUNNER_TEMP/last-step.name"+ exec > >(tee "$RUNNER_TEMP/last-step.log") 2>&1nix develop --command bash -euo pipefail -c 'cd apps/webbun scripts/ios-app-store.mjs submit'shell: bashenv:+ LOGGED_STEP: Submit for App ReviewIOS_RELEASE_PR: ${{ github.event.pull_request.number }}- name: Comment on the PRif: success() || failure()@@ -483,6 +654,7 @@ jobs:github-token: ${{ secrets.GITHUB_TOKEN }}script: |const fs = require('fs');+ const path = require('path');const confPath = 'apps/web/tauri/src-tauri/tauri.ios.conf.json';const conf = fs.existsSync(confPath)? JSON.parse(fs.readFileSync(confPath, 'utf8'))@@ -493,23 +665,55 @@ jobs:`${context.serverUrl}/${context.repo.owner}/${context.repo.repo}` +`/actions/runs/${context.runId}`;const success = '${{ job.status }}' === 'success';- const body = success- ? [- `📱 iOS ${version} (build ${build}) was uploaded to TestFlight and submitted for App Review.`,- '',- 'When Apple approves it, the version releases to the App Store automatically,',- 'the **iOS Release Watch** workflow re-runs the **iOS Native Check** on this PR',- 'within half an hour of that, and the PR becomes mergeable. To merge it the',- 'moment that happens, click **Enable auto-merge** on this PR now (squash).',- 'After merge, the next prod deploy applies the iOS native build floor committed in `min-native-build.json`, prompting older installs to update.',- '',- `[Workflow run](${runUrl})`,- ].join('\n')- : [- `📱 iOS App Store release for ${version} (build ${build}) **failed** — see the [workflow run](${runUrl}).`,- '',- 'Fix the problem, then remove and re-add the `ios-update` label to retry.',- ].join('\n');+ const SUCCESS_BODY = [+ `📱 iOS ${version} (build ${build}) was uploaded to TestFlight and submitted for App Review.`,+ '',+ 'When Apple approves it, the version releases to the App Store automatically,',+ 'the **iOS Release Watch** workflow re-runs the **iOS Native Check** on this PR',+ 'within half an hour of that, and the PR becomes mergeable. To merge it the',+ 'moment that happens, click **Enable auto-merge** on this PR now (squash).',+ 'After merge, the next prod deploy applies the iOS native build floor committed in `min-native-build.json`, prompting older installs to update.',+ '',+ `[Workflow run](${runUrl})`,+ ].join('\n');+ let body;+ if (success) {+ body = SUCCESS_BODY;+ } else {+ // Name the failed step and, when it is one that logs its+ // output (steps::logged_run), quote the end of that output.+ let failedStep = null;+ try {+ const { data } = await github.rest.actions.listJobsForWorkflowRunAttempt({+ owner: context.repo.owner,+ repo: context.repo.repo,+ run_id: context.runId,+ attempt_number: Number(process.env.GITHUB_RUN_ATTEMPT),+ });+ const job = data.jobs.find((j) => j.name === 'iOS App Store Release');+ failedStep = job?.steps.find((s) => s.conclusion === 'failure')?.name ?? null;+ } catch (error) {+ core.warning(`Could not list this job's steps: ${error.message}`);+ }+ const read = (file) => {+ try {+ return fs.readFileSync(path.join(process.env.RUNNER_TEMP, file), 'utf8');+ } catch {+ return '';+ }+ };+ let tail = '';+ if (failedStep && read('last-step.name').trim() === failedStep) {+ const lines = read('last-step.log').replace(/\x1b\[[0-9;]*m/g, '').trimEnd().split('\n');+ tail = lines.slice(-30).join('\n').slice(-3000);+ }+ body = [+ `📱 iOS App Store release for ${version} (build ${build}) **failed**${failedStep ? ` at **${failedStep}**` : ''} — see the [workflow run](${runUrl}).`,+ ...(tail ? ['', '```text', tail, '```'] : []),+ '',+ 'Fix the problem, then remove and re-add the `ios-update` label to retry.',+ ].join('\n');+ }await github.rest.issues.createComment({owner: context.repo.owner,repo: context.repo.repo,diff --git a/.github/workflows/ios-release-drift.yml b/.github/workflows/ios-release-drift.ymlindex 8c7ae4cd9b..aa117f1626 100644--- a/.github/workflows/ios-release-drift.yml+++ b/.github/workflows/ios-release-drift.yml@@ -54,16 +54,23 @@ jobs:CACHE_WASM_MANIFEST=crates/client/cache-wasm/Cargo.tomlexport NATIVE_TREE_EXCLUDE='(^|/)(android|macos|linux|windows|desktop)([_./-]|$)|\.(android|macos|linux|windows)\.|\.md$|^desktop-release\.json$|^\.helix/'- # native_tree_hash <commit>: prints the hash, fails if the path is missing.+ # native_tree_listing <commit>: what the hash covers — the filtered ls-tree+ # lines plus the cache wasm version — fails if the path is missing.# (--full-tree: ls-tree otherwise narrows its output to the current directory,# which would silently hash nothing when run from apps/web.)- native_tree_hash() {+ native_tree_listing() {git rev-parse -q --verify "$1:${NATIVE_TREE_PATH}" >/dev/null || return 1- {- git ls-tree -r --full-tree "$1:${NATIVE_TREE_PATH}" \- | awk -F'\t' '$2 !~ ENVIRON["NATIVE_TREE_EXCLUDE"]'- echo "cache-wasm-version $(cache_wasm_version "$1")"- } | git hash-object --stdin+ git ls-tree -r --full-tree "$1:${NATIVE_TREE_PATH}" \+ | awk -F'\t' '$2 !~ ENVIRON["NATIVE_TREE_EXCLUDE"]'+ echo "cache-wasm-version $(cache_wasm_version "$1")"+ }++ # native_tree_hash <commit>: prints the hash of the listing, and fails when the+ # listing does (a pipe would hash nothing and succeed).+ native_tree_hash() {+ local listing+ listing=$(native_tree_listing "$1") || return 1+ git hash-object --stdin <<<"$listing"}# cache_wasm_version <commit>: the `version` of the client cache wasm packagediff --git a/.github/workflows/ios-release-watch.yml b/.github/workflows/ios-release-watch.ymlindex 4e3bd0126e..0e095bafec 100644--- a/.github/workflows/ios-release-watch.yml+++ b/.github/workflows/ios-release-watch.yml@@ -135,16 +135,23 @@ jobs:CACHE_WASM_MANIFEST=crates/client/cache-wasm/Cargo.tomlexport NATIVE_TREE_EXCLUDE='(^|/)(android|macos|linux|windows|desktop)([_./-]|$)|\.(android|macos|linux|windows)\.|\.md$|^desktop-release\.json$|^\.helix/'- # native_tree_hash <commit>: prints the hash, fails if the path is missing.+ # native_tree_listing <commit>: what the hash covers — the filtered ls-tree+ # lines plus the cache wasm version — fails if the path is missing.# (--full-tree: ls-tree otherwise narrows its output to the current directory,# which would silently hash nothing when run from apps/web.)- native_tree_hash() {+ native_tree_listing() {git rev-parse -q --verify "$1:${NATIVE_TREE_PATH}" >/dev/null || return 1- {- git ls-tree -r --full-tree "$1:${NATIVE_TREE_PATH}" \- | awk -F'\t' '$2 !~ ENVIRON["NATIVE_TREE_EXCLUDE"]'- echo "cache-wasm-version $(cache_wasm_version "$1")"- } | git hash-object --stdin+ git ls-tree -r --full-tree "$1:${NATIVE_TREE_PATH}" \+ | awk -F'\t' '$2 !~ ENVIRON["NATIVE_TREE_EXCLUDE"]'+ echo "cache-wasm-version $(cache_wasm_version "$1")"+ }++ # native_tree_hash <commit>: prints the hash of the listing, and fails when the+ # listing does (a pipe would hash nothing and succeed).+ native_tree_hash() {+ local listing+ listing=$(native_tree_listing "$1") || return 1+ git hash-object --stdin <<<"$listing"}# cache_wasm_version <commit>: the `version` of the client cache wasm packagediff --git a/.github/workflows/release-label-check.yml b/.github/workflows/release-label-check.ymlindex 1e5703bfc1..dd1e251eee 100644--- a/.github/workflows/release-label-check.yml+++ b/.github/workflows/release-label-check.yml@@ -46,11 +46,11 @@ jobs:return 0fiif [[ "$mergeable" == "CONFLICTING" ]]; then- echo "::error::PR #${PR_NUMBER} conflicts with its base branch, so there is no merge result to check; resolve the conflicts first." >&2+ echo "PR #${PR_NUMBER} conflicts with its base branch, so GitHub has no merge result for it." >&2return 1fiif (( $(date +%s) > deadline )); then- echo "::error::GitHub has not computed PR #${PR_NUMBER}'s merge commit yet (mergeable=${mergeable}); retry in a minute." >&2+ echo "GitHub has not computed PR #${PR_NUMBER}'s merge commit yet (mergeable=${mergeable})." >&2return 1fiecho "Merge commit not computed yet (mergeable=${mergeable}); waiting." >&2diff --git a/.github/workflows/web-app-check-main.yml b/.github/workflows/web-app-check-main.ymlindex 45a589242f..d40c12d6f0 100644--- a/.github/workflows/web-app-check-main.yml+++ b/.github/workflows/web-app-check-main.yml@@ -163,11 +163,11 @@ jobs:return 0fiif [[ "$mergeable" == "CONFLICTING" ]]; then- echo "::error::PR #${PR_NUMBER} conflicts with its base branch, so there is no merge result to check; resolve the conflicts first." >&2+ echo "PR #${PR_NUMBER} conflicts with its base branch, so GitHub has no merge result for it." >&2return 1fiif (( $(date +%s) > deadline )); then- echo "::error::GitHub has not computed PR #${PR_NUMBER}'s merge commit yet (mergeable=${mergeable}); retry in a minute." >&2+ echo "GitHub has not computed PR #${PR_NUMBER}'s merge commit yet (mergeable=${mergeable})." >&2return 1fiecho "Merge commit not computed yet (mergeable=${mergeable}); waiting." >&2@@ -705,16 +705,23 @@ jobs:CACHE_WASM_MANIFEST=crates/client/cache-wasm/Cargo.tomlexport NATIVE_TREE_EXCLUDE='(^|/)(android|macos|linux|windows|desktop)([_./-]|$)|\.(android|macos|linux|windows)\.|\.md$|^desktop-release\.json$|^\.helix/'- # native_tree_hash <commit>: prints the hash, fails if the path is missing.+ # native_tree_listing <commit>: what the hash covers — the filtered ls-tree+ # lines plus the cache wasm version — fails if the path is missing.# (--full-tree: ls-tree otherwise narrows its output to the current directory,# which would silently hash nothing when run from apps/web.)- native_tree_hash() {+ native_tree_listing() {git rev-parse -q --verify "$1:${NATIVE_TREE_PATH}" >/dev/null || return 1- {- git ls-tree -r --full-tree "$1:${NATIVE_TREE_PATH}" \- | awk -F'\t' '$2 !~ ENVIRON["NATIVE_TREE_EXCLUDE"]'- echo "cache-wasm-version $(cache_wasm_version "$1")"- } | git hash-object --stdin+ git ls-tree -r --full-tree "$1:${NATIVE_TREE_PATH}" \+ | awk -F'\t' '$2 !~ ENVIRON["NATIVE_TREE_EXCLUDE"]'+ echo "cache-wasm-version $(cache_wasm_version "$1")"+ }++ # native_tree_hash <commit>: prints the hash of the listing, and fails when the+ # listing does (a pipe would hash nothing and succeed).+ native_tree_hash() {+ local listing+ listing=$(native_tree_listing "$1") || return 1+ git hash-object --stdin <<<"$listing"}# cache_wasm_version <commit>: the `version` of the client cache wasm package@@ -755,11 +762,11 @@ jobs:return 0fiif [[ "$mergeable" == "CONFLICTING" ]]; then- echo "::error::PR #${PR_NUMBER} conflicts with its base branch, so there is no merge result to check; resolve the conflicts first." >&2+ echo "PR #${PR_NUMBER} conflicts with its base branch, so GitHub has no merge result for it." >&2return 1fiif (( $(date +%s) > deadline )); then- echo "::error::GitHub has not computed PR #${PR_NUMBER}'s merge commit yet (mergeable=${mergeable}); retry in a minute." >&2+ echo "GitHub has not computed PR #${PR_NUMBER}'s merge commit yet (mergeable=${mergeable})." >&2return 1fiecho "Merge commit not computed yet (mergeable=${mergeable}); waiting." >&2diff --git a/apps/web/docs/ios-releases.md b/apps/web/docs/ios-releases.mdindex 90ab66a892..b0bf3f5aeb 100644--- a/apps/web/docs/ios-releases.md+++ b/apps/web/docs/ios-releases.md@@ -78,7 +78,9 @@ icon and app-name branding are Android-only.`iOS Native Check` passes. (The workflow doesn't enable auto-mergeitself: that would need a user token, because a merge set up by theActions token doesn't trigger the push-to-`main` workflows such as the- dev redeploy.) To retry after a failure, remove and re-add the label.+ dev redeploy.) A failure comment names the step that failed and, for+ the checking steps, quotes the end of its output. To retry after a+ failure, remove and re-add the label.The label only works on a PR that is mergeable: GitHub does not run`pull_request` workflows on a PR that conflicts with `main`, so therelease never starts there. The **`Release Label Check`** workflow@@ -185,8 +187,12 @@ code" is defined above. The checks:submitting): the head's native tree must equal that of the PR's mergeresult. A head that lacks native code `main` gained since it branchedwould go through App Review but could never pass the gate; the release- refuses instead, and the fix is to merge `main`, bump, and re-add the- label.+ refuses instead, lists the native files `main` changed, and the fix is to+ merge `main`, bump, and re-add the label. When GitHub has no merge result+ (the PR conflicts with `main`, or GitHub hasn't computed it yet) the check+ compares `main`'s native tree with the PR's branch point instead: if+ `main`'s native code hasn't moved, merging can only carry the PR's own,+ whatever files the conflicts are in, and the release goes ahead.- **Live check** (the gate): the live build's stamp must equal the nativetree of the PR's **current merge result** (fetched through the API, so are-run of the job evaluates today's `main`, not the one the run starteddiff --git a/apps/web/scripts/android-native.mjs b/apps/web/scripts/android-native.mjsindex 3492beee99..7d20457cd1 100644--- a/apps/web/scripts/android-native.mjs+++ b/apps/web/scripts/android-native.mjs@@ -59,14 +59,19 @@ export function androidTreeListing(git, commit) {.filter((line) => line && !androidExclude.test(line.split('\t')[1]));}-/// One hash for "the Android native code" at a commit: the listing above-/// plus the cache wasm version. Equal hashes mean no native change.-export function androidNativeHash(git, commit) {- const content = [+/// What the hash covers at a commit: the listing above plus the cache wasm+/// version, one line each (the iOS `native_tree_listing` twin).+export function androidNativeListing(git, commit) {+ return [...androidTreeListing(git, commit),`cache-wasm-version ${cacheWasmVersion(git, commit)}`,- ].join('\n');- return git(['hash-object', '--stdin'], `${content}\n`);+ ];+}++/// One hash for "the Android native code" at a commit. Equal hashes mean no+/// native change.+export function androidNativeHash(git, commit) {+ return git(['hash-object', '--stdin'], `${androidNativeListing(git, commit).join('\n')}\n`);}/// Why two commits differ, for messages: which of the two signals moved.@@ -99,6 +104,7 @@ export function androidVersionCode(git, commit) {// CLI for the workflows' shell steps:// bun scripts/android-native.mjs hash [commit] the native hash+// bun scripts/android-native.mjs listing [commit] what it covers// bun scripts/android-native.mjs version-code [commit] the versionCodeif (process.argv[1] &&@@ -109,8 +115,9 @@ if (const git = gitIn(process.cwd());const resolved = git(['rev-parse', '--verify', '--end-of-options', `${commit}^{commit}`]);if (command === 'hash') console.log(androidNativeHash(git, resolved));+ else if (command === 'listing') console.log(androidNativeListing(git, resolved).join('\n'));else if (command === 'version-code') console.log(androidVersionCode(git, resolved));- else throw new Error('Usage: android-native.mjs hash|version-code [commit]');+ else throw new Error('Usage: android-native.mjs hash|listing|version-code [commit]');} catch (error) {console.error(error instanceof Error ? error.message : 'android-native failed');process.exitCode = 1;diff --git a/apps/web/scripts/android-version-check.test.ts b/apps/web/scripts/android-version-check.test.tsindex 3982b1fa90..1617224ab5 100644--- a/apps/web/scripts/android-version-check.test.ts+++ b/apps/web/scripts/android-version-check.test.ts@@ -82,6 +82,14 @@ describe('PR Android version enforcement', () => {expect(checkAndroidVersion({ cwd, base })).toContain('No Android native changes');});+ it('passes a Markdown-only change under the Tauri tree without a bump', () => {+ const base = git('rev-parse', 'HEAD');+ write('apps/web/tauri/src-tauri/README.md', '# docs');+ write('apps/web/tauri/callkit_plugin/permissions/autogenerated/reference.md', '# generated');+ commit();+ expect(checkAndroidVersion({ cwd, base })).toContain('No Android native changes');+ });+it.each(['modify', 'add', 'delete', 'rename'])('rejects a native %s without a bump',(change) => {diff --git a/docs/development/android.md b/docs/development/android.mdindex d9f9c3c65e..35c32ce8d7 100644--- a/docs/development/android.md+++ b/docs/development/android.md@@ -170,21 +170,26 @@ To release:first refuses drafts, PRs with failing checks (pending ones are waited on,up to 30 minutes), PRs without a bump, and PRs whose head lacks Androidnative code that landed on `main` since they branched (the gate hashes- the merge result, so such a bundle could never pass it; merge `main`,- bump, re-add the label). It then builds the signed App Bundle from the PR- head on a hosted Ubuntu runner (Android SDK, Nix, signing and Firebase- config from Doppler `android-release/prd`), verifies it with bundletool,+ the merge result, so such a bundle could never pass it; the refusal lists+ the native files `main` changed; merge `main`, bump, re-add the label).+ When GitHub has no merge result (the PR conflicts with `main`, or GitHub+ hasn't computed it yet) the check compares `main` with the PR's branch+ point instead and goes ahead if `main`'s native code hasn't moved. It+ then builds the signed App Bundle from the PR head on a hosted Ubuntu+ runner (Android SDK, Nix, signing and Firebase config from Doppler+ `android-release/prd`), verifies it with bundletool,checks again that neither the PR head nor `main` changed native codeduring the build, uploads it to the **internal** track with`status=completed`, and promotes it to **production** as a full rollout(Google review applies). The bundle and R8 mapping are kept as a workflowartifact for 90 days. The release notes carry a provenance stamp,`native tree <hash> for PR #<n>`, the twin of the iOS TestFlight stamp.- The run comments the outcome on the PR; remove and re-add the label to- retry. Click **Enable auto-merge** on the PR to merge the moment it is- live. The label only works on a PR that is mergeable: GitHub does not- run `pull_request` workflows on a PR that conflicts with `main`, so the- release never starts there. The **`Release Label Check`** workflow+ The run comments the outcome on the PR (a failure names the step that+ failed and, for the checking steps, quotes the end of its output);+ remove and re-add the label to retry. Click **Enable auto-merge** on the+ PR to merge the moment it is live. The label only works on a PR that is+ mergeable: GitHub does not run `pull_request` workflows on a PR that+ conflicts with `main`, so the release never starts there. The **`Release Label Check`** workflow(`.github/workflows/release-label-check.yml`, a `pull_request_target`workflow, which GitHub does run) then comments and removes the label;resolve the conflicts and re-add it. On a mergeable PR that workflowdiff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/android_play_release.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/android_play_release.rsindex 289df931d5..7610cc14ab 100644--- a/tooling/xtask/crates/xtask_workflows/src/workflows/android_play_release.rs+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/android_play_release.rs@@ -57,6 +57,8 @@ fn release_job() -> Job {.timeout_minutes(90u32).permissions(Permissions::default()+ // The failure comment names the step that failed.+ .actions(Level::Read).checks(Level::Read).contents(Level::Read).id_token(Level::Write)@@ -67,6 +69,7 @@ fn release_job() -> Job {.add_env(("GH_TOKEN", "${{ github.token }}")).add_env(("GH_REPO", "${{ github.repository }}")).add_env(("PR_NUMBER", "${{ github.event.pull_request.number }}"))+ .add_env(("BASE_BRANCH", "${{ github.event.pull_request.base.ref }}")).add_step(checkout_pr_head()).add_step(setup_bun()).add_step(preconditions())@@ -114,17 +117,19 @@ fn setup_bun() -> Step<Use> {/// PR must already be mergeable: not a draft, every other check on the head/// commit green (pending ones are waited on), and the version code bumped.fn preconditions() -> Step<Run> {- Step::new("Require the PR to be ready to merge")- .run(concat!(+ steps::logged_run(+ "Require the PR to be ready to merge",+ concat!(include_str!("scripts/android_git_fetch.sh"),include_str!("scripts/pr_merge_commit.sh"),+ include_str!("scripts/merge_result_native_check.sh"),include_str!("scripts/android_release_preconditions.sh")- ))- .id("preconditions")- .shell("bash")- .working_directory(xtask_paths::repo_dir!("apps/web"))- .add_env(("HEAD_SHA", "${{ github.event.pull_request.head.sha }}"))- .add_env(("WAIT_MINUTES", "30"))+ ),+ )+ .id("preconditions")+ .working_directory(xtask_paths::repo_dir!("apps/web"))+ .add_env(("HEAD_SHA", "${{ github.event.pull_request.head.sha }}"))+ .add_env(("WAIT_MINUTES", "30"))}fn install_android_sdk() -> Step<Run> {@@ -219,8 +224,9 @@ fn preserve_build_log() -> Step<Use> {}fn verify_and_collect() -> Step<Run> {- Step::new("Verify and collect App Bundle")- .run(indoc::indoc! {r#"+ steps::logged_run(+ "Verify and collect App Bundle",+ indoc::indoc! {r#"set -euo pipefailcurl --fail --location --retry 3 \https://github.com/google/bundletool/releases/download/1.18.3/bundletool-all-1.18.3.jar \@@ -250,40 +256,44 @@ fn verify_and_collect() -> Step<Run> {sha256sum "$mapping_filename" > "$mapping_filename.sha256"echo "bundle=$GITHUB_WORKSPACE/android-artifacts/$bundle_filename" >> "$GITHUB_OUTPUT"echo "mapping=$GITHUB_WORKSPACE/android-artifacts/$mapping_filename" >> "$GITHUB_OUTPUT"- "#})- .id("artifact")- .shell("bash")- .working_directory(xtask_paths::repo_dir!("apps/web"))- .add_env(("VERSION_CODE", "${{ steps.preconditions.outputs.version_code }}"))- .add_env(("RELEASE_FILENAME", "${{ steps.metadata.outputs.filename }}"))+ "#},+ )+ .id("artifact")+ .working_directory(xtask_paths::repo_dir!("apps/web"))+ .add_env(("VERSION_CODE", "${{ steps.preconditions.outputs.version_code }}"))+ .add_env(("RELEASE_FILENAME", "${{ steps.metadata.outputs.filename }}"))}-/// Native code pushed while the build ran would make the bundle stale; don't-/// upload it (the drift workflow also cancels runs after the fact).+/// Native code pushed while the build ran, on the PR or on `main`, would make+/// the bundle stale; don't upload it (the drift workflow also cancels runs+/// after the fact).fn head_guard() -> Step<Run> {- Step::new("Require the PR's Android native code to be unchanged since the build")- .run(concat!(+ steps::logged_run(+ "Require the PR's Android native code to be unchanged since the build",+ concat!(include_str!("scripts/android_git_fetch.sh"),include_str!("scripts/pr_merge_commit.sh"),+ include_str!("scripts/merge_result_native_check.sh"),include_str!("scripts/android_release_head_guard.sh")- ))- .shell("bash")- .working_directory(xtask_paths::repo_dir!("apps/web"))+ ),+ )+ .working_directory(xtask_paths::repo_dir!("apps/web"))}/// The release notes carry the native hash and PR number, which the gate and/// the watcher compare against the merge result (the TestFlight stamp's twin).fn provenance_stamp() -> Step<Run> {- Step::new("Write the provenance stamp as release notes")- .run(indoc::indoc! {r#"+ steps::logged_run(+ "Write the provenance stamp as release notes",+ indoc::indoc! {r#"set -euo pipefailhash=$(bun scripts/android-native.mjs hash HEAD)mkdir -p "$RUNNER_TEMP/whatsnew"printf 'native tree %s for PR #%s\n' "$hash" "$PR_NUMBER" > "$RUNNER_TEMP/whatsnew/whatsnew-en-US"echo "Stamp: native tree ${hash} for PR #${PR_NUMBER}"- "#})- .shell("bash")- .working_directory(xtask_paths::repo_dir!("apps/web"))+ "#},+ )+ .working_directory(xtask_paths::repo_dir!("apps/web"))}fn upload_workflow_artifact() -> Step<Use> {@@ -345,8 +355,9 @@ fn upload_internal() -> Step<Use> {/// Internal → production, full rollout. Play can take a moment to show the/// internal release in a fresh edit, so the promotion is retried briefly.fn promote_production() -> Step<Run> {- Step::new("Promote to production")- .run(indoc::indoc! {r#"+ steps::logged_run(+ "Promote to production",+ indoc::indoc! {r#"set -euo pipefailfor attempt in 1 2 3 4 5; doif node scripts/android-play-promote.mjs; then@@ -357,12 +368,12 @@ fn promote_production() -> Step<Run> {doneecho "Could not promote version code ${VERSION_CODE} to production; promote it by hand with publish-android-play.yml (operation=promote-production)." >&2exit 1- "#})- .shell("bash")- .working_directory(xtask_paths::repo_dir!("apps/web"))- .add_env(("GOOGLE_PLAY_ACCESS_TOKEN", "${{ steps.auth.outputs.access_token }}"))- .add_env(("VERSION_CODE", "${{ steps.preconditions.outputs.version_code }}"))- .add_env(("CHANGES_NOT_SENT_FOR_REVIEW", "false"))+ "#},+ )+ .working_directory(xtask_paths::repo_dir!("apps/web"))+ .add_env(("GOOGLE_PLAY_ACCESS_TOKEN", "${{ steps.auth.outputs.access_token }}"))+ .add_env(("VERSION_CODE", "${{ steps.preconditions.outputs.version_code }}"))+ .add_env(("CHANGES_NOT_SENT_FOR_REVIEW", "false"))}fn remove_signing_material() -> Step<Run> {@@ -390,28 +401,62 @@ fn pr_comment() -> Step<Use> {.add_with(("script",indoc::indoc! {r#"+ const fs = require('fs');+ const path = require('path');const versionCode = '${{ steps.preconditions.outputs.version_code }}' || '?';const releaseName = '${{ steps.metadata.outputs.release_name }}' || `version code ${versionCode}`;const runUrl =`${context.serverUrl}/${context.repo.owner}/${context.repo.repo}` +`/actions/runs/${context.runId}`;const success = '${{ job.status }}' === 'success';- const body = success- ? [- `🤖 Android ${releaseName} was uploaded to Google Play internal testing and submitted for a full production rollout.`,- '',- 'When Google approves it, the version goes live, the **Android Release Watch** workflow',- 're-runs the **Android Native Check** on this PR within half an hour of that, and the PR',- 'becomes mergeable. To merge it the moment that happens, click **Enable auto-merge** on this PR now (squash).',- 'After merge, the next prod deploy applies the Android native build floor committed in `min-native-build.json`.',- '',- `[Workflow run](${runUrl})`,- ].join('\n')- : [- `🤖 Android Play release for ${releaseName} **failed** — see the [workflow run](${runUrl}).`,- '',- 'Fix the problem, then remove and re-add the `android-update` label to retry.',- ].join('\n');+ const SUCCESS_BODY = [+ `🤖 Android ${releaseName} was uploaded to Google Play internal testing and submitted for a full production rollout.`,+ '',+ 'When Google approves it, the version goes live, the **Android Release Watch** workflow',+ 're-runs the **Android Native Check** on this PR within half an hour of that, and the PR',+ 'becomes mergeable. To merge it the moment that happens, click **Enable auto-merge** on this PR now (squash).',+ 'After merge, the next prod deploy applies the Android native build floor committed in `min-native-build.json`.',+ '',+ `[Workflow run](${runUrl})`,+ ].join('\n');+ let body;+ if (success) {+ body = SUCCESS_BODY;+ } else {+ // Name the failed step and, when it is one that logs its+ // output (steps::logged_run), quote the end of that output.+ let failedStep = null;+ try {+ const { data } = await github.rest.actions.listJobsForWorkflowRunAttempt({+ owner: context.repo.owner,+ repo: context.repo.repo,+ run_id: context.runId,+ attempt_number: Number(process.env.GITHUB_RUN_ATTEMPT),+ });+ const job = data.jobs.find((j) => j.name === 'Android Play Release');+ failedStep = job?.steps.find((s) => s.conclusion === 'failure')?.name ?? null;+ } catch (error) {+ core.warning(`Could not list this job's steps: ${error.message}`);+ }+ const read = (file) => {+ try {+ return fs.readFileSync(path.join(process.env.RUNNER_TEMP, file), 'utf8');+ } catch {+ return '';+ }+ };+ let tail = '';+ if (failedStep && read('last-step.name').trim() === failedStep) {+ const lines = read('last-step.log').replace(/\x1b\[[0-9;]*m/g, '').trimEnd().split('\n');+ tail = lines.slice(-30).join('\n').slice(-3000);+ }+ body = [+ `🤖 Android Play release for ${releaseName} **failed**${failedStep ? ` at **${failedStep}**` : ''} — see the [workflow run](${runUrl}).`,+ ...(tail ? ['', '```text', tail, '```'] : []),+ '',+ 'Fix the problem, then remove and re-add the `android-update` label to retry.',+ ].join('\n');+ }await github.rest.issues.createComment({owner: context.repo.owner,repo: context.repo.repo,diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/ios_app_store_release.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/ios_app_store_release.rsindex e64240b1b2..6de8523641 100644--- a/tooling/xtask/crates/xtask_workflows/src/workflows/ios_app_store_release.rs+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/ios_app_store_release.rs@@ -61,6 +61,8 @@ fn release_job() -> Job {.timeout_minutes(90u32).permissions(Permissions::default()+ // The failure comment names the step that failed.+ .actions(Level::Read).checks(Level::Read).contents(Level::Read).pull_requests(Level::Write)@@ -70,6 +72,7 @@ fn release_job() -> Job {.add_env(("GH_TOKEN", "${{ github.token }}")).add_env(("GH_REPO", "${{ github.repository }}")).add_env(("PR_NUMBER", "${{ github.event.pull_request.number }}"))+ .add_env(("BASE_BRANCH", "${{ github.event.pull_request.base.ref }}")).add_step(checkout_pr_head()).add_step(require_cli_tools()).add_step(preconditions())@@ -88,23 +91,26 @@ fn release_job() -> Job {/// PR must already be mergeable: not a draft, every other check on the head/// commit green (pending ones are waited on). Fails before the long build.fn preconditions() -> Step<Run> {- Step::new("Require the PR to be ready to merge")- .run(concat!(+ steps::logged_run(+ "Require the PR to be ready to merge",+ concat!(include_str!("scripts/ios_native_tree.sh"),include_str!("scripts/pr_merge_commit.sh"),+ include_str!("scripts/merge_result_native_check.sh"),include_str!("scripts/ios_release_preconditions.sh")- ))- .shell("bash")- .add_env(("HEAD_SHA", "${{ github.event.pull_request.head.sha }}"))- .add_env(("WAIT_MINUTES", "30"))+ ),+ )+ .add_env(("HEAD_SHA", "${{ github.event.pull_request.head.sha }}"))+ .add_env(("WAIT_MINUTES", "30"))}/// The pre-build steps run outside the Nix dev shell (it isn't installed/// yet) and need `gh` + `jq`; the Namespace macOS image is not guaranteed to/// ship them.fn require_cli_tools() -> Step<Run> {- Step::new("Ensure gh and jq are installed")- .run(indoc::indoc! {r#"+ steps::logged_run(+ "Ensure gh and jq are installed",+ indoc::indoc! {r#"set -euo pipefailfor tool in gh jq; doif ! command -v "$tool" >/dev/null; then@@ -114,20 +120,23 @@ fn require_cli_tools() -> Step<Run> {donegh --version | head -1jq --version- "#})- .shell("bash")+ "#},+ )}-/// Native code pushed while the build ran would make the upload stale; don't-/// submit it (the drift workflow also withdraws after the fact).+/// Native code pushed while the build ran, on the PR or on `main`, would make+/// the upload stale; don't submit it (the drift workflow also withdraws after+/// the fact).fn head_guard() -> Step<Run> {- Step::new("Require the PR's native code to be unchanged since the build")- .run(concat!(+ steps::logged_run(+ "Require the PR's native code to be unchanged since the build",+ concat!(include_str!("scripts/ios_native_tree.sh"),include_str!("scripts/pr_merge_commit.sh"),+ include_str!("scripts/merge_result_native_check.sh"),include_str!("scripts/ios_release_head_guard.sh")- ))- .shell("bash")+ ),+ )}fn checkout_pr_head() -> Step<Use> {@@ -143,13 +152,14 @@ fn checkout_pr_head() -> Step<Use> {.add_with(("persist-credentials", false))}-/// Run a command in `apps/web` inside the Nix dev shell.+/// Run a command in `apps/web` inside the Nix dev shell, with its output+/// quotable by the failure comment (so not for the build: see `logged_run`).fn in_dev_shell(name: &str, commands: &str) -> Step<Run> {- Step::new(name)- .run(format!(- "nix develop --command bash -euo pipefail -c '\n{commands}'"- ))- .shell("bash")+ steps::logged_run(name, dev_shell_script(commands))+}++fn dev_shell_script(commands: &str) -> String {+ format!("nix develop --command bash -euo pipefail -c '\n{commands}'")}fn verify_bump() -> Step<Run> {@@ -201,15 +211,16 @@ fn configure_signing() -> Step<Run> {/// `wait-build` stamps the processed build with the native tree it was built/// from (and the PR number), which the merge gate later verifies.fn build_and_upload() -> Step<Run> {- in_dev_shell(- "Build and upload to App Store Connect",- " bun install --frozen-lockfile\n cd apps/web\n just ios-release --no-bump\n",- )- .if_condition(Expression::new(- "steps.build-check.outputs.uploaded != 'true'",- ))- .add_env(("VITE_POSTHOG_API_KEY", vars::POSTHOG_API_KEY))- .add_env(("IOS_RELEASE_PR", "${{ github.event.pull_request.number }}"))+ Step::new("Build and upload to App Store Connect")+ .run(dev_shell_script(+ " bun install --frozen-lockfile\n cd apps/web\n just ios-release --no-bump\n",+ ))+ .shell("bash")+ .if_condition(Expression::new(+ "steps.build-check.outputs.uploaded != 'true'",+ ))+ .add_env(("VITE_POSTHOG_API_KEY", vars::POSTHOG_API_KEY))+ .add_env(("IOS_RELEASE_PR", "${{ github.event.pull_request.number }}"))}/// `IOS_RELEASE_PR` lets `submit` recognise (and take over) this PR's own@@ -237,6 +248,7 @@ fn pr_comment() -> Step<Use> {"script",indoc::indoc! {r#"const fs = require('fs');+ const path = require('path');const confPath = 'apps/web/tauri/src-tauri/tauri.ios.conf.json';const conf = fs.existsSync(confPath)? JSON.parse(fs.readFileSync(confPath, 'utf8'))@@ -247,23 +259,55 @@ fn pr_comment() -> Step<Use> {`${context.serverUrl}/${context.repo.owner}/${context.repo.repo}` +`/actions/runs/${context.runId}`;const success = '${{ job.status }}' === 'success';- const body = success- ? [- `📱 iOS ${version} (build ${build}) was uploaded to TestFlight and submitted for App Review.`,- '',- 'When Apple approves it, the version releases to the App Store automatically,',- 'the **iOS Release Watch** workflow re-runs the **iOS Native Check** on this PR',- 'within half an hour of that, and the PR becomes mergeable. To merge it the',- 'moment that happens, click **Enable auto-merge** on this PR now (squash).',- 'After merge, the next prod deploy applies the iOS native build floor committed in `min-native-build.json`, prompting older installs to update.',- '',- `[Workflow run](${runUrl})`,- ].join('\n')- : [- `📱 iOS App Store release for ${version} (build ${build}) **failed** — see the [workflow run](${runUrl}).`,- '',- 'Fix the problem, then remove and re-add the `ios-update` label to retry.',- ].join('\n');+ const SUCCESS_BODY = [+ `📱 iOS ${version} (build ${build}) was uploaded to TestFlight and submitted for App Review.`,+ '',+ 'When Apple approves it, the version releases to the App Store automatically,',+ 'the **iOS Release Watch** workflow re-runs the **iOS Native Check** on this PR',+ 'within half an hour of that, and the PR becomes mergeable. To merge it the',+ 'moment that happens, click **Enable auto-merge** on this PR now (squash).',+ 'After merge, the next prod deploy applies the iOS native build floor committed in `min-native-build.json`, prompting older installs to update.',+ '',+ `[Workflow run](${runUrl})`,+ ].join('\n');+ let body;+ if (success) {+ body = SUCCESS_BODY;+ } else {+ // Name the failed step and, when it is one that logs its+ // output (steps::logged_run), quote the end of that output.+ let failedStep = null;+ try {+ const { data } = await github.rest.actions.listJobsForWorkflowRunAttempt({+ owner: context.repo.owner,+ repo: context.repo.repo,+ run_id: context.runId,+ attempt_number: Number(process.env.GITHUB_RUN_ATTEMPT),+ });+ const job = data.jobs.find((j) => j.name === 'iOS App Store Release');+ failedStep = job?.steps.find((s) => s.conclusion === 'failure')?.name ?? null;+ } catch (error) {+ core.warning(`Could not list this job's steps: ${error.message}`);+ }+ const read = (file) => {+ try {+ return fs.readFileSync(path.join(process.env.RUNNER_TEMP, file), 'utf8');+ } catch {+ return '';+ }+ };+ let tail = '';+ if (failedStep && read('last-step.name').trim() === failedStep) {+ const lines = read('last-step.log').replace(/\x1b\[[0-9;]*m/g, '').trimEnd().split('\n');+ tail = lines.slice(-30).join('\n').slice(-3000);+ }+ body = [+ `📱 iOS App Store release for ${version} (build ${build}) **failed**${failedStep ? ` at **${failedStep}**` : ''} — see the [workflow run](${runUrl}).`,+ ...(tail ? ['', '```text', tail, '```'] : []),+ '',+ 'Fix the problem, then remove and re-add the `ios-update` label to retry.',+ ].join('\n');+ }await github.rest.issues.createComment({owner: context.repo.owner,repo: context.repo.repo,diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/android_release_head_guard.sh b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/android_release_head_guard.shindex ddbe0928ce..0ea239cae6 100644--- a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/android_release_head_guard.sh+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/android_release_head_guard.sh@@ -20,13 +20,10 @@ elsefiecho "PR head moved to ${head_sha:0:10} but its Android native code is unchanged (${built:0:10})."fi-merge=$(pr_merge_commit)-gh_fetch "$merge"-merged=$(bun scripts/android-native.mjs hash "$merge")-if [[ "$merged" != "$built" ]]; then- echo "Android native code landed on main while this release was building: the merge result" \- "(${merge:0:10}) hashes ${merged:0:10}, the bundle ${built:0:10}. Not uploading a bundle the merge gate could never accept." >&2- echo "Merge main into the PR, bump (cd apps/web && just android-bump), commit, and re-add the android-update label." >&2+if ! merge_result_native_check "bun scripts/android-native.mjs hash" "bun scripts/android-native.mjs listing" gh_fetch; then+ echo "Android native code landed on ${BASE_BRANCH} while this release was building. Not uploading the bundle" \+ "(native hash ${built:0:10}): the merge gate could never accept it." >&2+ echo "Merge ${BASE_BRANCH} into the PR, bump (cd apps/web && just android-bump), commit, and re-add the android-update label." >&2exit 1fi-echo "Merge result ${merge:0:10} matches the built native code (${built:0:10}); uploading."+echo "Uploading the bundle (native hash ${built:0:10})."diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/android_release_preconditions.sh b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/android_release_preconditions.shindex aad0f97eef..f1ba130e3a 100644--- a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/android_release_preconditions.sh+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/android_release_preconditions.sh@@ -39,15 +39,13 @@ version_code=$(sed -n 's/^version_code=//p' "$outputs")# result, not of its head. A head that lacks Android native code main gained# since the PR branched would be released but could never pass the gate — and# a Play release cannot be withdrawn. Refuse before the build instead.-merge=$(pr_merge_commit)-gh_fetch "$merge"-if [[ "$(bun scripts/android-native.mjs hash "$merge")" != "$(bun scripts/android-native.mjs hash HEAD)" ]]; then- echo "PR #${PR_NUMBER}'s merge result (${merge:0:10}) has Android native code this head lacks: main changed native code since the PR branched." \- "Merge main into the PR, bump (cd apps/web && just android-bump), commit, and re-add android-update." >&2+if ! merge_result_native_check "bun scripts/android-native.mjs hash" "bun scripts/android-native.mjs listing" gh_fetch; then+ echo "A bundle from this head could never pass the merge gate. Merge ${BASE_BRANCH} into the PR," \+ "bump (cd apps/web && just android-bump), commit, and re-add android-update." >&2exit 1fiecho "version_code=${version_code}" >> "$GITHUB_OUTPUT"-echo "Releasing Android version code ${version_code} (native hash matches the merge result ${merge:0:10})."+echo "Releasing Android version code ${version_code}."# (`gh pr checks` names are job names, not workflow names.)ours='^(Android Native Check|Android Play Release|Re-run the native check|Web App Status Check|Android Release Drift|iOS Native Check)'diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/ios_native_tree.sh b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/ios_native_tree.shindex e0b4987246..562d6d09b6 100644--- a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/ios_native_tree.sh+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/ios_native_tree.sh@@ -24,16 +24,23 @@ NATIVE_TREE_PATH=apps/web/tauriCACHE_WASM_MANIFEST=crates/client/cache-wasm/Cargo.tomlexport NATIVE_TREE_EXCLUDE='(^|/)(android|macos|linux|windows|desktop)([_./-]|$)|\.(android|macos|linux|windows)\.|\.md$|^desktop-release\.json$|^\.helix/'-# native_tree_hash <commit>: prints the hash, fails if the path is missing.+# native_tree_listing <commit>: what the hash covers — the filtered ls-tree+# lines plus the cache wasm version — fails if the path is missing.# (--full-tree: ls-tree otherwise narrows its output to the current directory,# which would silently hash nothing when run from apps/web.)-native_tree_hash() {+native_tree_listing() {git rev-parse -q --verify "$1:${NATIVE_TREE_PATH}" >/dev/null || return 1- {- git ls-tree -r --full-tree "$1:${NATIVE_TREE_PATH}" \- | awk -F'\t' '$2 !~ ENVIRON["NATIVE_TREE_EXCLUDE"]'- echo "cache-wasm-version $(cache_wasm_version "$1")"- } | git hash-object --stdin+ git ls-tree -r --full-tree "$1:${NATIVE_TREE_PATH}" \+ | awk -F'\t' '$2 !~ ENVIRON["NATIVE_TREE_EXCLUDE"]'+ echo "cache-wasm-version $(cache_wasm_version "$1")"+}++# native_tree_hash <commit>: prints the hash of the listing, and fails when the+# listing does (a pipe would hash nothing and succeed).+native_tree_hash() {+ local listing+ listing=$(native_tree_listing "$1") || return 1+ git hash-object --stdin <<<"$listing"}# cache_wasm_version <commit>: the `version` of the client cache wasm packagediff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/ios_release_head_guard.sh b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/ios_release_head_guard.shindex a2d6b9453a..74b49d02e1 100644--- a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/ios_release_head_guard.sh+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/ios_release_head_guard.sh@@ -22,13 +22,10 @@ elsefiecho "PR head moved to ${head_sha:0:10} but its native tree is still ${built_tree:0:10}."fi-merge=$(pr_merge_commit)-native_tree_fetch "$merge"-merged_tree=$(native_tree_hash "$merge")-if [[ "$merged_tree" != "$built_tree" ]]; then- echo "iOS native code landed on main while this release was building: the merge result" \- "(${merge:0:10}) hashes ${merged_tree:0:10}, build ${built} ${built_tree:0:10}. Not submitting a build the merge gate could never accept." >&2- echo "Merge main into the PR, bump (${bump}), commit, and re-add the ios-update label." >&2+if ! merge_result_native_check native_tree_hash native_tree_listing native_tree_fetch; then+ echo "iOS native code landed on ${BASE_BRANCH} while this release was building. Not submitting build ${built}" \+ "(native tree ${built_tree:0:10}): the merge gate could never accept it." >&2+ echo "Merge ${BASE_BRANCH} into the PR, bump (${bump}), commit, and re-add the ios-update label." >&2exit 1fi-echo "Merge result ${merge:0:10} matches the built native tree (${built_tree:0:10}); submitting."+echo "Submitting build ${built} (native tree ${built_tree:0:10})."diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/ios_release_preconditions.sh b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/ios_release_preconditions.shindex 69d42a7df3..d2fafde121 100644--- a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/ios_release_preconditions.sh+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/ios_release_preconditions.sh@@ -26,14 +26,11 @@ fi# The gate compares the build's stamp with the native tree of the PR's merge# result, not of its head. A head that lacks iOS native code main gained since# the PR branched would go through App Review but could never pass the gate.-merge=$(pr_merge_commit)-native_tree_fetch "$merge"-if [[ "$(native_tree_hash "$merge")" != "$(native_tree_hash HEAD)" ]]; then- echo "PR #${PR_NUMBER}'s merge result (${merge:0:10}) has iOS native code this head lacks: main changed native code since the PR branched." \- "Merge main into the PR, bump (doppler run --project ios-release --config prd -- just ios-bump), commit, and re-add ios-update." >&2+if ! merge_result_native_check native_tree_hash native_tree_listing native_tree_fetch; then+ echo "A build from this head could never pass the merge gate. Merge ${BASE_BRANCH} into the PR," \+ "bump (doppler run --project ios-release --config prd -- just ios-bump), commit, and re-add ios-update." >&2exit 1fi-echo "Native tree matches the merge result ${merge:0:10}."# Web App Status Check aggregates the gate, so it is red whenever the gate is;# its other inputs (Typecheck, Test, Build, ...) are separate checks and stay.diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/merge_result_native_check.sh b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/merge_result_native_check.shnew file mode 100644index 0000000000..6eeb069302--- /dev/null+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/merge_result_native_check.sh@@ -0,0 +1,70 @@+# --- merge result native check ------------------------------------------------+# merge_result_native_check <hash> <listing> <fetch>: is the native code of+# PR #PR_NUMBER's merge result the native code of HEAD, the code this run+# built or is about to build? The merge gate hashes the merge result, so a+# build that differs from it could never pass the gate. <hash> / <listing>+# print a commit's native hash / the listing behind it; <fetch> makes a+# commit available (the iOS and Android helpers differ). Needs GH_TOKEN,+# GH_REPO, PR_NUMBER, BASE_BRANCH, and pr_merge_commit.+#+# GitHub's test merge commit answers directly when it exists. It doesn't for+# a PR that conflicts with its base, but the question still has an answer:+# if the base's native code hasn't moved since the PR branched, merging can+# only carry HEAD's native code, whatever files the conflicts are in. A+# refusal lists the native files the base changed.+merge_result_native_check() {+ local hash=$1 listing=$2 fetch=$3 built built_hash merge merge_hash compare tip \+ merge_base tip_hash base_hash why files+ # Callers run this under `if !`, which turns off `set -e` here, so every+ # lookup is checked: an empty commit hashes the same on both sides and would+ # pass an unchecked comparison.+ built=$(git rev-parse HEAD)+ if ! built_hash=$($hash "$built"); then+ echo "Could not hash this build's native code (${built:0:10})." >&2+ return 1+ fi+ merge=""+ if merge=$(pr_merge_commit); then+ if ! $fetch "$merge" || ! merge_hash=$($hash "$merge"); then+ echo "Could not fetch or hash PR #${PR_NUMBER}'s merge result (${merge:0:10})." >&2+ return 1+ fi+ if [[ "$merge_hash" == "$built_hash" ]]; then+ echo "Native code matches the merge result ${merge:0:10}."+ return 0+ fi+ why="PR #${PR_NUMBER}'s merge result (${merge:0:10}) has native code this build (${built:0:10}) lacks"+ fi+ if ! compare=$(gh api "repos/${GH_REPO}/compare/${BASE_BRANCH}...${built}" \+ --jq '"\(.base_commit.sha) \(.merge_base_commit.sha)"'); then+ echo "Could not compare ${BASE_BRANCH} with ${built:0:10}, so the merge result's native code is unverified." >&2+ return 1+ fi+ read -r tip merge_base <<<"$compare"+ if [[ -z "$tip" || -z "$merge_base" ]] || ! $fetch "$tip" || ! $fetch "$merge_base"; then+ echo "Could not fetch ${BASE_BRANCH} (${tip:0:10}) or the PR's branch point (${merge_base:0:10})." >&2+ return 1+ fi+ if [[ -z "$merge" ]]; then+ if ! tip_hash=$($hash "$tip") || ! base_hash=$($hash "$merge_base"); then+ echo "Could not hash ${BASE_BRANCH} (${tip:0:10}) or the PR's branch point (${merge_base:0:10})." >&2+ return 1+ fi+ if [[ "$tip_hash" == "$base_hash" ]]; then+ echo "PR #${PR_NUMBER} has no merge result (conflicts, or GitHub has not computed it), but ${BASE_BRANCH} (${tip:0:10})" \+ "still has the native code the PR branched from (${merge_base:0:10}), so merging can only carry this build's native code."+ return 0+ fi+ why="PR #${PR_NUMBER} has no merge result (conflicts, or GitHub has not computed it), and ${BASE_BRANCH} changed native code since the PR branched"+ fi+ # Listing lines are `<mode> <type> <sha>\t<path>` or `cache-wasm-version <v>`.+ # awk splits on the tab portably; BSD sed has no `\t` in a bracket.+ files=$({ diff <($listing "$merge_base") <($listing "$tip") || true; } \+ | awk -F'\t' '/^[<>] cache-wasm-version / { print " " substr($0, 3); next }+ /^[<>] / && NF > 1 { print " " $2 }' | sort -u)+ echo "${why}. Native changes on ${BASE_BRANCH} since ${merge_base:0:10}" \+ "(https://github.com/${GH_REPO}/compare/${merge_base:0:10}...${tip:0:10}):" >&2+ echo "${files:- (none listed: an excluded path?)}" >&2+ return 1+}+# ------------------------------------------------------------------------------diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/pr_merge_commit.sh b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/pr_merge_commit.shindex a6eeda9caa..e948f96a07 100644--- a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/pr_merge_commit.sh+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/pr_merge_commit.sh@@ -16,11 +16,11 @@ pr_merge_commit() {return 0fiif [[ "$mergeable" == "CONFLICTING" ]]; then- echo "::error::PR #${PR_NUMBER} conflicts with its base branch, so there is no merge result to check; resolve the conflicts first." >&2+ echo "PR #${PR_NUMBER} conflicts with its base branch, so GitHub has no merge result for it." >&2return 1fiif (( $(date +%s) > deadline )); then- echo "::error::GitHub has not computed PR #${PR_NUMBER}'s merge commit yet (mergeable=${mergeable}); retry in a minute." >&2+ echo "GitHub has not computed PR #${PR_NUMBER}'s merge commit yet (mergeable=${mergeable})." >&2return 1fiecho "Merge commit not computed yet (mergeable=${mergeable}); waiting." >&2diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/steps.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/steps.rsindex 491ab982c5..1cd668e079 100644--- a/tooling/xtask/crates/xtask_workflows/src/workflows/steps.rs+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/steps.rs@@ -93,6 +93,27 @@ pub fn setup_rust_light() -> Step<Use> {.add_with(("rust-cache", "false"))}+/// A `bash` step whose output the job's closing "Comment on the PR" step+/// quotes when the job fails. The step records its name in+/// `$RUNNER_TEMP/last-step.name` and tees its stdout and stderr into+/// `$RUNNER_TEMP/last-step.log`, both truncated at the step's start, so the+/// files describe the failed step when the comment step runs (it checks the+/// name against the API's failed step first: an unlogged step may have+/// failed since). Only for steps whose output is messages — the comment is+/// not secret-masked the way the log is, so a step that handles credentials+/// or runs a build stays an ordinary step.+pub fn logged_run(name: &str, script: impl AsRef<str>) -> Step<Run> {+ Step::new(name)+ .run(format!(+ "printf '%s\\n' \"$LOGGED_STEP\" > \"$RUNNER_TEMP/last-step.name\"\n\+ exec > >(tee \"$RUNNER_TEMP/last-step.log\") 2>&1\n\+ {}",+ script.as_ref()+ ))+ .shell("bash")+ .add_env(("LOGGED_STEP", name))+}+/// Install Nix on a macOS runner. The Linux [`setup_nix`] action doesn't apply/// there, so Apple jobs (DMG signing, the iOS simulator preview) install it/// with the same script instead.diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/web_app_check_main/ios_native_check.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/web_app_check_main/ios_native_check.rsindex e6345caa5e..ad264f6e96 100644--- a/tooling/xtask/crates/xtask_workflows/src/workflows/web_app_check_main/ios_native_check.rs+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/web_app_check_main/ios_native_check.rs@@ -7,7 +7,7 @@//!//! 1. Detects native changes: a path filter over `apps/web/tauri/**`,//! minus what never reaches the iOS binary (anything Android-only by-//! name, the desktop updater manifest, editor config) — the same+//! name, the desktop updater manifest, editor config, Markdown) — the same//! exclusions as the native tree hash in `scripts/ios_native_tree.sh` —//! or a bump of the client cache wasm package version//! (`crates/client/cache-wasm/Cargo.toml`): the app compiles the cache