Created
March 22, 2014 20:38
-
-
Save tobru/9713978 to your computer and use it in GitHub Desktop.
A git post-receive hook for Jekyll which supports branches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'fileutils' | |
GIT_REPO = '/home/me/mywebsite_ch.git' | |
TMP_GIT_CLONE = '/tmp/mywebsite_ch_clone' | |
DOCROOT = { 'master' => ENV['HOME']+'/public_html', | |
'draft' => ENV['HOME']+'/public_html_draft' } | |
JEKYLL_CONFIG = { 'master' => '_config.yml', | |
'draft' => '_config.yml,_config-draft.yml' } | |
def exit_with_msg(msg) | |
puts msg | |
exit 1 | |
end | |
# detect branch | |
branch = 'unknown' | |
$stdin.read.split(' ').each do |param| | |
branch = param.split('/')[2] if param.include?('/') | |
end | |
exit_with_msg('branch unknown') if branch == 'unknown' | |
exit_with_msg('branch not configured') if not DOCROOT.has_key?(branch) | |
exit_with_msg('jekyll config not configured') if not JEKYLL_CONFIG.has_key?(branch) | |
puts "INFO: cloning branch '#{branch}' to #{TMP_GIT_CLONE}" | |
system("git clone -b #{branch} #{GIT_REPO} #{TMP_GIT_CLONE}") | |
Dir.chdir(TMP_GIT_CLONE) | |
puts "INFO: running jekyll build to '#{DOCROOT[branch]}'" | |
system("jekyll build -s #{TMP_GIT_CLONE} -d #{DOCROOT[branch]} --config #{JEKYLL_CONFIG[branch]}") | |
Dir.chdir(ENV['HOME']) | |
puts "INFO: removing #{TMP_GIT_CLONE}" | |
FileUtils.rm_rf(TMP_GIT_CLONE) | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment