-
Notifications
You must be signed in to change notification settings - Fork 3
/
Rakefile
29 lines (27 loc) · 1.07 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
require 'rubygems'
desc 'Generate site from Travis CI and publish site 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.'
system 'bundle exec middleman build'
next
end
repo = %x(git config remote.origin.url).gsub(/^git:/, 'https:')
deploy_branch = 'gh-pages'
if repo.match(/github\.com\.git$/)
deploy_branch = 'master'
end
system "git remote set-url --push origin #{repo}"
system "git remote set-branches --add origin #{deploy_branch}"
system 'git fetch -q'
system "git config user.name '#{ENV['GIT_NAME']}'"
system "git config user.email '#{ENV['GIT_EMAIL']}'"
system 'git config credential.helper "store --file=.git/credentials"'
File.open('.git/credentials', 'w') do |f|
f.write("https://#{ENV['GH_TOKEN']}:@github.com")
end
system "git branch #{deploy_branch} origin/#{deploy_branch}"
system 'bundle exec middleman build && bundle exec middleman deploy'
File.delete '.git/credentials'
end