-
Notifications
You must be signed in to change notification settings - Fork 2
/
Rakefile
88 lines (72 loc) · 1.65 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
REPOSITORY = 'emacs-jp/reading-init.el'
MASTER_REPOSITORY = if ENV['GH_TOKEN']
"https://[email protected]/#{REPOSITORY}"
else
"[email protected]:#{REPOSITORY}.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
sh "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}"
sh 'git clean -fd'
end
end
def build
sh 'bundle exec middleman build'
end
def server
begin
sh 'bundle exec middleman server'
rescue Interrupt
sleep 3
end
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}'"
sh "git push -f --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 'Deploy website'
task :server do
build
server
end
desc 'Publish website'
task :publish do
push_to_gh_pages MASTER_REPOSITORY, PUBLISH_BRANCH
end