Skip to content

surge-sh/example-travisci-pullrequests

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Travis CI example Build Status

An example using Travis CI for continuous deployment to Surge.sh.

Getting started

Continuous Integration services like Travis CI make it possible to run Surge and publish your project each time you push to a GitHub repository and when someone opens a pull request.

Building pull requests using Travis CI and Surge allows you to see a preview of the changes that someone’s made in the pull request. This can be especailly useful if you’re building a blog or documentation site and using a static site generator: if a kind contributor adds a new blog post or updates the docs, you’ll be able to see exactly what they’d like you to merge without even needing to clone the pull request locally.

  1. Get your token
  2. Add your project’s repository to Travis CI
  3. Push a .travis.yml file that will run the surge command

Get your token

Your secret Surge token allows services like Travis CI to login and publish projects on your behalf. Get your Surge token by running the following command in your terminal:

surge token

You’ll be asked to login again, and afterwards your token will be displayed like this:

token: a142e09a6b13a21be512b141241c7123

Add your project’s repository to Travis CI

Now you are ready to login and setup your project on Travis CI. Add your project’s GitHub repo to your list of Travis CI projects. The screenshots are using the surge-sh/example-travis repo:

Press Environment Variables next, and you’ll be able to secretly add your email address and token so Travis CI can login to Surge for you:

Create one environment variable called:

SURGE_LOGIN

…and set it to the email address you use with Surge. Next, add another environment variable called:

SURGE_TOKEN

…and set it to your Surge token.

Push a .travis.yml file that will run the surge command

Travis CI machines won’t have Surge installed by default, so you also need to save Surge as a [development dependency] to your project. You can do this by creating a package.json file if you don’t have one already. Run the following command in your terminal to be walked through making this file (you can hit enter to accept the defaults):

npm init

You will end up with a file that looks something like this one.

Next, run this command to save Surge as a devDependency, so Travis CI will install it:

npm install --save-dev surge

Double-check your tests

If you needed to add a new package.json file, you’ll want to make one small change. It’s possible your initial build will fail if you don’t have any tests, or if you have the default test command in your package.json.

You can add tests or just clear this out of your package.json file entirely, changing:

"scripts": {
  "test": "echo \"Error: no test specified.\" && exit 1"
}

…into:

"scripts": {
  "test": "echo \"Error: no test specified.\""
}

License

The MIT License (MIT)

Copyright © 2015 Chloi Inc.

About

An example using Travis CI to build pull request previews.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages