Skip to content

Instantly share code, notes, and snippets.

@razor-x
Last active March 12, 2021 13:22
Show Gist options
  • Save razor-x/8166421 to your computer and use it in GitHub Desktop.
Save razor-x/8166421 to your computer and use it in GitHub Desktop.
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'
next
end
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 user.name '#{ENV['GIT_NAME']}'"
sh "git config user.email '#{ENV['GIT_EMAIL']}'"
end
sh 'git add --all'
sh "git commit -m 'Built from #{rev}'."
verbose false do
sh "git push -q #{deploy_url} #{deploy_branch}"
end
end
end
end
@willwade
Copy link

I'm a Ruby newb.. But am I imagining things or have we not defined what 'destination' is on https://gist.github.com/razor-x/8166421#file-rakefile-L18 ? 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