This repository was archived by the owner on Feb 27, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcancel-deployments.ts
More file actions
75 lines (58 loc) · 1.99 KB
/
cancel-deployments.ts
File metadata and controls
75 lines (58 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env node
import { getBenchmarkProjects } from './util.ts'
import constants from './constants.json' with { type: 'json' }
import { Vercel } from '@vercel/sdk'
const VERCEL_TOKEN = process.env.VERCEL_TOKEN!
const { teamId } = constants
if (!VERCEL_TOKEN) {
console.error('Error: VERCEL_TOKEN is not set in .env')
process.exit(1)
}
const vercel = new Vercel({ bearerToken: VERCEL_TOKEN })
async function cancelCurrentDeployments() {
console.log('Fetching all benchmark projects...')
const projects = await getBenchmarkProjects(vercel, { limit: '100' })
if (!projects.length) {
console.log('No projects found')
return
}
console.log(`Found ${projects.length} projects to check`)
let totalCancelled = 0
for (const project of projects) {
console.log(`\nChecking project: ${project.name}`)
try {
const deploymentsData = await vercel.deployments.getDeployments({
projectId: project.id,
teamId,
limit: 100,
})
const deployments = deploymentsData.deployments.filter((deployment) =>
['QUEUED', 'BUILDING', 'INITIALIZING'].includes(deployment.state ?? ''),
)
if (deployments.length === 0) {
console.log(` No current deployments for ${project.name}`)
continue
}
console.log(` Found ${deployments.length} current deployment(s)`)
for (const deployment of deployments) {
try {
await vercel.deployments.cancelDeployment({
id: deployment.uid,
teamId,
})
console.log(` ✓ Cancelled deployment: ${deployment.uid}`)
totalCancelled++
} catch (error) {
console.error(
` ✗ Failed to cancel deployment ${deployment.uid}:`,
error,
)
}
}
} catch (error) {
console.error(`✗ Failed to process ${project.name}:`, error)
}
}
console.log(`\nDone! Cancelled ${totalCancelled} current deployment(s)`)
}
cancelCurrentDeployments().catch(console.error)