This repository was archived by the owner on Feb 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRakefile
More file actions
73 lines (59 loc) · 1.39 KB
/
Rakefile
File metadata and controls
73 lines (59 loc) · 1.39 KB
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
MASTER_REPO = if ENV['GH_TOKEN']
'https://$GH_TOKEN@github.com/o2project/blog.o2p.jp'
else
'git@github.com:o2project/blog.o2p.jp'
end
PUBLISH_BRANCH = 'master'
DEST_DIR = 'build'
def init_repo(repo, branch)
require 'fileutils'
if Dir["#{DEST_DIR}/.git"].empty?
FileUtils.rm_rf DEST_DIR
sh "git clone --quiet #{repo} #{DEST_DIR} 2> /dev/null"
end
Dir.chdir DEST_DIR do
sh "git checkout --orphan #{branch}"
end
end
def update_repo(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_target_repo(repo, branch)
sha1, _ = `git log -n 1 --oneline`.strip.split(' ')
Dir.chdir DEST_DIR do
sh 'git add -A'
sh "git commit -m '[ci skip] Update with #{sha1}'"
sh "git push --quiet #{repo} #{branch} 2> /dev/null"
end
end
desc 'Setup origin repo for GitHub pages'
task :setup do
init_repo MASTER_REPO, PUBLISH_BRANCH
update_repo 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_target_repo MASTER_REPO, PUBLISH_BRANCH
end
task default: :setup