Automate Deployment with Travis CI

You might want to automate your Now deployments. Here is how you can achieve this by using Git and Travis. Every time you push or merge to the master branch a new build and deployment is initiated in Travis CI.
  1. You need to get a token. Go to the tokens page of your dashboard, under Account Settings, Tokens. Enter the name of the Token (e.g. Travis CI) and hit enter. A new token will be created which you can copy to your clipboard by clicking Copy.
  2. Create a .travis.yml file in the root of your project.
  3. Generate a secure variable for your ZEIT token by running the following command with the token you obtained from your ZEIT account. (You need to install The Travis Client):
travis encrypt -r username/repo NOW_TOKEN=xxxxxxxxxxxxxxxxxxxxxxx --add
  1. Now open your .travis.yml file and add the following:
language: node_js
node_js:
- "node"
cache: npm
script: npm run deploy
after_script: npm run alias
env:
global:
    secure: <this is your encrypted NOW token. It was added when you ran travis encrypt>
  1. Open your package.json file and add the following information, adapted for your own deployment. This is used to run the alias command and point your domain to the correct deployment (you could also put this in a now.json file):
{
    ...
    "now": {
        "name": "example",
        "alias": "example.com"
        }
    ...
}
  1. Also add the following 2 scripts to the script property in your package.json file. These are used by your Travis config. The first is to deploy and the second is used to alias your latest deploy:
{
    ...
    "scripts": {
    ...
        "deploy": "now -e NODE_ENV=production --token $NOW_TOKEN --npm",
        "alias": "now alias --token=$NOW_TOKEN"
        }
    }
}
  1. Test it out by committing your code to Github. Check out your travis-ci.org build feed.