Last active
August 29, 2015 14:18
-
-
Save reklis/a48e48965747406b7048 to your computer and use it in GitHub Desktop.
git hooks example
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
#!/bin/bash | |
# server-side post-update deployment hook | |
# https://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin | |
set -e # exit immediately if anything is non-zero return | |
set -m # enable background jobs | |
set -u # undefined variables are an error | |
set -x # echo the commands while they are executed | |
# curl mywebhook/deploymentstarted | |
# note that the initial working directory is the repo, not the hooks directory | |
deployment=../deployedfoo | |
archive="/tmp/foo-$(date +%Y%m%d-%H%M%S).zip" | |
# export an archive of the code from the repo | |
git archive -o "$archive" master | |
# kill the current deployment | |
rm -rf "$deployment" | |
mkdir -p "$deployment" | |
# extract the archive to the deployment folder | |
unzip -o "$archive" -d "$deployment" | |
rm "$archive" | |
# change to the deployment folder and do whatever to finish up | |
# npm i --production, bundle install, etc | |
cd "$deployment" | |
make main | |
logfile="$(pwd -P)/main.log" | |
nohup ./main.o &>$logfile & | |
echo $! > ./main.pid | |
# curl mywebhook/deploymentcomplete |
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
#!/bin/sh | |
# local client-side pre-commit test hook | |
make test | |
# grunt test | |
# gulp test | |
# etc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment