This repository has been archived by the owner on Jan 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathRakefile
111 lines (89 loc) · 2.51 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#############################################################################
#
# Modified version of jekyllrb Rakefile
# https://github.com/jekyll/jekyll/blob/master/Rakefile
#
#############################################################################
require 'rake'
require 'yaml'
CONFIG = YAML.load(File.read('_config.yml'))
REPO = CONFIG["repo"]
DESTINATION = CONFIG['destination']
USERNAME = "w3c"
SOURCE_BRANCH = "master"
DESTINATION_BRANCH = "master"
ENV["USERNAME"] = USERNAME
ENV["REPO"] = REPO
ENV["DESTINATION"] = DESTINATION
ENV["DESTINATION_BRANCH"] = DESTINATION_BRANCH
#############################################################################
#
# Helper functions
#
#############################################################################
def check_destination
unless Dir.exist? DESTINATION
Dir.mkdir DESTINATION
end
end
def init_submodules
sh "git submodule update --init"
end
def jekyll command
sh "bundle exec jekyll #{command}"
end
#############################################################################
#
# Site tasks
#
#############################################################################
check_destination
desc "Update submodules"
task :submodule_update do
init_submodules
if `git diff --staged`.strip != ""
puts "staging area must be clean"
exit
end
sh "git submodule -q foreach 'git fetch -q && git checkout -q origin/master && cd $toplevel && git add $path'"
if `git diff --staged`.strip != ""
sh "git commit -m 'Update to latest submodules'"
end
end
desc "Generate the site"
task :build do
jekyll "build"
end
desc "Generate the site and serve locally"
task :serve do
jekyll "serve"
end
desc "Generate the site, serve locally and watch for changes"
task :watch do
jekyll "serve --watch"
end
desc "Generate the site and push changes to remote origin"
task :deploy do
# Detect pull request
if ENV['TRAVIS_PULL_REQUEST'].to_s.to_i > 0
puts 'Pull request detected. Not proceeding with deploy.'
exit
end
# Configure git if this is run in Travis CI
if ENV["TRAVIS"]
if ENV['TRAVIS_SECURE_ENV_VARS'] == "false"
puts 'Not able to access secure variables'
exit
end
sh "git config --global user.name '#{ENV['GIT_NAME']}'"
sh "git config --global user.email '#{ENV['GIT_EMAIL']}'"
sh "git config --global push.default tracking"
end
sh "git submodule update --init"
sh "git checkout #{SOURCE_BRANCH}"
sh "./clone.sh"
# Generate the site
jekyll "build"
# Commit and push to github
sh "./deploy.sh"
end