Last active
March 19, 2019 02:55
-
-
Save andipaetzold/94e470b4f74c85d426000d95791603fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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