Install Travis CI's CLI:
- [Official Instructions] https://github.com/travis-ci/travis.rb
- On a Mac:
gem install travis
On your local machine:
-
Run
npm test
to ensure tests are working correctly locally -
Add properly configured
.travis.yml
(see below) -
Using no database:
language: node_js
node_js: node
- Using MongoDB
language: node_js
node_js: node
services:
- mongodb
- Using PostgreSQL - you need to create the database and create the tables. The easiest way to do the latter is to provide a
.sql
script file with theCREATE TABLE
commands
language: node_js
node_js: node
services:
- postgresql
before_script:
- psql -U postgres -c 'CREATE DATABASE "[YOUR-TEST-DATABASE]";'
- psql -U postgres -f ./db/create-tables.sql -d [YOUR-TEST-DATABASE]
- Commit and push repo to Github
On Travis - activate integration:
- Go to Profile: User (in upper-right) > Accounts
- Click "Sync Account"
- Activate repo
On GitHub - verify integration and test:
- Go to Settings > Integrations & Services
- There should be an entry for "Travis CI" under Services
- Click the "edit" button, then click "Test service" to test integration
On Travis:
- Watch build complete successfully :-)
Install Heroku CLI:
- Offical Instructions
- Mac:
brew install heroku
- Win: Download Installer
Problems installing? Try the Heroku NPM package
npm install -g heroku-cli
Configure .travis.yml
to deploy to Heroku:
- Go to project:
- Run:
CD <YOUR PROJECT>
- Run:
- Login to Heroku
- Run:
heroku login
(and enter your UN/PW)
- Run:
- Create an app
- Run:
heroku create <app-name>
- Run:
- Login to travis
- Run:
travis login
(and enter your UN/PW for GitHub)
- Run:
- Add Heroku info to
.travis.yml
, run:- Run:
travis setup heroku
- Run:
- Follow prompts, make sure the app name and repo are correct
- Your
.travis.yml
should look like this:
language: node_js
node_js: node
services:
- <DATABASE-SERVICE-NAME>
before_script:
# If using postgres then create database and create tables
- psql -U postgres -c 'CREATE DATABASE "noteful-test";'
- psql -U postgres -f ./db/noteful.4.sql -d noteful-test
deploy:
provider: heroku
api_key:
secure: oOa1TMdgeY5+rySYW0HY30j+ot+KUqs1H...
app: <APP-NAME-ON-HEROKU>
on:
repo: <GITHUB-USERNAME>/<REPO-NAME>
- Ensure tests are still working
- Run:
npm test
- Run:
- Commit and push changes to GitHub
- Run
git commit -am "setup CICD"
- Run
- Changes should deploy to GitHub > Travis CI > Heroku
Skip this section if you are not using a DB.
- Add connection string to (Environment) Config Vars
-
Go to: Personal Apps > PROJECT NAME > Settings
-
Click "Reveal Config Vars"
-
Using Heroku Mongo or Postgres Add-On:
- Browse to your Heroku App.
- Click "Resources"
- In the Add-ons input: type
postgres
ormlab
- Select: the free plan and click
Provision
- Heroku will create "Config Vars" for the database
- Postgres:
DATABASE_URL
- Mongo:
MONGODB_URI
- Postgres:
- Select: the free plan and click
-
If using ElephantSQL or MLab manually then:
- Browse to your Heroku App.
- Click "Settings"
- Click "Reveal Config Vars"
- Enter appropriate var for database
DATABASE_URL
=postgres://<UN>:<PW>@stampy.db.elephantsql.com:<PORT>/<DB>
MONGODB_URI
=mongodb://<UN>:<PW>@<SEREVER>.mlab.com:<PORT>/<DB>
- Browse to your Heroku App.
-
Add a Travis CI badge to your repo
- On Travis CI, find your project and click on the badge
- Change the dropdown menu to "Markdown" and copy the output
- Add the badge code to your
readme.md
file, commit and push - The code looks something like this:
[](https://travis-ci.org/<USERNAME>/<REPO-NAME>)
Issue: Running travis setup heroku
returns the wrong repo name.
Example:
travis setup heroku
Deploy only from username/OLD-REPO-NAME? |yes|
Encrypt API key? |yes|
Reason:
Travis CLI add a "slug" entry to the .git/config
[travis]
slug = username/OLD-REPO-NAME
Fix:
Remove the [travis] and the slug from .git/config
If a deploy property exists in .travis.yml
, remove it
rerun travis setup heroku
Alternatively, run travis setup heroku --force
to override existing deploy property
Remove the "deploy" property from the Travis.yml