Skip to content

Instantly share code, notes, and snippets.

@askobara
Created April 1, 2015 17:46
Show Gist options
  • Save askobara/1a86f57c03aa8e4c6fd1 to your computer and use it in GitHub Desktop.
Save askobara/1a86f57c03aa8e4c6fd1 to your computer and use it in GitHub Desktop.
Capistrano like post-receive git hook
#!/bin/bash
ROOT='/home/git/testing'
BRANCH='master'
MAX_RELEASES=5
RELEASE=$(date +%s)
while read oldrev newrev refname
do
branch=$(git rev-parse --symbolic --abbrev-ref $refname)
if [ "$BRANCH" == "$branch" ]; then
# create new release
mkdir -p "$ROOT/releases/$RELEASE"
git archive $branch | tar -x -f - -C "$ROOT/releases/$RELEASE"
# all customizations should be placed here
# such as running composer, migrations, etc.
# create symlink to the last release
ln -s "$ROOT/releases/$RELEASE" "$ROOT/releases/current"
mv "$ROOT/releases/current" "$ROOT/"
# delete old releases
OLD_RELEASES=$(ls -1 "$ROOT/releases" | sort -h | head -n -$MAX_RELEASES)
for OLD in $OLD_RELEASES; do
rm -rf "$ROOT/releases/$OLD"
done
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment