Skip to content

Instantly share code, notes, and snippets.

@andipaetzold
Last active March 19, 2019 02:55
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andipaetzold/94e470b4f74c85d426000d95791603fd to your computer and use it in GitHub Desktop.
Save andipaetzold/94e470b4f74c85d426000d95791603fd to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eo pipefail
echo "Deleting existing hosting releases"
SITE=$1
echo "Site: $SITE"
HEADER_AUTH="Authorization: Bearer "$(gcloud auth application-default print-access-token)"";
PAGE_TOKEN=
FIRST=true
while :
do
echo "Fetching releases for $PAGE_TOKEN"
RELEASES=$( \
curl \
-sS \
-H "$HEADER_AUTH" \
"https://firebasehosting.googleapis.com/v1beta1/sites/$SITE/releases?pageToken=$PAGE_TOKEN&pageSize=25" \
)
for RELEASE_ID in $(echo $RELEASES | jq '.releases | keys[]')
do
VERSION_NAME=$(echo $RELEASES | jq --raw-output ".releases[$RELEASE_ID].version.name")
MESSAGE=$(echo $RELEASES | jq --raw-output ".releases[$RELEASE_ID].message")
VERSION_STATUS=$(echo $RELEASES | jq --raw-output ".releases[$RELEASE_ID].version.status")
if [ "$VERSION_STATUS" == "FINALIZED" ] && [ "$FIRST" == false ]
then
echo "Deleting release $MESSAGE ($VERSION_NAME)";
curl \
-sS \
-X DELETE \
-H "$HEADER_AUTH" \
"https://firebasehosting.googleapis.com/v1beta1/$VERSION_NAME"
fi
FIRST=false
done
if [ $(echo $RELEASES | jq --raw-output '.nextPageToken') == "null" ]
then
exit 0
fi
PAGE_TOKEN=$(echo $RELEASES | jq --raw-output '.nextPageToken')
sleep 1s
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment