Skip to content

Instantly share code, notes, and snippets.

@contolini
Last active July 3, 2019 14:01
Show Gist options
  • Save contolini/e99209cf9ea2490a2b55a867be2fa14d to your computer and use it in GitHub Desktop.
Save contolini/e99209cf9ea2490a2b55a867be2fa14d to your computer and use it in GitHub Desktop.
How to automatically deploy a GitHub repo's branches to surge.sh using Travis CI

First, add SURGE_USER and SURGE_TOKEN environment variables to the repo's settings page in Travis:

travis surge.sh settings

Then modify the repo's .travis.yml file to perform whatever build steps are required to generate the static website in the before_deploy step. Below, I'm installing Jekyll and building the site in the docs/ dir where my site's source files live.

language: node_js
before_deploy:
  - gem install jekyll
  - cd ./docs/ && jekyll build
  - REPO_SLUG=${TRAVIS_REPO_SLUG//\//-}
deploy:
  provider: surge
  project: ./docs/_site
  domain: "${REPO_SLUG}-${TRAVIS_BRANCH}.surge.sh"
  skip_cleanup: true
  on:
    all_branches: true

Travis will deploy every branch that is pushed up to GitHub with domains in the format https://<github-username>-<repo_name>-<branch-name>.surge.sh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment