Skip to content

Instantly share code, notes, and snippets.

@tlvince
Created November 21, 2014 19:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tlvince/aed461c2d0a828235da6 to your computer and use it in GitHub Desktop.
Save tlvince/aed461c2d0a828235da6 to your computer and use it in GitHub Desktop.
Quick and dirty Yeoman-Travis-Heroku deployment for static apps
  1. Add grunt-build-control to your app:

    npm install --save grunt-build-control
  2. Append its Grunt task:

    buildcontrol: {
      options: {
        commit: true,
        tag: require('./package.json').version,
        push: true
      },
      heroku: {
        options: {
          remote: 'git@heroku.com:[app].git',
          branch: 'master'
        }
      }
    }
  3. Append a deploy script to .travis.yml:

    after_success:
      - ./scripts/deploy.sh
  4. Drop in the deploy script:

    #!/usr/bin/env bash
    set -e
    
    info() { echo "$0: $1"; }
    error() { info "$1"; exit 1; }
    
    [[ "$TRAVIS" ]] || error "This script assumes its running within Travis"
    [[ "$TRAVIS_PULL_REQUEST" == "true" ]] && error "Not deploying pull requests"
    [[ "$TRAVIS_BRANCH" == "master" ]] || error "Unsupported branch $TRAVIS_BRANCH"
    
    git config --global user.name "TravisCI"
    git config --global user.email "travis@example.com"
    ssh-keyscan -t rsa heroku.com >> ~/.ssh/known_hosts 2>/dev/null
    gem install heroku
    echo yes | heroku keys:add
    grunt build
    mv dist/index.html dist/index.php
    grunt buildcontrol:heroku
    heroku keys:remove "$(< ~/.ssh/id_rsa.pub)"
  5. Add your Heroku API key to Travis:

    travis env set HEROKU_API_KEY `heroku auth:token`
@simonmorley
Copy link

V. helpful.

Only one comment for future readers: I had to manually remove id_rsa from ~/.ssh/ otherwise the keys add command failed.

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