Last active
January 5, 2021 10:13
-
-
Save NikitaGlukhi/f094a6a8e6812d104d779e37d6560705 to your computer and use it in GitHub Desktop.
Travis CI config and bash script for deploying to Firebase preview channels and commenting GitHub PRs
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
sudo: false | |
language: node_js | |
node_js: "12" | |
notifications: | |
email: false | |
git: | |
submodules: false | |
script: | |
- echo "skipping tests" | |
stages: | |
- name: "Deploy to Firebase preview channel" | |
if: branch = master AND type = pull_request | |
install: | |
- npm ci | |
jobs: | |
include: | |
- stage: "Deploy to Firebase preview channel" | |
skip_cleanup: true | |
provider: firebase | |
project: fir-project-dc47e | |
before_script: | |
- sudo apt-get install jq | |
- npm install firebase-tools -g | |
- npm run build:prod | |
script: bash deploy-to-firebase-preview-channels.sh |
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
#!/usr/bin/env bash | |
DEPLOY_TO_PREVIEW_CHANNEL_RESULT=$(firebase hosting:channel:deploy pr-$TRAVIS_PULL_REQUEST --expires 30d --token $FIREBASE_TOKEN --json) | |
RESULT=`echo ${DEPLOY_TO_PREVIEW_CHANNEL_RESULT} | jq -r '.result'` | |
RESULT_DATA=`echo ${RESULT} | jq -r '."fir-project-dc47e"'` | |
SITE=`echo ${RESULT_DATA} | jq -r '."site"'` | |
URL=`echo ${RESULT_DATA} | jq -r '."url"'` | |
EXPIRE_TIME_UTC=`echo ${RESULT_DATA} | jq -r .expireTime` | |
EXPIRE_TIME=$(TZ='GMT' date -d $EXPIRE_TIME_UTC +%c) | |
NEW_COMMENT="Project: $SITE \n Url: $URL \n This link will expire at $EXPIRE_TIME" | |
COMMENTS=$(curl -H "Authorization: token $GITHUB_TOKEN" -X GET "https://api.github.com/repos/$TRAVIS_REPO_SLUG/issues/$TRAVIS_PULL_REQUEST/comments") | |
SUBSTRING="Project: fir-project-dc47e" | |
COMMENT_ID=-1 | |
for row in $(echo "${COMMENTS}" | jq -r '.[] | @base64'); do | |
echo ${row} | |
_jq() { | |
echo ${row} | base64 --decode | jq -r ${1} | |
} | |
BODY=$(_jq '.body') | |
if [[ ${BODY} == *"$SUBSTRING"* ]]; then | |
COMMENT_ID=$(_jq '.id') | |
fi | |
done | |
if [[ ${COMMENT_ID} -ge 0 ]]; | |
then | |
curl -H "Authorization: token $GITHUB_TOKEN" -X PATCH -d "{\"body\": \"$NEW_COMMENT\"}" "https://api.github.com/repos/${TRAVIS_REPO_SLUG}/issues/comments/${COMMENT_ID}" | |
else | |
curl -H "Authorization: token $GITHUB_TOKEN" -X POST -d "{\"body\": \"$NEW_COMMENT\"}" "https://api.github.com/repos/${TRAVIS_REPO_SLUG}/issues/${TRAVIS_PULL_REQUEST}/comments" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment