Skip to content

Commit

Permalink
chore: add updates to force redeployment on Vercel
Browse files Browse the repository at this point in the history
  • Loading branch information
Parkreiner committed Nov 22, 2024
1 parent 5101c27 commit 28d6879
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
58 changes: 58 additions & 0 deletions .github/scripts/check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ required_vars=(
"INSTATUS_API_KEY"
"INSTATUS_PAGE_ID"
"INSTATUS_COMPONENT_ID"
"VERCEL_API_KEY"

)

# Check if each required variable is set
Expand All @@ -17,6 +19,11 @@ for var in "${required_vars[@]}"; do
fi
done

JUST_REDEPLOYED="$JUST_REDEPLOYED:-0"
if (JUST_REDEPLOYED); do
return 1
fi

REGISTRY_BASE_URL="${REGISTRY_BASE_URL:-https://registry.coder.com}"

status=0
Expand Down Expand Up @@ -74,6 +81,41 @@ create_incident() {
echo "$incident_id"
}

force_redeploy_registry () {
# These are not secret values; safe to just expose directly in script
local VERCEL_TEAM_SLUG="codercom"
local VERCEL_TEAM_ID="team_tGkWfhEGGelkkqUUm9nXq17r"
local VERCEL_APP="registry"

local latest_res=$(curl "https://api.vercel.com/v6/deployments?app=$VERCEL_APP&limit=1&slug=$VERCEL_TEAM_SLUG&teamId=$VERCEL_TEAM_ID" \
--fail \
--silent \
-H "Authorization: Bearer $VERCEL_API_KEY" \
-H "Content-Type: application/json"
)

# If we have zero deployments, something is VERY wrong. Make the whole
# script exit with a non-zero status code
local latest_id=$(echo $latest_res | jq '.deployments[0].uid')
if (( latest_id == "null" )); do
echo "Unable to pull any previous deployments for redeployment"
return 1
fi

local redeploy_res=$(curl -X POST "https://api.vercel.com/v13/deployments?forceNew=1&skipAutoDetectionConfirmation=1&slug=$VERCEL_TEAM_SLUG&teamId=$VERCEL_TEAM_ID" \
--fail \
--silent \
--output "/dev/null" \
-H "Authorization: Bearer $VERCEL_API_KEY" \
-H "Content-Type: application/json" \
-d "{
"deploymentId": $latest_id,
}"
)

echo $redeploy_res
}

# Check each module's accessibility
for module in "${modules[@]}"; do
# Trim leading/trailing whitespace from module name
Expand All @@ -96,6 +138,8 @@ if (( status == 0 )); then
echo "All modules are operational."
# set to
update_component_status "OPERATIONAL"

echo "JUST_REDEPLOYED=0" >> $GITHUB_ENV
else
echo "The following modules have issues: ${failures[*]}"
# check if all modules are down
Expand All @@ -108,6 +152,20 @@ else
# Create a new incident
incident_id=$(create_incident)
echo "Created incident with ID: $incident_id"

# If a module is down, force a reployment to try getting things back online
# ASAP
status_code=$(force_redeploy_registry)
# shellcheck disable=SC2181
if (( status_code == 200 )); then
echo "Reployment successful"
else
echo "Unable to redeploy automatically"
fi

# Update environment variable so that if automatic re-deployment fails, we
# don't keep running the script over and over again
echo "JUST_REDEPLOYED=1" >> $GITHUB_ENV
fi

exit "${status}"
1 change: 1 addition & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ jobs:
INSTATUS_API_KEY: ${{ secrets.INSTATUS_API_KEY }}
INSTATUS_PAGE_ID: ${{ secrets.INSTATUS_PAGE_ID }}
INSTATUS_COMPONENT_ID: ${{ secrets.INSTATUS_COMPONENT_ID }}
VERCEL_API_KEY: ${{ secrets.VERCEL_API_KEY }}

0 comments on commit 28d6879

Please sign in to comment.