#!/usr/bin/env bun /** * Read-only sweep of us-east-1 for anything a live-check run may have left: * resources carrying `ts-cloud-livecheck=`, or tagged or named after * the scratch project. Exits 0 only when nothing is found. * * AWS_PROFILE=stacks bun --no-env-file scripts/livecheck/sweep.ts [--json] */ import { findResources, guard } from './lib' const [runId, project] = process.argv.slice(2).filter(arg => !arg.startsWith('--')) if (!runId || !project) { console.error('usage: AWS_PROFILE=stacks bun --no-env-file scripts/livecheck/sweep.ts [--json]') process.exit(2) } if (project.length < 12) { // A short name would match unrelated resources by substring. console.error(`Refusing a project name this short (${project}); use the scratch name, e.g. tscloud-livecheck-20261202`) process.exit(2) } let found: ReturnType try { guard() found = findResources(runId, project) } catch (error) { // An error is not an empty account: never exit 0 on one. console.error(`sweep failed: ${error instanceof Error ? error.message : String(error)}`) process.exit(2) } if (process.argv.includes('--json')) console.log(JSON.stringify(found, null, 2)) else if (!found.length) console.log(`sweep: nothing found for ${runId} / ${project} in us-east-1`) else { console.log(`sweep: ${found.length} resource(s) found for ${runId} / ${project} in us-east-1:`) for (const item of found.sort((a, b) => a.type.localeCompare(b.type))) console.log(` ${item.type.padEnd(21)} ${item.id} ${item.tagged ? '[run tag]' : '[name/project match]'} ${item.detail}`) } process.exit(found.length ? 1 : 0)