Created
May 24, 2013 04:56
-
-
Save drewinglis/5641346 to your computer and use it in GitHub Desktop.
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 | |
# don't deploy if we don't want to | |
DEPLOY_BRANCH=$(git config --get s3-deploy.branch) | |
if [ -z ${DEPLOY_BRANCH} ]; then | |
echo "No deploy branch. Exiting. (Add the s3-deploy.branch config variable in the gitolite.conf file.)" | |
exit 0 | |
fi | |
CURRENT_BRANCH="" | |
while read oldrev newrev refname | |
do | |
CURRENT_BRANCH=$(git rev-parse --symbolic --abbrev-ref $refname) | |
done | |
if [ ${DEPLOY_BRANCH} != ${CURRENT_BRANCH} ]; then | |
echo "Current branch: ${CURRENT_BRANCH} does not match deploy branch: ${DEPLOY_BRANCH}. Skipping. (Change the s3-deploy.branch config variable in the gitolite.conf file.)" | |
exit 0 | |
fi | |
# get repository name | |
if [ $(git rev-parse --is-bare-repository) = true ] | |
then | |
REPOSITORY_DIR=$PWD | |
else | |
REPOSITORY_DIR=$(readlink -nf "$PWD"/..) | |
fi | |
REPOSITORY_NAME=$(basename "${REPOSITORY_DIR}") | |
REPOSITORY_NAME=${REPOSITORY_NAME%.git} | |
echo "Using ${REPOSITORY_NAME} as project name" | |
# get the bucket name before we change git contexts | |
BUCKET_NAME=$(git config --get s3-deploy.bucket-name) | |
# change to local copy and checkout code | |
LOCAL_COPY=${HOME}/${REPOSITORY_NAME} | |
if [ -d ${LOCAL_COPY} ]; then | |
git --git-dir=${LOCAL_COPY}/.git fetch | |
git --git-dir=${LOCAL_COPY}/.git --work-tree=${LOCAL_COPY} reset origin/${DEPLOY_BRANCH} --hard | |
else | |
git clone ${REPOSITORY_DIR} ${LOCAL_COPY} | |
if [ "master" != ${DEPLOY_BRANCH} ]; then | |
git --git-dir=${LOCAL_COPY}/.git --work-tree=${LOCAL_COPY} checkout --track origin/${DEPLOY_BRANCH} | |
fi | |
fi | |
# set the ruby version we want | |
source ${HOME}/.bash_profile | |
rvm use 1.9.3 | |
cd ${LOCAL_COPY} | |
# install gems | |
if [ -f Gemfile ]; then | |
echo "Installing gems from Gemfile..." | |
bundle install | |
else | |
echo "No Gemfile found, skipping bundle install" | |
fi | |
# do the jekyll-y thing | |
echo "Running jekyll preprocessor..." | |
jekyll --no-auto | |
# upload to S3 | |
if [ -z ${BUCKET_NAME} ]; then | |
BUCKET_NAME=${REPOSITORY_NAME} | |
fi | |
echo "Uploading to S3 bucket: ${BUCKET_NAME}" | |
cd _site | |
for file in $(find . | cut -c 3-); do | |
# check that we actually have a file to upload (no empty paths, no directories) | |
if [ -n ${file} ] && [ -f ${file} ]; then | |
echo "UPLOADING: ${file}" | |
s3put ${BUCKET_NAME} ${file} | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment