-
Notifications
You must be signed in to change notification settings - Fork 11
/
Rakefile
54 lines (45 loc) · 1.52 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
require 'rake'
require 'date'
require 'yaml'
CONFIG = YAML.load(File.read('_config.yml'))
USERNAME = CONFIG["username"]
REPO = CONFIG["repo"]
SOURCE_BRANCH = "master"
DESTINATION_BRANCH = "publish"
DESTINATION = CONFIG["destination"]
def check_destination
unless Dir.exist? CONFIG["destination"]
sh "git clone https://$GIT_NAME:[email protected]/#{USERNAME}/#{REPO}.git #{CONFIG["destination"]}"
end
end
namespace :site do
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"]
sh "git config --global user.name $GIT_NAME"
sh "git config --global user.email $GIT_EMAIL"
sh "git config --global push.default simple"
end
# Make sure destination folder exists as git repo
check_destination
sh "git checkout #{SOURCE_BRANCH}"
Dir.chdir(CONFIG["destination"]) { sh "git checkout #{DESTINATION_BRANCH}" }
# Generate the site
sh "bundle exec jekyll build"
sh "cp -r css #{DESTINATION}"
# Commit and push to github
sha = `git log`.match(/[a-z0-9]{40}/)[0]
Dir.chdir(CONFIG["destination"]) do
sh "git add --all ."
sh "git commit -m 'Updating to #{USERNAME}/#{REPO}@#{sha}.'"
sh "git push --quiet origin #{DESTINATION_BRANCH}"
puts "Pushed updated branch #{DESTINATION_BRANCH} to GitHub Pages"
end
end
end