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
feat(ci): tell the author when a release label cannot start a release (#8425)
Peter Chinmanc13d3a1e8fe8
diff --git a/.github/workflows/release-label-check.yml b/.github/workflows/release-label-check.ymlnew file mode 100644index 0000000000..1e5703bfc1--- /dev/null+++ b/.github/workflows/release-label-check.yml@@ -0,0 +1,124 @@+# DO NOT EDIT — regenerate with `cargo x workflows` (from the repository root).+# Source: tooling/xtask/crates/xtask_workflows/src/workflows/release_label_check.rs+name: Release Label Check+'on':+ pull_request_target:+ types:+ - labeled+jobs:+ check:+ if: github.event.label.name == 'ios-update' || github.event.label.name == 'android-update'+ name: Announce the release the label started+ runs-on: namespace-profile-linux-tiny-no-cache+ permissions:+ pull-requests: write+ env:+ GH_TOKEN: ${{ github.token }}+ GH_REPO: ${{ github.repository }}+ PR_NUMBER: ${{ github.event.pull_request.number }}+ HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}+ HEAD_REF: ${{ github.event.pull_request.head.ref }}+ HEAD_SHA: ${{ github.event.pull_request.head.sha }}+ LABEL: ${{ github.event.label.name }}+ PLATFORM: ${{ github.event.label.name == 'ios-update' && 'iOS' || 'Android' }}+ WORKFLOW: ${{ github.event.label.name == 'ios-update' && 'iOS App Store Release' || 'Android Play Release' }}+ WORKFLOW_FILE: ${{ github.event.label.name == 'ios-update' && 'ios-app-store-release.yml' || 'android-play-release.yml' }}+ CONF_PATH: ${{ github.event.label.name == 'ios-update' && 'apps/web/tauri/src-tauri/tauri.ios.conf.json' || 'apps/web/tauri/src-tauri/tauri.android.conf.json' }}+ timeout-minutes: 10+ steps:+ - name: Announce the release, or explain why none started+ run: |+ # --- PR merge result ----------------------------------------------------------+ # pr_merge_commit: print the sha of GitHub's test merge commit for $PR_NUMBER —+ # the merge result the native gates hash. GitHub computes it lazily+ # (mergeable=UNKNOWN until it has), so poll a little; a PR that really+ # conflicts with its base cannot merge anyway. Needs GH_TOKEN, GH_REPO,+ # PR_NUMBER. Progress goes to stderr so `merge=$(pr_merge_commit)` works.+ pr_merge_commit() {+ local deadline pr_json mergeable merge+ deadline=$(( $(date +%s) + 120 ))+ while true; do+ pr_json=$(gh pr view "$PR_NUMBER" --repo "$GH_REPO" --json mergeable,potentialMergeCommit)+ mergeable=$(jq -r '.mergeable' <<<"$pr_json")+ merge=$(jq -r '.potentialMergeCommit.oid // empty' <<<"$pr_json")+ if [[ -n "$merge" ]]; then+ echo "$merge"+ return 0+ fi+ if [[ "$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+ return 1+ fi+ if (( $(date +%s) > deadline )); then+ echo "::error::GitHub has not computed PR #${PR_NUMBER}'s merge commit yet (mergeable=${mergeable}); retry in a minute." >&2+ return 1+ fi+ echo "Merge commit not computed yet (mergeable=${mergeable}); waiting." >&2+ sleep 10+ done+ }+ # ------------------------------------------------------------------------------+ set -euo pipefail+ # The $WORKFLOW workflow runs on `pull_request` events. GitHub delivers none+ # for a PR that conflicts with its base, and the release job skips fork PRs;+ # either way the label did nothing and nobody was told. Say so on the PR and+ # take the label off: a release label with no release behind it misleads the+ # drift and watch workflows. On a mergeable PR the label did start a release:+ # announce it, with the version in flight and the run to watch (the run+ # itself comments the outcome when it ends).+ announce_release() {+ local since deadline run url conf what steps+ # The release run was created by the same label event as this one, so it+ # exists by now; the window only keeps an older run for the same head (an+ # earlier label add) from being mistaken for it. Runs the release job+ # skipped (another label added at the same time) complete within seconds.+ since=$(date -u -d '-10 minutes' +%FT%TZ)+ deadline=$(( $(date +%s) + 120 ))+ while true; do+ run=$(gh run list --repo "$GH_REPO" --workflow "$WORKFLOW_FILE" --event pull_request --branch "$HEAD_REF" \+ --json databaseId,url,createdAt,headSha,conclusion --limit 10 \+ --jq "[.[] | select(.headSha == \"${HEAD_SHA}\" and .createdAt >= \"${since}\" and .conclusion != \"skipped\")] | first // empty")+ [[ -n "$run" ]] && break+ if (( $(date +%s) > deadline )); then+ gh pr comment "$PR_NUMBER" --repo "$GH_REPO" --body "⚠️ This PR is mergeable, but no **${WORKFLOW}** run has appeared for it in two minutes. Remove and re-add the \`${LABEL}\` label."+ return 0+ fi+ echo "No ${WORKFLOW} run for ${HEAD_SHA:0:10} yet; waiting."+ sleep 10+ done+ url=$(jq -r '.url' <<<"$run")+ conf=$(gh api "repos/${GH_REPO}/contents/${CONF_PATH}?ref=${HEAD_SHA}" --jq '.content' | base64 --decode)+ if [[ "$LABEL" == ios-update ]]; then+ what="iOS $(jq -r '.version' <<<"$conf") (build $(jq -r '.bundle.iOS.bundleVersion' <<<"$conf"))"+ steps="builds the app, uploads it to TestFlight and submits it for App Review"+ else+ what="Android version code $(jq -r '.bundle.android.versionCode' <<<"$conf")"+ steps="builds the App Bundle, uploads it to the internal track and promotes it to production"+ fi+ gh pr comment "$PR_NUMBER" --repo "$GH_REPO" --body "🚀 **${WORKFLOW}** started for ${what} at ${HEAD_SHA:0:10} ([workflow run](${url})). It ${steps}, then comments here with the result."+ echo "PR #${PR_NUMBER}: ${WORKFLOW} started for ${what}: ${url}"+ }+ if [[ "$HEAD_REPO" != "$GH_REPO" ]]; then+ why="this PR comes from a fork (\`${HEAD_REPO}\`), and releases are only built from branches in this repository."+ next="Push the branch to this repository, open a PR from it, and add the \`${LABEL}\` label there."+ elif merge=$(pr_merge_commit); then+ echo "PR #${PR_NUMBER} is mergeable (merge result ${merge:0:10}); the ${WORKFLOW} workflow should have started."+ announce_release+ exit 0+ elif [[ "$(gh pr view "$PR_NUMBER" --repo "$GH_REPO" --json mergeable --jq '.mergeable')" == "CONFLICTING" ]]; then+ why="this PR has merge conflicts with its base branch, and GitHub does not run \`pull_request\` workflows (the **${WORKFLOW}** workflow among them) on a conflicting PR."+ next="Resolve the conflicts, wait for the checks, then re-add the \`${LABEL}\` label."+ else+ # Still UNKNOWN after the helper's polling: GitHub may or may not have run+ # the release. Say so without touching the label — removing it under a+ # release that did start would hide that release from the drift and watch+ # workflows.+ gh pr comment "$PR_NUMBER" --repo "$GH_REPO" --body "⚠️ GitHub has not worked out whether this PR is mergeable, so it is unclear whether the **${WORKFLOW}** workflow started. If no **${WORKFLOW}** run appears in this PR's checks within a few minutes, remove and re-add the \`${LABEL}\` label."+ exit 0+ fi+ gh pr edit "$PR_NUMBER" --repo "$GH_REPO" --remove-label "$LABEL"+ gh pr comment "$PR_NUMBER" --repo "$GH_REPO" --body "⚠️ The ${PLATFORM} release did not start: ${why} The \`${LABEL}\` label was removed.++ ${next}"+ echo "PR #${PR_NUMBER}: ${why}"+ shell: bashdiff --git a/apps/web/docs/ios-releases.md b/apps/web/docs/ios-releases.mdindex 300c0a7461..eae22a8841 100644--- a/apps/web/docs/ios-releases.md+++ b/apps/web/docs/ios-releases.md@@ -69,6 +69,14 @@ icon and app-name branding are Android-only.itself: that would need a user token, because a merge set up by theActions token doesn't trigger the push-to-`main` workflows such as thedev redeploy.) 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 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 workflow+ instead comments that the release started, with the version in flight+ and a link to the run.4. Wait for Apple to approve. The version releases automatically, and the**`iOS Release Watch`** workflow (`.github/workflows/ios-release-watch.yml`,every 30 minutes) notices: for each open PR labeled `ios-update` it asks@@ -97,7 +105,7 @@ a CI-pushed bump commit would wedge the PR.If the tauri change doesn't break the native/web contract (comments, dev-onlytooling, desktop-only config), add the **`skip-ios-update`** label instead;-the **`iOS Native Check Label`** workflow re-runs just the gate job (and the+the **`Native Check Label`** workflow re-runs just the gate job (and thestatus check that depends on it) when that label is added or removed, so thegate passes without a release and without re-running the whole web suite.That workflow is not a required check: it waits for the web suite run todiff --git a/docs/development/android.md b/docs/development/android.mdindex d350240c95..7d92342e84 100644--- a/docs/development/android.md+++ b/docs/development/android.md@@ -168,7 +168,14 @@ To release:`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 toretry. Click **Enable auto-merge** on the PR to merge the moment it is- live.+ 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 workflow+ instead comments that the release started, with the version in flight+ and a link to the run.3. Wait for Google. The **`Android Release Watch`** workflow (every 30minutes) notices the version code being published on production, re-runsthe PR's failed `Android Native Check` job, and comments; the PR merges ifdiff --git a/tooling/xtask/crates/xtask_workflows/src/workflows.rs b/tooling/xtask/crates/xtask_workflows/src/workflows.rsindex 055f0bba5f..1ca6f6f180 100644--- a/tooling/xtask/crates/xtask_workflows/src/workflows.rs+++ b/tooling/xtask/crates/xtask_workflows/src/workflows.rs@@ -50,6 +50,7 @@ mod path_validation;mod publish_sdk;mod pulumi_preview_pr;mod push_local_stack_binaries;+mod release_label_check;mod release_sdk;mod reusable_deploy_service;mod reusable_preview_service;@@ -309,6 +310,11 @@ const WORKFLOWS: &[WorkflowFile] = &[file_name: "native-check-label.yml",render_yaml: || render_gh_workflow(native_check_label::native_check_label)(),},+ WorkflowFile {+ slug: "release_label_check",+ file_name: "release-label-check.yml",+ render_yaml: || render_gh_workflow(release_label_check::release_label_check)(),+ },WorkflowFile {slug: "android_play_release",file_name: "android-play-release.yml",diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/release_label_check.rs b/tooling/xtask/crates/xtask_workflows/src/workflows/release_label_check.rsnew file mode 100644index 0000000000..1e4cbb5943--- /dev/null+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/release_label_check.rs@@ -0,0 +1,73 @@+//! `Release Label Check` — tells the author when an `ios-update` /+//! `android-update` label could not start a release. The release workflows+//! run on `pull_request` events, and GitHub creates no run at all for a+//! `pull_request` event on a PR that conflicts with its base (there is no+//! merge ref to run against); the release job also skips fork PRs. In both+//! cases the label silently does nothing, and nothing is left on the PR to+//! say so. `pull_request_target` events are delivered regardless, so this+//! workflow explains on the PR and removes the label: a release label with+//! no release behind it would make the drift and watch workflows treat the+//! next push as a drifted release. On a mergeable PR it instead announces the+//! release that did start, with the version in flight and a link to the run.+//!+//! `pull_request_target` runs with base-repo permissions on fork PRs, so+//! this job must never check out or execute PR head code — there is+//! deliberately no checkout step; it only reads event metadata and calls the+//! PR API.++use gh_workflow::{+ Event, Expression, Job, Level, Permissions, PullRequestTarget, PullRequestType, Step, Workflow,+};++use crate::workflows::runners;++/// Build the workflow.+pub fn release_label_check() -> Workflow {+ Workflow::new("Release Label Check")+ .on(Event::default()+ .pull_request_target(PullRequestTarget::default().add_type(PullRequestType::Labeled)))+ .add_job("check", check_job())+}++fn check_job() -> Job {+ Job::default()+ .name("Announce the release the label started")+ .cond(Expression::new(+ "github.event.label.name == 'ios-update' || github.event.label.name == 'android-update'",+ ))+ .runs_on(runners::Runner::TinyNoCache.to_string())+ .timeout_minutes(10u32)+ // Write: the job comments on the PR and removes the label.+ .permissions(Permissions::default().pull_requests(Level::Write))+ .add_env(("GH_TOKEN", "${{ github.token }}"))+ .add_env(("GH_REPO", "${{ github.repository }}"))+ .add_env(("PR_NUMBER", "${{ github.event.pull_request.number }}"))+ .add_env(("HEAD_REPO", "${{ github.event.pull_request.head.repo.full_name }}"))+ .add_env(("HEAD_REF", "${{ github.event.pull_request.head.ref }}"))+ .add_env(("HEAD_SHA", "${{ github.event.pull_request.head.sha }}"))+ .add_env(("LABEL", "${{ github.event.label.name }}"))+ .add_env((+ "PLATFORM",+ "${{ github.event.label.name == 'ios-update' && 'iOS' || 'Android' }}",+ ))+ .add_env((+ "WORKFLOW",+ "${{ github.event.label.name == 'ios-update' && 'iOS App Store Release' || 'Android Play Release' }}",+ ))+ .add_env((+ "WORKFLOW_FILE",+ "${{ github.event.label.name == 'ios-update' && 'ios-app-store-release.yml' || 'android-play-release.yml' }}",+ ))+ .add_env((+ "CONF_PATH",+ "${{ github.event.label.name == 'ios-update' && 'apps/web/tauri/src-tauri/tauri.ios.conf.json' || 'apps/web/tauri/src-tauri/tauri.android.conf.json' }}",+ ))+ .add_step(+ Step::new("Announce the release, or explain why none started")+ .run(concat!(+ include_str!("scripts/pr_merge_commit.sh"),+ include_str!("scripts/release_label_check.sh"),+ ))+ .shell("bash"),+ )+}diff --git a/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/release_label_check.sh b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/release_label_check.shnew file mode 100644index 0000000000..db1f123b66--- /dev/null+++ b/tooling/xtask/crates/xtask_workflows/src/workflows/scripts/release_label_check.sh@@ -0,0 +1,63 @@+set -euo pipefail+# The $WORKFLOW workflow runs on `pull_request` events. GitHub delivers none+# for a PR that conflicts with its base, and the release job skips fork PRs;+# either way the label did nothing and nobody was told. Say so on the PR and+# take the label off: a release label with no release behind it misleads the+# drift and watch workflows. On a mergeable PR the label did start a release:+# announce it, with the version in flight and the run to watch (the run+# itself comments the outcome when it ends).+announce_release() {+ local since deadline run url conf what steps+ # The release run was created by the same label event as this one, so it+ # exists by now; the window only keeps an older run for the same head (an+ # earlier label add) from being mistaken for it. Runs the release job+ # skipped (another label added at the same time) complete within seconds.+ since=$(date -u -d '-10 minutes' +%FT%TZ)+ deadline=$(( $(date +%s) + 120 ))+ while true; do+ run=$(gh run list --repo "$GH_REPO" --workflow "$WORKFLOW_FILE" --event pull_request --branch "$HEAD_REF" \+ --json databaseId,url,createdAt,headSha,conclusion --limit 10 \+ --jq "[.[] | select(.headSha == \"${HEAD_SHA}\" and .createdAt >= \"${since}\" and .conclusion != \"skipped\")] | first // empty")+ [[ -n "$run" ]] && break+ if (( $(date +%s) > deadline )); then+ gh pr comment "$PR_NUMBER" --repo "$GH_REPO" --body "⚠️ This PR is mergeable, but no **${WORKFLOW}** run has appeared for it in two minutes. Remove and re-add the \`${LABEL}\` label."+ return 0+ fi+ echo "No ${WORKFLOW} run for ${HEAD_SHA:0:10} yet; waiting."+ sleep 10+ done+ url=$(jq -r '.url' <<<"$run")+ conf=$(gh api "repos/${GH_REPO}/contents/${CONF_PATH}?ref=${HEAD_SHA}" --jq '.content' | base64 --decode)+ if [[ "$LABEL" == ios-update ]]; then+ what="iOS $(jq -r '.version' <<<"$conf") (build $(jq -r '.bundle.iOS.bundleVersion' <<<"$conf"))"+ steps="builds the app, uploads it to TestFlight and submits it for App Review"+ else+ what="Android version code $(jq -r '.bundle.android.versionCode' <<<"$conf")"+ steps="builds the App Bundle, uploads it to the internal track and promotes it to production"+ fi+ gh pr comment "$PR_NUMBER" --repo "$GH_REPO" --body "🚀 **${WORKFLOW}** started for ${what} at ${HEAD_SHA:0:10} ([workflow run](${url})). It ${steps}, then comments here with the result."+ echo "PR #${PR_NUMBER}: ${WORKFLOW} started for ${what}: ${url}"+}+if [[ "$HEAD_REPO" != "$GH_REPO" ]]; then+ why="this PR comes from a fork (\`${HEAD_REPO}\`), and releases are only built from branches in this repository."+ next="Push the branch to this repository, open a PR from it, and add the \`${LABEL}\` label there."+elif merge=$(pr_merge_commit); then+ echo "PR #${PR_NUMBER} is mergeable (merge result ${merge:0:10}); the ${WORKFLOW} workflow should have started."+ announce_release+ exit 0+elif [[ "$(gh pr view "$PR_NUMBER" --repo "$GH_REPO" --json mergeable --jq '.mergeable')" == "CONFLICTING" ]]; then+ why="this PR has merge conflicts with its base branch, and GitHub does not run \`pull_request\` workflows (the **${WORKFLOW}** workflow among them) on a conflicting PR."+ next="Resolve the conflicts, wait for the checks, then re-add the \`${LABEL}\` label."+else+ # Still UNKNOWN after the helper's polling: GitHub may or may not have run+ # the release. Say so without touching the label — removing it under a+ # release that did start would hide that release from the drift and watch+ # workflows.+ gh pr comment "$PR_NUMBER" --repo "$GH_REPO" --body "⚠️ GitHub has not worked out whether this PR is mergeable, so it is unclear whether the **${WORKFLOW}** workflow started. If no **${WORKFLOW}** run appears in this PR's checks within a few minutes, remove and re-add the \`${LABEL}\` label."+ exit 0+fi+gh pr edit "$PR_NUMBER" --repo "$GH_REPO" --remove-label "$LABEL"+gh pr comment "$PR_NUMBER" --repo "$GH_REPO" --body "⚠️ The ${PLATFORM} release did not start: ${why} The \`${LABEL}\` label was removed.++${next}"+echo "PR #${PR_NUMBER}: ${why}"