Create a gist now

Instantly share code, notes, and snippets.

@razor-x /Rakefile
Last active Apr 22, 2016

Automatic publishing to GitHub Pages with Travis CI
desc 'Generate deck from Travis CI and publish to GitHub Pages.'
task :travis do
# if this is a pull request, do a simple build of the site and stop
if ENV['TRAVIS_PULL_REQUEST'].to_s.to_i > 0
puts 'Pull request detected. Executing build only.'
sh 'bundle exec rake build'
repo = %x(git config remote.origin.url).gsub(/^git:/, 'https:').strip
deploy_url = repo.gsub %r{https://}, "https://#{ENV['GH_TOKEN']}@"
deploy_branch = repo.match(/github\.io\.git$/) ? 'master' : 'gh-pages'
rev = %x(git rev-parse HEAD).strip
Dir.mktmpdir do |dir|
dir = File.join dir, 'site'
sh 'bundle exec rake build'
fail "Build failed." unless Dir.exists? destination
sh "git clone --branch #{deploy_branch} #{repo} #{dir}"
sh %Q(rsync -rt --del --exclude=".git" --exclude=".nojekyll" #{destination} #{dir})
Dir.chdir dir do
# setup credentials so Travis CI can push to GitHub
verbose false do
sh "git config '#{ENV['GIT_NAME']}'"
sh "git config '#{ENV['GIT_EMAIL']}'"
sh 'git add --all'
sh "git commit -m 'Built from #{rev}'."
verbose false do
sh "git push -q #{deploy_url} #{deploy_branch}"

I'm a Ruby newb.. But am I imagining things or have we not defined what 'destination' is on ? I'm struggling to get this to run 'NameError: undefined local variable or method `destination' for main:Object'

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