This repository has been archived by the owner on Nov 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
51 lines (43 loc) · 1.53 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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'tmpdir'
destination = 'public'
task :default => [:build]
def run(command)
raise "Failed to execute '#{command}'" if !system(command)
end
desc 'Generate patternlab 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
author_date = `git log -n 1 --format='%aD'`.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" --exclude="CNAME" #{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 --date='#{author_date}' -m 'Built from #{rev}'."
verbose false do
sh "git push -q #{deploy_url} #{deploy_branch}"
end
end
end
end
desc 'Generate patternlab'
task :build do
run('grunt build')
end