deploy-storybook.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/bash
  2. set -eu
  3. if [[ "$TRAVIS_SECURE_ENV_VARS" == "false" ]]; then
  4. echo "Secrets are not available, skipping actual deploy."
  5. exit;
  6. fi
  7. # Decrypt the credentials we added to the repo using the key we added with the Travis command line tool
  8. openssl aes-256-cbc -K $encrypted_020be61ef175_key -iv $encrypted_020be61ef175_iv -in .travis/storybook-credentials.tar.gz.enc -out credentials.tar.gz -d
  9. # If the SDK is not already cached, download it and unpack it
  10. if [ ! -d ${HOME}/google-cloud-sdk ]; then curl https://sdk.cloud.google.com | bash; fi
  11. echo "gcloud version: $(gcloud version)"
  12. # Use the decrypted service account credentials to authenticate the command line tool
  13. tar -xzf credentials.tar.gz
  14. gcloud auth activate-service-account --key-file client-secret.json
  15. GS_BUCKET_NAME=sentryio-storybook
  16. DEPLOY_BRANCH=${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH}
  17. echo "Build branch: ${DEPLOY_BRANCH}"
  18. # Transform the branch name to a bucket directory
  19. BRANCH_PROCESSED=$(echo "${DEPLOY_BRANCH}" | tr '[:upper:]./' '[:lower:]--' | tr -cd '[:alnum:]-_')
  20. BUCKET_DIR_NAME="branches/${BRANCH_PROCESSED}"
  21. echo "Bucket directory: ${BUCKET_DIR_NAME}"
  22. # Upload the files
  23. gsutil cp docs-ui/.storybook-out/favicon.ico "gs://${GS_BUCKET_NAME}/favicon.ico"
  24. gsutil -m rsync -r -d docs-ui/.storybook-out/ "gs://${GS_BUCKET_NAME}/${BUCKET_DIR_NAME}"
  25. # Upload build metadata
  26. echo "{\"branch\": \"${DEPLOY_BRANCH}\", \"commit\": \"${TRAVIS_COMMIT}\", \"synced_at\": $(date +%s)}" > build-info.json
  27. gsutil cp build-info.json "gs://${GS_BUCKET_NAME}/${BUCKET_DIR_NAME}"