-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpost-receive
executable file
·32 lines (27 loc) · 994 Bytes
/
post-receive
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/bash
trap 'error_handler' ERR
function error_handler {
echo "🚨 An error occurred, deploy failed"
exit 1
}
# Clone the project as a bare repo, and install this hook at $GIT_DIR/hooks/post-receive
# Then add git remote locally, e.g. git remote add prod <server>:$TARGET
# to deploy: git push prod master
# make sure $TARGET exists on the server beforehand
TARGET="/srv/receptdatabasen"
GIT_DIR="/srv/receptdatabasen.git"
# shellcheck disable=SC2162
# shellcheck disable=SC2034
while read oldrev newrev ref
do
if [[ $ref =~ .*/master$ ]];
then
echo "Master ref received. Deploying master branch to production..."
git --work-tree=$TARGET --git-dir=$GIT_DIR checkout -f
cd $TARGET || error_handler
OLDREV=$oldrev NEWREV=$newrev REF=$ref $TARGET/scripts/deploy.sh
echo "🚀 Deployed $newrev"
else
echo "Ref $ref successfully received. Doing nothing: only the master branch may be deployed on this server."
fi
done