Created
April 1, 2015 17:46
-
-
Save askobara/1a86f57c03aa8e4c6fd1 to your computer and use it in GitHub Desktop.
Capistrano like post-receive git hook
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 | |
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