|
| 1 | +#!/bin/sh |
| 2 | +# Executed when the `master` or `staging` branches of PokeAPI/api-data and PokeAPI/pokeapi.co are pushed to |
| 3 | +# Runs in CircleCI |
| 4 | +# Deploys both pokeapi.co and api-data to Firebase in the respective project |
| 5 | +# $FIREBASE_DEPLOY_TOKEN, $FIREBASE_PROJECT_ID, $FIREBASE_DEPLOY_TOKEN_STAGING, $FIREBASE_PROJECT_ID_STAGING are present in CircleCI |
| 6 | +# $deploy_location is an environment variable set when the job is triggered by one of the two repositories getting pushed |
| 7 | + |
| 8 | +if [ "${deploy_location:=master}" = 'master' ]; then # https://stackoverflow.com/a/2013589/3482533 |
| 9 | + echo 'Deploying master branches of PokeAPI/api-data and PokeAPI/pokeapi.co to https://pokeapi.co' |
| 10 | + TOKEN=${FIREBASE_DEPLOY_TOKEN} |
| 11 | + PROJECT=${FIREBASE_PROJECT_ID} |
| 12 | +elif [ "${deploy_location}" = 'staging' ]; then |
| 13 | + echo 'Deploying staging branches of PokeAPI/api-data and PokeAPI/pokeapi.co to the staging location' |
| 14 | + TOKEN=${FIREBASE_DEPLOY_TOKEN_STAGING} |
| 15 | + PROJECT=${FIREBASE_PROJECT_ID_STAGING} |
| 16 | +fi |
| 17 | + |
| 18 | +mkdir -p public |
| 19 | + |
| 20 | +# Get stored artifacts from api-data and unpack into the 'public' directory |
| 21 | +wget -O '_gen.tar.gz' "$(curl -s https://circleci.com/api/v1.1/project/github/PokeAPI/api-data/latest/artifacts?branch=${deploy_location} | jq -r .[0].url)" |
| 22 | +if [ $? -ne 0 ]; then |
| 23 | + echo "Couldn't find the latest api-data .tar.gz for the branch ${deploy_location}" |
| 24 | + exit 1 |
| 25 | +fi |
| 26 | +tar xzf _gen.tar.gz -C public |
| 27 | + |
| 28 | +# Get stored artifacts from pokeapi.co and unpack into the current directory |
| 29 | +wget -O 'static_website.tar.gz' "$(curl -s https://circleci.com/api/v1.1/project/github/PokeAPI/pokeapi.co/latest/artifacts?branch=${deploy_location} | jq -r .[0].url)" |
| 30 | +if [ $? -ne 0 ]; then |
| 31 | + echo "Couldn't find the latest pokeapi.co website .tar.gz for the branch ${deploy_location}" |
| 32 | + exit 1 |
| 33 | +fi |
| 34 | +tar xzf static_website.tar.gz -C public |
| 35 | + |
| 36 | +# Deploy to Firebase |
| 37 | +yarn --ignore-engines --cwd functions install |
| 38 | +functions/node_modules/.bin/firebase deploy --token="${TOKEN}" --project="${PROJECT}" |
0 commit comments