Skip to content

Commit

Permalink
feat(ci): add firebase preview to PRs (#5970)
Browse files Browse the repository at this point in the history
  • Loading branch information
valorkin authored Nov 3, 2020
1 parent b838326 commit b7a03cc
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "ngx-bootstrap-demo"
}
}
14 changes: 13 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sudo: false
language: node_js
node_js: "10"
node_js: "12"

services:
- xvfb
Expand Down Expand Up @@ -38,6 +38,8 @@ testPostDeploy: &testPostDeploy
stages:
- name: "Publish to ngx-bootstrap-ci"
if: ( branch = development AND type = push ) OR type = pull_request OR tag =~ ^v\d+
- name: "Deploy to firebase preview channel"
if: branch = development AND type = pull_request
- name: Testing
if: ( branch = development AND type = push ) OR type = pull_request OR tag =~ ^v\d+
- name: deploy
Expand Down Expand Up @@ -140,6 +142,16 @@ jobs:
- npm config set '//registry.npmjs.org/:_authToken' $NPM_AUTH_TOKEN_CI
- if [[ "$TRAVIS_PULL_REQUEST" != false ]]; then npm unpublish --tag $TRAVIS_COMMIT --force; fi

- stage: "Deploy to firebase preview channel"
skip_cleanup: true
provider: firebase
project: ngx-bootstrap-demo
before_script:
- sudo apt-get install jq
- npm install firebase-tools -g
- npm run demo.ng-build
script: bash scripts/firebase/deploy-to-preview-channel.sh

- &surge
stage: deploy
script:
Expand Down
10 changes: 10 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"hosting": {
"public": "demo/dist/browser",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
35 changes: 35 additions & 0 deletions scripts/firebase/deploy-to-preview-channel.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/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'`
NGX_BOOTSTRAP_DEMO=`echo ${RESULT} | jq -r '."ngx-bootstrap-demo"'`
SITE=`echo ${NGX_BOOTSTRAP_DEMO} | jq -r .site`
URL=`echo ${NGX_BOOTSTRAP_DEMO} | jq -r .url`
EXPIRE_TIME_UTC=`echo ${NGX_BOOTSTRAP_DEMO} | 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 -X GET "https://api.github.com/repos/$TRAVIS_REPO_SLUG/issues/$TRAVIS_PULL_REQUEST/comments")

SUBSTRING="Project: ngx-bootstrap-demo"
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

0 comments on commit b7a03cc

Please sign in to comment.