-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathnightly_build.sh
executable file
·86 lines (70 loc) · 2.65 KB
/
nightly_build.sh
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
#!/bin/bash
PostToSlack () {
# Single quoting the string breaks formatting, so instead we rely on the \" -> \\" to make sure this doesn't break the curl
# SAFE_TEXT=${1@Q}
SAFE_TEXT=${1//\"/\\\"}
curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"$SAFE_TEXT\"}" $HOOK_URL
}
# Make sure all of our necessary configuration works
source nightly_env.sh
if [ -z "$HOOK_URL" ] || [ -z "$BOT_TOKEN" ]; then
echo "Nightly build cannot work without the following settings set: \$HOOK_URL and \$BOT_TOKEN"
exit
fi
# Clean all
make clean-all
docker system prune -af
# Double check that the .env file works?
# But also we need to check that we can't just merge the .env file
if [[ $SKIP_GIT -ne 1 ]]; then
git stash push -m "NIGHTLY_STASH"
git pull >tmp/gitpull.txt 2<&1
if [ $? -ne 0 ]; then
PostToSlack "Could not automatically pull git repo:\n\`\`\`$(cat tmp/gitpull.txt)\`\`\`"
exit
fi
git submodule update --recursive --init
# Figure out the index of the stash we applied
STASH_TEXT=$(git stash list | grep "NIGHTLY_STASH")
if [[ ! -z $STASH_TEXT ]]; then
[[ $STASH_TEXT =~ \{([[:digit:]]+)\} ]]
git stash pop ${BASH_REMATCH[1]} >tmp/stashapply.txt 2<&1
if [ $? -ne 0 ]; then
PostToSlack "Could not automatically merge git repo:\n\`\`\`$(cat tmp/stashapply.txt)\`\`\`"
exit
fi
fi
fi
# Rerun nightly_env.sh in case anything changed in the .env file
source nightly_env.sh
# Re-initialize conda
make bin-conda
source bin/miniconda3/etc/profile.d/conda.sh
make init-conda
conda activate candig
make build-all BUILD_OPTS="--no-cache" ARGS="-s" >tmp/lastbuild.txt 2<&1
if [ $? -ne 0 ]; then
PostToSlack "Build failed:\n\`\`\`$(tail tmp/lastbuild.txt)\`\`\`"
exit
fi
# Don't run integration tests until we see that every service has completed setup
TYK_TESTS=""
TRIES=0
while [ -z "$TYK_TESTS" ];
do
TYK_TESTS=$(make test-integration ARGS='-k "test_tyk" etc/tests/test_integration.py' | grep "1 passed")
sleep 15
TRIES=$TRIES+1
if [[ $TRIES -gt 120 ]]; then
PostToSlack "Tyk did not go live after 30 minutes"
exit
fi
done
make test-integration >tmp/integration-build.txt 2<&1
if [ $? -ne 0 ]; then
PostToSlack "Integration tests failed:\n\`\`\`$(tail tmp/integration-build.txt)\`\`\`"
exit
fi
source env.sh
cd $BUILD_PATH
PostToSlack "\`\`\`\nBuild success:\n$TYK_LOGIN_TARGET_URL\nusername: $CANDIG_SITE_ADMIN_USER\npassword $CANDIG_SITE_ADMIN_PASSWORD\nusername: $CANDIG_NOT_ADMIN_USER\npassword $CANDIG_NOT_ADMIN_PASSWORD\nusername: $CANDIG_NOT_ADMIN2_USER\npassword $CANDIG_NOT_ADMIN2_PASSWORD\n\`\`\`"