Continuous Deployment services like Codeship make it possible to run publish your project on Surge each time you push to a GitHub or Bitbucket repository.
This guide will walk you through:
- Getting your Surge token, so Codeship can login to Surge on your behalf
- Adding Surge as a
devDependency, so Codeship can install Surge
- Setting up your project on Codeship, so you can publish each time you push to GitHub or Bitbucket
First, you’ll need your token from the Surge CLI. This secret key lets services like Codeship login and publish projects on your behalf. Get your Surge token by running the following command in your terminal:
You’ll be asked to login again, and afterwards your token will be displayed like this:
Adding Surge as a
devDependency to a
Codeship’s machines won’t have Surge installed by default, so you also need to save Surge as a development dependency in your project. This lets Codeship know it needs to install Surge to publish 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):
You will end up with a file that looks something like this one.
Next, run this command to save Surge as a
devDependency, so Codeship will install it:
npm install --save-dev surge
Add your project’s repository to Codeship
Now you can login and setup a new project on Codeship. Add your project’s GitHub or Bitbucket repository to your Codeship projects:
Define your Setup and Test Commands
Now you’re ready to run
surge on Codeship. Your Codeship setup commands run before the deployment command.
Your setup commands should look like this:
# Install the latest version of Node.js nvm install stable nvm use stable # Install Surge as a devDependency npm install
After you push you successfully to your repository, Codeship will run your Test Pipeline commands:
# Run your tests (if you have any) npm test
Add Environment Variables
Press Environment Variables next, and you’ll be able to secretly add your email address and token so Codeship can login to Surge for you:
Create one environment variable called:
…and set it to the email address you use with Surge. Next, add another environment variable called:
…and set it to your Surge token.
Add a deployment script
Push to your repository, and your Setup and Test commands should run, triggering your tests to run on Codeship. Now, Codeship will let you move onto adding a script for Continuous Deployment. You can press the button labeled Set up Continuous Deployment or access this section under your project settings:
Add a Custom Script and enter the command you want to run with Surge, for example:
surge --project ./ example-codeship.surge.sh
Now, when you push your poject to GitHub or Bitbucket again, this command will be run and your project will get published automatically.
Copyright © 2015 Chloi Inc.