-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
71 lines (57 loc) · 1.45 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= ''
PUBLISH_BRANCH = 'master'
DEST_DIR = 'build'
task default: %w[middleman]
task :serve do
sh('bundle', 'exec', 'middleman')
end
task :build do
sh('bundle', 'exec', 'middleman', 'build')
end
task :clean do
require 'fileutils'
Dir["#{DEST_DIR}/*"].each do |file|
FileUtils.rm_rf file
end
end
task :middleman do
require 'rubygems'
load Gem.bin_path('middleman-core', 'middleman')
end
task :test do
require 'html/proofer'
HTML::Proofer.new("./build", {
href_ignore: [/.*\?.*/, /\{\{.*\}\}/, /#.*/],
only_4xx: true
}).run
end
task :deploy do
initialize_repository MASTER_REPOSITORY, PUBLISH_BRANCH
update_repository PUBLISH_BRANCH
sh('bundle', 'exec', 'middleman', 'build')
push_to_gh_pages MASTER_REPOSITORY, PUBLISH_BRANCH
end
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 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