Skip to content

Instantly share code, notes, and snippets.

@mortenson
Created January 2, 2024 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mortenson/52c57d3dcf21766e627a11ac838e2d20 to your computer and use it in GitHub Desktop.
Save mortenson/52c57d3dcf21766e627a11ac838e2d20 to your computer and use it in GitHub Desktop.
Bash script to wait for the given Render services to finish deploying. Useful for triggering deploy hooks sequentially, or tracking deploy status in GitHub actions.
#! /bin/bash
# RENDER_SERVICE_NAMES should be a newline-separated list of service IDs (ex: srv-...)
# RENDER_API_TOKEN is your personal Render API token
max_attempts=200
while IFS= read -r RENDER_SERVICE_NAME; do
echo "Checking $RENDER_SERVICE_NAME ..."
attempt_counter=0
while true
do
# List deploys for this service.
response=$(curl --max-time 30 -sSf "https://api.render.com/v1/services/$RENDER_SERVICE_NAME/deploys" -H 'Accept: application/json' -H "Authorization: Bearer $RENDER_API_TOKEN")
if [ $? -ne 0 ]
then
echo "Request failed"
exit 1
fi
# See if any deploys are in progress.
echo "$response" | grep -vq "in_progress"
if [ $? -eq 0 ]
then
echo "No deploys are running!"
break
fi
# Check if we've waited too long.
if [ ${attempt_counter} -eq ${max_attempts} ]
then
echo "Max attempts reached"
exit 1
fi
# Sleep and again.
echo "Waiting for deploy to finish ..."
attempt_counter=$(($attempt_counter+1))
sleep 2;
done
done <<< "$RENDER_SERVICE_NAMES"
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment