30
loading...
This website collects cookies to deliver better user experience
stages:
- name: "Deploy to Firebase preview channel"
if: branch = master AND type = pull_request
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
#!/usr/bin/env bash
DEPLOY_TO_PREVIEW_CHANNEL_RESULT=$(firebase hosting:channel:deploy pr-$TRAVIS_PULL_REQUEST --expires 30d --token $FIREBASE_TOKEN --json)
{
"status": "success",
"result": {
"fir-project-dc47e": {
"site": "fir-project-dc47e",
"url": "https://fir-project-dc47e--pr-1-t36vykr3.web.app",
"expireTime": "2021-01-08T09:27:24.847798020Z"
}
}
}
RESULT=`echo ${DEPLOY_TO_PREVIEW_CHANNEL_RESULT} | jq -r '.result'`
{
"site": "fir-project-dc47e",
"url": "https://fir-project-dc47e--pr-1-t36vykr3.web.app",
"expireTime": "2021-01-08T09:27:24.847798020Z"
}
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)
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
30