Created
January 14, 2015 22:31
-
-
Save thehunmonkgroup/84034a4ec15667ce739d to your computer and use it in GitHub Desktop.
Deploy a Jekyll site to a non-bare repository via git push
This file contains 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
#!/bin/bash | |
# | |
# Utility script which can be used to trigger rebuild of a jekyll site that is | |
# managed via a git repository. Most often, you would call this script in the | |
# post-receive hook of a full (non-bare) git repository, such that the rebuild | |
# happens after a push. | |
# | |
# Run with no arguments for usage. | |
# | |
# CAVEATS: | |
# | |
# 1. The git, jekyll, and pygmentize executables must be in the PATH. | |
# 2. receive.denycurrentbranch should be set to 'warn' or 'ignore' in the | |
# target repository. From within the target repository: | |
# git config receive.denycurrentbranch warn | |
# 3. If you're foolish enough leave uncommitted changes lying around in the | |
# target repository, this script will wipe them out! | |
# | |
# Source the .bashrc file if present, this allows for a non-standard location | |
# of executables, such as via RVM/pyenv. | |
if [ -f ~/.bashrc ]; then | |
. ~/.bashrc | |
fi | |
GIT=`which git` | |
JEKYLL=`which jekyll` | |
TIMESTAMP=`date` | |
REPO_DIR=$1 | |
LOG_FILE=$2 | |
function usage() { | |
echo " | |
Usage: jekyll-git-push.sh <repo_dir> [log_file] | |
repo_dir: Full path to the working tree of the jekyll site repository. | |
log_file: Optional file to log results to. | |
Ex. jekyll-git-push.sh /home/me/repo /tmp/jekyll.log | |
" | |
} | |
function log() { | |
message=$1 | |
log_message="$TIMESTAMP - $REPO_DIR - $message" | |
echo "$log_message" | |
if [ "$LOG_FILE" != "" ]; then | |
echo "$log_message" >> $LOG_FILE | |
fi | |
} | |
if [ "$REPO_DIR" = "" ]; then | |
log "ERROR: no repository configured" | |
usage | |
exit 1 | |
fi | |
$GIT --work-tree=${REPO_DIR} --git-dir=${REPO_DIR}/.git reset --hard | |
if [ $? = 0 ]; then | |
$JEKYLL build -s $REPO_DIR -d ${REPO_DIR}/_site | |
if [ $? = 0 ]; then | |
log "site rebuild successful" | |
exit 0 | |
else | |
log "ERROR: could not rebuild site" | |
usage | |
fi | |
else | |
log "ERROR: could not reset the git working tree" | |
usage | |
fi | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment