Skip to content

Instantly share code, notes, and snippets.

@reklis
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reklis/a48e48965747406b7048 to your computer and use it in GitHub Desktop.
Save reklis/a48e48965747406b7048 to your computer and use it in GitHub Desktop.
git hooks example
#!/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
#!/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