-
Notifications
You must be signed in to change notification settings - Fork 15
/
update-hook
executable file
·51 lines (36 loc) · 1.03 KB
/
update-hook
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env bash
# Automatically deploy a web application by pushing updates to a git
# repository.
#
# For information on usage of this hook, please see the README.md that came
# with your installation of giddyup.
#
set -euo pipefail
# Consistent sourcing location for hooks deployed in multiple environments.
GIDDYUP_HOME="$(dirname "$(readlink -f "$0")")"
. "${GIDDYUP_HOME}/functions.sh"
REPO="$(dirname "$(cd "$(dirname "$0")"; pwd -P)")"
ROOT="$(dirname "${REPO}")"
if [ "$(get_config debug)" = "true" ]; then
set -x
fi
init_env
REF="$1"
OLDREV="$2"
NEWREV="$3"
IFS="," read -ra allowed_refs <<< "$(get_config allowedRefs "refs/heads/master,refs/heads/main")"
readonly allowed_refs
ref_allowed="n"
for aref in "${allowed_refs[@]}"; do
if [ "$aref" = "$REF" ]; then
ref_allowed="y"
fi
done
if [ "$ref_allowed" = "n" ]; then
echo "ERROR: Cannot push to ref $REF (allowed refs: ${allowed_refs[*]})" >&2
exit 1
fi
cd "${RELEASE}"
git --git-dir "${REPO}" archive --format=tar "${NEWREV}" | tar xf -
cd "${ROOT}"
cycle_release