Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Travis deployment previews to surge.sh #6

Open
wants to merge 1 commit into
base: gh-pages
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
sudo: false

language: ruby
cache: bundler
rvm:
- 2.3.3

before_install:
- test $TRAVIS_PULL_REQUEST && ./.travis/pr_status pending "Waiting for website to build"

script:
- bash .travis/build.sh

after_success:
- test $TRAVIS_PULL_REQUEST && ./.travis/pr_deploy
after_failure:
- test $TRAVIS_PULL_REQUEST && ./.travis/pr_status error "Website failed to build"

env:
global:
- GITHUB_AUTH_USER=allejo
- GITHUB_USER=CityofSantaMonica
- GITHUB_REPO=CityNet
- NOKOGIRI_USE_SYSTEM_LIBRARIES=true
notifications:
email: false
6 changes: 6 additions & 0 deletions .travis/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

git submodule update --init
bundle install --path vendor/bundle
bundle exec jekyll build
#bundle exec htmlproofer ./_site
11 changes: 11 additions & 0 deletions .travis/pr_deploy
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

URL="https://$GITHUB_USER--$GITHUB_REPO--$TRAVIS_PULL_REQUEST.surge.sh"
if [ ! -f /usr/local/bin/surge ]; then npm install -g surge; fi
surge --project ./_site --domain "$URL" > /dev/null
SURGE_STATUS=$?
STATUS=$([ $SURGE_STATUS -eq 0 ] && echo "success" || echo "failure")
DESC=$([ $SURGE_STATUS -eq 0 ] && echo "Staging website deployed successfully" || echo "Staging website deployment failed")

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
bash $DIR/pr_status "$STATUS" "$DESC" "$URL"
14 changes: 14 additions & 0 deletions .travis/pr_status
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

STATUS=$1
DESC=$2
URL=$3

data="{\"state\":\"$STATUS\","
if [ ! -z "$URL" ]
then
data="$data\"target_url\":\"$URL\","
fi
data="$data\"description\":\"$DESC\",\"context\":\"surge.sh/staging\"}"

curl -u $GITHUB_AUTH_USER:$GITHUB_PR_TOKEN --data "$data" "https://api.github.com/repos/$GITHUB_USER/$GITHUB_REPO/statuses/$TRAVIS_PULL_REQUEST_SHA" > /dev/null