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
chore(ci): migrate cancel-stuck-deploys cron to namespace + cargo x workflows (#4516)
teo2e2560397ae9
diff --git a/.github/workflows/cancel-stuck-cloud-storage-deploys.yml b/.github/workflows/cancel-stuck-cloud-storage-deploys.ymldeleted file mode 100644index 299009c24b..0000000000--- a/.github/workflows/cancel-stuck-cloud-storage-deploys.yml+++ /dev/null@@ -1,73 +0,0 @@-name: Cancel Stuck Cloud Storage Deploys--on:- schedule:- - cron: '0 * * * *'- workflow_dispatch:- inputs:- max-age-minutes:- description: Cancel active runs older than this many minutes- required: false- default: '90'- type: string- dry-run:- description: Log what would be cancelled without doing it- required: false- default: false- type: boolean--permissions:- actions: write- contents: read--jobs:- cancel-stuck:- name: Cancel runs stuck queued or in_progress past threshold- runs-on: ubuntu-latest- timeout-minutes: 5- env:- WORKFLOW_FILE: deploy-cloud-storage-on-push.yml- MAX_AGE_MINUTES: ${{ inputs.max-age-minutes || '90' }}- DRY_RUN: ${{ inputs.dry-run || 'false' }}- GH_TOKEN: ${{ github.token }}- GH_REPO: ${{ github.repository }}- steps:- - name: Cancel runs older than threshold- shell: bash- run: |- set -euo pipefail-- threshold_seconds=$(( MAX_AGE_MINUTES * 60 ))- now=$(date -u +%s)-- mapfile -t stuck < <(- gh api "repos/${GH_REPO}/actions/workflows/${WORKFLOW_FILE}/runs?per_page=100" \- | jq -r --argjson now "$now" --argjson threshold "$threshold_seconds" '- .workflow_runs[]- | select(.status == "queued" or .status == "in_progress")- | ($now - (.created_at | fromdateiso8601)) as $age- | select($age > $threshold)- | "\(.id)\t\($age)\t\(.html_url)"- '- )-- if [[ ${#stuck[@]} -eq 0 ]]; then- echo "No stuck runs found."- exit 0- fi-- echo "Found ${#stuck[@]} stuck run(s):"- for row in "${stuck[@]}"; do- IFS=$'\t' read -r run_id age url <<<"$row"- age_min=$(( age / 60 ))- echo " run ${run_id} (age ${age_min}m): ${url}"- if [[ "$DRY_RUN" == "true" ]]; then- echo " [dry-run] would cancel"- else- if gh api --method POST "repos/${GH_REPO}/actions/runs/${run_id}/cancel" >/dev/null 2>&1; then- echo " cancelled"- else- echo " cancel failed (may have already completed)"- fi- fi- donediff --git a/.github/workflows/cancel_stuck_cloud_storage_deploys.yml b/.github/workflows/cancel_stuck_cloud_storage_deploys.ymlnew file mode 100644index 0000000000..c3bbb52b6b--- /dev/null+++ b/.github/workflows/cancel_stuck_cloud_storage_deploys.yml@@ -0,0 +1,72 @@+# DO NOT EDIT — regenerate with `cargo x workflows` (from rust/cloud-storage).+# Source: rust/cloud-storage/tools/xtask/src/workflows/cancel_stuck_cloud_storage_deploys.rs+name: Cancel Stuck Cloud Storage Deploys+on:+ schedule:+ - cron: 0 * * * *+ workflow_dispatch:+ inputs:+ max-age-minutes:+ description: Cancel active runs older than this many minutes+ required: false+ default: '90'+ type: string+ dry-run:+ description: Log what would be cancelled without doing it+ required: false+ default: false+ type: boolean+permissions:+ actions: write+ contents: read+jobs:+ cancel-stuck:+ name: Cancel runs stuck queued or in_progress past threshold+ runs-on: namespace-profile-linux-tiny-no-cache+ env:+ WORKFLOW_FILE: deploy-cloud-storage-on-push.yml+ MAX_AGE_MINUTES: ${{ inputs.max-age-minutes || '90' }}+ DRY_RUN: ${{ inputs.dry-run || 'false' }}+ GH_TOKEN: ${{ github.token }}+ GH_REPO: ${{ github.repository }}+ timeout-minutes: 5+ steps:+ - name: Cancel runs older than threshold+ run: |+ set -euo pipefail++ threshold_seconds=$(( MAX_AGE_MINUTES * 60 ))+ now=$(date -u +%s)++ mapfile -t stuck < <(+ gh api "repos/${GH_REPO}/actions/workflows/${WORKFLOW_FILE}/runs?per_page=100" \+ | jq -r --argjson now "$now" --argjson threshold "$threshold_seconds" '+ .workflow_runs[]+ | select(.status == "queued" or .status == "in_progress")+ | ($now - (.created_at | fromdateiso8601)) as $age+ | select($age > $threshold)+ | "\(.id)\t\($age)\t\(.html_url)"+ '+ )++ if [[ ${#stuck[@]} -eq 0 ]]; then+ echo "No stuck runs found."+ exit 0+ fi++ echo "Found ${#stuck[@]} stuck run(s):"+ for row in "${stuck[@]}"; do+ IFS=$'\t' read -r run_id age url <<<"$row"+ age_min=$(( age / 60 ))+ echo " run ${run_id} (age ${age_min}m): ${url}"+ if [[ "$DRY_RUN" == "true" ]]; then+ echo " [dry-run] would cancel"+ else+ if gh api --method POST "repos/${GH_REPO}/actions/runs/${run_id}/cancel" >/dev/null 2>&1; then+ echo " cancelled"+ else+ echo " cancel failed (may have already completed)"+ fi+ fi+ done+ shell: bashdiff --git a/rust/cloud-storage/tools/xtask/src/workflows/cancel_stuck_cloud_storage_deploys.rs b/rust/cloud-storage/tools/xtask/src/workflows/cancel_stuck_cloud_storage_deploys.rsnew file mode 100644index 0000000000..eada9e9956--- /dev/null+++ b/rust/cloud-storage/tools/xtask/src/workflows/cancel_stuck_cloud_storage_deploys.rs@@ -0,0 +1,110 @@+//! `Cancel Stuck Cloud Storage Deploys` — hourly cron that cancels+//! `deploy-cloud-storage-on-push` runs stuck queued/in_progress past a+//! threshold. Generated into `cancel_stuck_cloud_storage_deploys.yml`+//! (replaces the hand-written `cancel-stuck-cloud-storage-deploys.yml`).+//!+//! Runs on the tiny no-cache profile: it's a single `gh api` + `jq` script+//! (both ship in Namespace's runner base image), no checkout, no build.++use anyhow::Result;+use gh_workflow::{Event, Job, Level, Permissions, Schedule, Step, Workflow, WorkflowDispatch};++use crate::workflows::runners;++/// Build the workflow. The `workflow_dispatch` input block is filled in by+/// [`patch`] (ordered map + typed boolean default).+pub fn cancel_stuck_cloud_storage_deploys() -> Workflow {+ Workflow::new("Cancel Stuck Cloud Storage Deploys")+ .on(Event::default()+ .add_schedule(Schedule::new("0 * * * *"))+ .workflow_dispatch(WorkflowDispatch::default()))+ .permissions(+ Permissions::default()+ .actions(Level::Write)+ .contents(Level::Read),+ )+ .add_job("cancel-stuck", cancel_stuck())+}++/// Fill in the ordered `workflow_dispatch` inputs block.+pub fn patch(root: &mut serde_yaml::Value) -> Result<()> {+ let on = root+ .get_mut("on")+ .and_then(serde_yaml::Value::as_mapping_mut)+ .ok_or_else(|| anyhow::anyhow!("rendered workflow has no `on` mapping"))?;+ on.insert(+ "workflow_dispatch".into(),+ crate::workflows::yaml_fragment(indoc::indoc! {r#"+ inputs:+ max-age-minutes:+ description: Cancel active runs older than this many minutes+ required: false+ default: '90'+ type: string+ dry-run:+ description: Log what would be cancelled without doing it+ required: false+ default: false+ type: boolean+ "#})?,+ );+ Ok(())+}++fn cancel_stuck() -> Job {+ Job::default()+ .name("Cancel runs stuck queued or in_progress past threshold")+ .runs_on(runners::Runner::TinyNoCache.to_string())+ .timeout_minutes(5u32)+ // Keep in sync with the deploy trigger's generated filename when the+ // deploy family is ported.+ .add_env(("WORKFLOW_FILE", "deploy-cloud-storage-on-push.yml"))+ .add_env(("MAX_AGE_MINUTES", "${{ inputs.max-age-minutes || '90' }}"))+ .add_env(("DRY_RUN", "${{ inputs.dry-run || 'false' }}"))+ .add_env(("GH_TOKEN", "${{ github.token }}"))+ .add_env(("GH_REPO", "${{ github.repository }}"))+ .add_step(cancel_runs())+}++fn cancel_runs() -> Step<gh_workflow::Run> {+ Step::new("Cancel runs older than threshold")+ .run(indoc::indoc! {r#"+ set -euo pipefail++ threshold_seconds=$(( MAX_AGE_MINUTES * 60 ))+ now=$(date -u +%s)++ mapfile -t stuck < <(+ gh api "repos/${GH_REPO}/actions/workflows/${WORKFLOW_FILE}/runs?per_page=100" \+ | jq -r --argjson now "$now" --argjson threshold "$threshold_seconds" '+ .workflow_runs[]+ | select(.status == "queued" or .status == "in_progress")+ | ($now - (.created_at | fromdateiso8601)) as $age+ | select($age > $threshold)+ | "\(.id)\t\($age)\t\(.html_url)"+ '+ )++ if [[ ${#stuck[@]} -eq 0 ]]; then+ echo "No stuck runs found."+ exit 0+ fi++ echo "Found ${#stuck[@]} stuck run(s):"+ for row in "${stuck[@]}"; do+ IFS=$'\t' read -r run_id age url <<<"$row"+ age_min=$(( age / 60 ))+ echo " run ${run_id} (age ${age_min}m): ${url}"+ if [[ "$DRY_RUN" == "true" ]]; then+ echo " [dry-run] would cancel"+ else+ if gh api --method POST "repos/${GH_REPO}/actions/runs/${run_id}/cancel" >/dev/null 2>&1; then+ echo " cancelled"+ else+ echo " cancel failed (may have already completed)"+ fi+ fi+ done+ "#})+ .shell("bash")+}diff --git a/rust/cloud-storage/tools/xtask/src/workflows/mod.rs b/rust/cloud-storage/tools/xtask/src/workflows/mod.rsindex 7d84cc3371..2e1ebbec97 100644--- a/rust/cloud-storage/tools/xtask/src/workflows/mod.rs+++ b/rust/cloud-storage/tools/xtask/src/workflows/mod.rs@@ -14,6 +14,7 @@ mod assign_labels;mod build_appimage_on_tag;mod build_desktop_on_tag;mod build_dmg_on_tag;+mod cancel_stuck_cloud_storage_deploys;mod check_generated;mod check_node_modules_nix;mod cleanup_preview;@@ -113,6 +114,16 @@ const WORKFLOWS: &[WorkflowFile] = &[file_name: "code_check_infra.yml",render_yaml: || render_gh_workflow(code_check_infra::code_check_infra)(),},+ WorkflowFile {+ slug: "cancel_stuck_cloud_storage_deploys",+ file_name: "cancel_stuck_cloud_storage_deploys.yml",+ render_yaml: || {+ render_patched(+ cancel_stuck_cloud_storage_deploys::cancel_stuck_cloud_storage_deploys,+ cancel_stuck_cloud_storage_deploys::patch,+ )+ },+ },WorkflowFile {slug: "cleanup_preview",file_name: "cleanup_preview.yml",