-
Notifications
You must be signed in to change notification settings - Fork 7
/
Rakefile
71 lines (58 loc) · 1.39 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
MASTER_REPOSITORY = if ENV['GH_TOKEN']
'https://[email protected]/terakoya/rails.terakoya.io.git'
else
'[email protected]:terakoya/rails.terakoya.io.git'
end
PUBLISH_BRANCH = 'gh-pages'
DEST_DIR = 'build'
def initialize_repository(repository, branch)
require 'fileutils'
if Dir["#{DEST_DIR}/.git"].empty?
FileUtils.rm_rf DEST_DIR
system "git clone --quiet #{repository} #{DEST_DIR} 2> /dev/null"
end
Dir.chdir DEST_DIR do
sh "git checkout --orphan #{branch}"
end
end
def update_repository(branch)
Dir.chdir DEST_DIR do
sh 'git fetch origin'
sh "git reset --hard origin/#{branch}"
end
end
def build
sh 'bundle exec middleman build'
end
def clean
require 'fileutils'
Dir["#{DEST_DIR}/*"].each do |file|
FileUtils.rm_rf file
end
end
def push_to_gh_pages(repository, branch)
sha1, _ = `git log -n 1 --oneline`.strip.split(' ')
Dir.chdir DEST_DIR do
sh 'git add -A'
sh "git commit -m 'Update with #{sha1}'"
system "git push --quiet #{repository} #{branch} 2> /dev/null"
end
end
desc 'Setup origin repository for GitHub pages'
task :setup do
initialize_repository MASTER_REPOSITORY, PUBLISH_BRANCH
update_repository PUBLISH_BRANCH
end
desc 'Clean built files'
task :clean do
clean
end
desc 'Build sites'
task :build do
clean
build
end
desc 'Publish website'
task :publish do
push_to_gh_pages MASTER_REPOSITORY, PUBLISH_BRANCH
end