Skip to content

Commit

Permalink
ci: deploy PRs to surge
Browse files Browse the repository at this point in the history
  • Loading branch information
infiniteluke committed Nov 7, 2017
1 parent b5f939a commit b8e8cd2
Show file tree
Hide file tree
Showing 4 changed files with 364 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ sudo: false
branches:
except:
- /^v\d/
after_success:
- make build
- ./.travis/pr_deploy.sh
before_deploy: yarn predeploy
deploy:
provider: pages
Expand Down
29 changes: 29 additions & 0 deletions .travis/pr_deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash
# Split on "/", ref: http://stackoverflow.com/a/5257398/689223
REPO_SLUG_ARRAY=(${TRAVIS_REPO_SLUG//\// })
REPO_OWNER=${REPO_SLUG_ARRAY[0]}
REPO_NAME=${REPO_SLUG_ARRAY[1]}
DEPLOY_PATH=./public


if [ "$TRAVIS_PULL_REQUEST" != "false" ]
then
DEPLOY_SUBDOMAIN_UNFORMATTED_LIST=(${TRAVIS_PULL_REQUEST}-pr)
for DEPLOY_SUBDOMAIN_UNFORMATTED in "${DEPLOY_SUBDOMAIN_UNFORMATTED_LIST[@]}"
do
echo $DEPLOY_SUBDOMAIN_UNFORMATTED
# replaces "/" or "." with "-"
# sed -r is only supported in linux, ref http://stackoverflow.com/a/2871217/689223
# Domain names follow the RFC1123 spec [a-Z] [0-9] [-]
# The length is limited to 253 characters
# https://en.wikipedia.org/wiki/Domain_Name_System#Domain_name_syntax
DEPLOY_SUBDOMAIN=`echo "$DEPLOY_SUBDOMAIN_UNFORMATTED" | sed -r 's/[\/|\.]+/\-/g'`
DEPLOY_DOMAIN=https://${DEPLOY_SUBDOMAIN}-${REPO_NAME}-${REPO_OWNER}.surge.sh
surge --project ${DEPLOY_PATH} --domain $DEPLOY_DOMAIN;
# Using the Issues api instead of the PR api
# Done so because every PR is an issue, and the issues api allows to post general comments,
# while the PR api requires that comments are made to specific files and specific commits
GITHUB_PR_COMMENTS=https://api.github.com/repos/${TRAVIS_REPO_SLUG}/issues/${TRAVIS_PULL_REQUEST}/comments
curl -H "Authorization: token ${GITHUB_API_TOKEN}" --request POST ${GITHUB_PR_COMMENTS} --data '{"body":"Review change(s): '${DEPLOY_DOMAIN}'"}'
done
fi
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
"gh-pages": "^1.0.0",
"husky": "^0.14.3",
"lint-staged": "^4.3.0",
"prettier": "^1.7.4"
"prettier": "^1.7.4",
"surge": "^0.19.0"
},
"dependencies": {
"bootstrap": "4.0.0-beta",
Expand Down
Loading

0 comments on commit b8e8cd2

Please sign in to comment.