Skip to content

Commit bd9a4c2

Browse files
committed
Added Rakefile for travis-ci.
1 parent 28bf3cb commit bd9a4c2

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

Rakefile

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#############################################################################
2+
#
3+
# Modified version of jekyllrb Rakefile
4+
# https://github.com/jekyll/jekyll/blob/master/Rakefile
5+
#
6+
#############################################################################
7+
8+
require 'rake'
9+
require 'date'
10+
require 'yaml'
11+
12+
CONFIG = YAML.load(File.read('_config.yml'))
13+
USERNAME = CONFIG["username"]
14+
REPO = CONFIG["repo"]
15+
SOURCE_BRANCH = CONFIG["branch"]
16+
DESTINATION_BRANCH = "gh-pages"
17+
18+
def check_destination
19+
unless Dir.exist? CONFIG["destination"]
20+
sh "git clone https://$GIT_NAME:[email protected]/#{USERNAME}/#{REPO}.git #{CONFIG["destination"]}"
21+
end
22+
end
23+
24+
namespace :site do
25+
desc "Generate the site"
26+
task :build do
27+
check_destination
28+
sh "bundle exec jekyll build"
29+
end
30+
31+
desc "Generate the site and serve locally"
32+
task :serve do
33+
check_destination
34+
sh "bundle exec jekyll serve"
35+
end
36+
37+
desc "Generate the site, serve locally and watch for changes"
38+
task :watch do
39+
sh "bundle exec jekyll serve --watch"
40+
end
41+
42+
desc "Generate the site and push changes to remote origin"
43+
task :deploy do
44+
# Detect pull request
45+
if ENV['TRAVIS_PULL_REQUEST'].to_s.to_i > 0
46+
puts 'Pull request detected. Not proceeding with deploy.'
47+
exit
48+
end
49+
50+
# Configure git if this is run in Travis CI
51+
if ENV["TRAVIS"]
52+
sh "git config --global user.name $GIT_NAME"
53+
sh "git config --global user.email $GIT_EMAIL"
54+
sh "git config --global push.default simple"
55+
end
56+
57+
# Make sure destination folder exists as git repo
58+
check_destination
59+
60+
sh "git checkout #{SOURCE_BRANCH}"
61+
Dir.chdir(CONFIG["destination"]) { sh "git checkout #{DESTINATION_BRANCH}" }
62+
63+
# Generate the site
64+
sh "bundle exec jekyll build"
65+
66+
# Commit and push to github
67+
sha = `git log`.match(/[a-z0-9]{40}/)[0]
68+
Dir.chdir(CONFIG["destination"]) do
69+
# check if there is anything to add and commit, and pushes it
70+
sh "if [ -n '$(git status)' ]; then
71+
git add --all .;
72+
git commit -m 'Updating to #{USERNAME}/#{REPO}@#{sha}.';
73+
git push --quiet origin #{DESTINATION_BRANCH};
74+
fi"
75+
puts "Pushed updated branch #{DESTINATION_BRANCH} to GitHub Pages"
76+
end
77+
end
78+
end

0 commit comments

Comments
 (0)