-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-receive
More file actions
executable file
·129 lines (98 loc) · 2.86 KB
/
pre-receive
File metadata and controls
executable file
·129 lines (98 loc) · 2.86 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#!/bin/bash
# flush STDIN coming from git; we have no use for that info in this hook but
# if you don't do this, git-shell sometimes dies of a signal 13 (SIGPIPE)
#[ -t 0 ] || cat >/dev/null
PATH=/usb/bin/:$PATH
APIURL="http://192.168.13.7:9001"
APIKEY="cM7I84LFT9s29u0tnxrvZaMze677ZE60" #test only
set -e
status() {
echo "-----> $*"
}
indent() {
c='s/^/ /'
case $(uname) in
Darwin) sed -l "$c";; # mac/bsd sed: -l buffers on line boundaries
*) sed -u "$c";; # unix/gnu sed: -u unbuffered (arbitrary) chunks of data
esac
}
suppress () {
c="s/^/`echo $'\e[1G'`/"
case $(uname) in
# Darwin) sed -e "s/^/\x1b[1g/";; # mac/bsd sed: -l buffers on line boundaries
Darwin) sed -l "$c";; # mac/bsd sed: -l buffers on line boundaries
*) sed -u "$c";; # unix/gnu sed: -u unbuffered (arbitrary) chunks of data
esac
}
echo | suppress
while read oldrev newrev refname
do
# Do something with $oldrev $newrev $refname
REF=$refname
NEWREV=$newrev
done
# GUMMI=`git ls-tree $NEWREV --name-only | grep .gummi`
# if [ "$GUMMI" = "" ]; then
# exit 0
# fi
BRANCH=$(echo $REF | grep "refs/heads" | sed 's/refs\/heads\///g')
if [ "$BRANCH" = "" ]; then
print "Couldn't determine branch. Ignoring."
exit 0;
fi
#REPO_NAME=$(pwd | awk -F"/" '{ print $NF }')
REPO_NAME=$(pwd | awk -F"/" '{ print $(NF-1),":",$NF }' | tr -d ' ' )
REPO_NAME=$(pwd | awk -F"/" '{print $NF}')
#git config -l
#pwd
#echo $REPO_NAME
#exit 1
status "Update pushed to branch: $BRANCH" | suppress
if [ "$(git ls-tree $NEWREV --name-only .gitmodules)" != "" ]; then
echo | suppress
echo " ! Git submodules are notsupported " | suppress
echo "" | suppress
exit 1
fi
# git archive --format tar.gz $NEWREV | ssh -o StrictHostKeyChecking=no -i ~/.ssh/id_dsa cdn@10.1.69.105 "cat - > git/$REPO_NAME-$BRANCH-$NEWREV.tar.gz"
# print " > Repository exported"
# echo " > Call api build: " curl -N -u :cM7I84LFT9s29u0tnxrvZaMze677ZE60 -s "http://api.nibbler.cz/git/$REPO_NAME/$BRANCH/$NEWREV"
echo "Reponame" $REPO_NAME | indent | suppress
echo "Reponame" $BRANCH | indent | suppress
echo "Reponame" $NEWREV | indent | suppress
status "Calling build api" | suppress
IFS=$'\n'
curl -s -N -u :$APIKEY -s "$APIURL/git/$REPO_NAME/$BRANCH/$NEWREV" 2>&1 | \
while read i
do
WAS_RESULT=1
if [ "$i" = "94ed473f82c3d1791899c7a732fc8fd0_exit_0" ]; then
export TERM="xterm"
tput setaf 2
echo -n " > Success" | suppress
tput sgr0
echo -e "\n" | suppress
exit 5
fi
# TODO predelat na regular
if [ "$i" = "94ed473f82c3d1791899c7a732fc8fd0_exit_1" ]; then
export TERM="xterm"
tput setaf 1
echo -n " > Build failed! " | suppress
tput sgr0
echo -e "\n" | suppress
echo | suppress
exit 1
fi
echo " $i" | suppress | indent
done
if [ "$?" = "5" ]; then
echo | suppress
exit 0
fi
export TERM="xterm"
tput setaf 1
status "Invalid api reposne " | suppress
tput sgr0
echo | suppress
exit 1