-
Notifications
You must be signed in to change notification settings - Fork 12
/
travis_configure.sh
executable file
·150 lines (137 loc) · 4.16 KB
/
travis_configure.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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
# Script for setting up OS specific CI test environment on travis-ci.org
#
# Copyright: Copyright (c) 2017 dunnhumby Germany GmbH. All rights reserved
set -e
# Script to print error message with the build is and environment variable
# MAKE_TARGET
#
# $1 error message to show
#
# Returns 0
print_error_msg ()
{
test ! -z "$1" || exit 1
echo "$1"
echo " os: $TRAVIS_OS_NAME"
echo " lsb: $DIST_NAME $DIST_VERSION"
echo " targets: $MAKE_TARGET"
return 0
}
# Script which is run before the installation script is called
#
# Only dependencies required in the native travis build environment should be
# installed in this step.
#
# For osx based builds homebrew is used to install required packages:
# - sed, (libtool), openssl, mysql
# Returns 0
before_install()
{
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
# jfrog dependency
if [[ -n "$TRAVIS_TAG" && ! -e $HOME/bin/jfrog ]]; then
mkdir -p $HOME/bin ;
curl -XGET -L -k 'https://api.bintray.com/content/jfrog/jfrog-cli-go/$latest/jfrog-cli-linux-amd64/jfrog?bt_package=jfrog-cli-linux-amd64' > $HOME/bin/jfrog ;
chmod a+x $HOME/bin/jfrog ;
fi
elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
brew update
brew install gnu-sed
xcode_version=`xcodebuild -version | grep 'Xcode' | cut -f 2 -d ' '`
# reinstall libtool on osx_image xcode6.x to ensure gsed is found by
# glibtoolize
if [[ "$xcode_version" == 6.* ]]; then
brew reinstall libtool
fi
brew install openssl
brew install [email protected]
brew link --overwrite --force [email protected]
else
print_error_msg "Invalid build configuration"
return 1
fi
return 0
}
# Enable binary logging by setting log_bin and server_id in the [mysqld]
# section of the mysql config file
#
# $1 path to mysql config file
#
# Returns 0
enable_mysqlbinlog()
{
echo "[mysqld]" | sudo tee -a "$1"
echo "server-id=1" | sudo tee -a "$1"
echo "log_bin=mysql_binlog" | sudo tee -a "$1"
return 0
}
# Invoked by the travis hook before_script to prepare the build environment
#
# For linux based builds docker-compose is used to set up the build environment
#
# No dependencies required in the native travis build environment should be
# installed in this step. Use before_install instead
#
# Returns 0 or 1 if called with an invalid build configuration
before_script()
{
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
# build images
docker-compose -f ./docker-compose.yml \
-f ./docker/docker-compose.$DIST_NAME.$DIST_VERSION.yml \
build
elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
# Creates a MySQL config file with binary logging enabled and
# starts the MySQL server
enable_mysqlbinlog "$HOME/.my.cnf"
mysql.server start
else
print_error_msg "Invalid build configuration"
return 1
fi
return 0
}
# Invoked by the travis hook script.
#
# Runs ci tests on travis' native build environment or in docker containers
#
# Linux:
# docker-compose is used to create a container with MySQL and a
# container which configures, compiles, tests and possibly builds
# distribution packages depending on the build configuration
#
# OSX:
# Compiles and runs unittests in the travis osx build environment
#
# Returns 0 or 1 if called with an invalid build configuration
run_tests()
{
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
docker-compose up --abort-on-container-exit
elif [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
if [ -d ./build ]; then
rm -rf build
fi
mkdir build && cd build
autoreconf -fi ..
# Pass the root of the openssl installation directory
../configure --with-openssl=$(brew --prefix openssl)
make check
else
print_error_msg "Invalid build configuration"
return 1
fi
return 0
}
## Script entrypoint
if [[ $1 == "before_install" ]]; then
before_install
elif [[ $1 == "before_script" ]]; then
before_script
elif [[ $1 == "run_tests" ]]; then
run_tests
else
echo "invalid function call"
exit 1
fi