Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save impaler/d194d26e8e4329f2621a8579dcbc2549 to your computer and use it in GitHub Desktop.
Save impaler/d194d26e8e4329f2621a8579dcbc2549 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
@impaler
Copy link
Author

impaler commented Mar 19, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment