1#!/usr/bin/env bash
2
3set -euo pipefail
4
5if [[ -z "${VERCEL_TOKEN:-}" ]]; then
6 echo "Error: VERCEL_TOKEN environment variable is not set."
7 echo "Get a token from https://vercel.com/account/tokens"
8 exit 1
9fi
10
11MAX_ATTEMPTS="60"
12SLEEP_SECONDS="10"
13VERCEL_SCOPE="zed-industries"
14VERCEL_URL="https://zed.dev"
15
16echo "Checking for in-progress deployments..."
17
18for ((i=1; i<=MAX_ATTEMPTS; i++)); do
19 RESPONSE=$(curl -s -H "Authorization: Bearer $VERCEL_TOKEN" \
20 "https://api.vercel.com/v6/deployments?slug=${VERCEL_SCOPE}&state=BUILDING,INITIALIZING,QUEUED&target=production&limit=1")
21
22 COUNT=$(echo "$RESPONSE" | jq '.deployments | length')
23
24 if [ "$COUNT" = "0" ]; then
25 echo "No in-progress deployments found. Proceeding with redeploy."
26 break
27 fi
28
29 if [ "$i" = "$MAX_ATTEMPTS" ]; then
30 echo "Timed out waiting for deployments to complete after $((MAX_ATTEMPTS * SLEEP_SECONDS)) seconds."
31 exit 1
32 fi
33
34 echo "Attempt $i/$MAX_ATTEMPTS: Found $COUNT in-progress deployment(s). Waiting ${SLEEP_SECONDS}s..."
35 sleep "$SLEEP_SECONDS"
36done
37
38echo "Triggering redeploy of ${VERCEL_URL}..."
39npm exec --yes -- vercel@37 --token="$VERCEL_TOKEN" --scope "$VERCEL_SCOPE" redeploy "$VERCEL_URL"