Skip to content

Commit aee5670

Browse files
authored
CPP-690 - Add per-commit Jenkins CI (#431)
1 parent b52b01c commit aee5670

2 files changed

Lines changed: 205 additions & 111 deletions

File tree

.build.sh

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
#!/bin/bash
2+
##
3+
# Copyright (c) DataStax, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
##
17+
18+
#Debug statements [if needed]
19+
#set -x #Trace
20+
#set -n #Check Syntax
21+
set -e #Fail fast on non-zero exit status
22+
23+
WORKER_INFORMATION=($(echo ${OS_VERSION} | tr "/" " "))
24+
DISTRO=${WORKER_INFORMATION[0]}
25+
RELEASE=${WORKER_INFORMATION[1]}
26+
SHA=$(echo ${GIT_COMMIT} | cut -c1-7)
27+
PROCS=$(grep -e '^processor' -c /proc/cpuinfo)
28+
29+
get_driver_version() {
30+
local header_file=$1
31+
local driver_prefix=$2
32+
local driver_version=$(grep "#define[ \t]\+${driver_prefix}_VERSION_\(MAJOR\|MINOR\|PATCH\|SUFFIX\)" ${header_file} | awk '
33+
BEGIN { major="?"; minor="?"; patch="?" }
34+
/_VERSION_MAJOR/ { major=$3 }
35+
/_VERSION_MINOR/ { minor=$3 }
36+
/_VERSION_PATCH/ { patch=$3 }
37+
/_VERSION_SUFFIX/ { suffix=$3; gsub(/"/, "", suffix) }
38+
END {
39+
if (length(suffix) > 0)
40+
printf "%s.%s.%s-%s", major, minor, patch, suffix
41+
else
42+
printf "%s.%s.%s", major, minor, patch
43+
}
44+
')
45+
if [[ ! ${driver_version} =~ ^[0-9]+\.[0-9]+\.[0-9]+([a-zA-Z0-9_\-]+)?$ ]]
46+
then
47+
echo "Unable to extract version from ${header_file} using prefix ${driver_prefix}"
48+
exit 1
49+
fi
50+
echo "${driver_version}"
51+
}
52+
53+
configure_environment() {
54+
if ! grep -lq "127.254.254.254" /etc/hosts; then
55+
printf "\n\n%s\n" "127.254.254.254 cpp-driver.hostname." | sudo tee -a /etc/hosts
56+
fi
57+
sudo cat /etc/hosts
58+
}
59+
60+
install_libuv() {
61+
(
62+
cd packaging
63+
git clone --depth 1 https://github.com/datastax/libuv-packaging.git
64+
65+
(
66+
cd libuv-packaging
67+
if [ "${DISTRO}" = "ubuntu" ]; then
68+
./build_deb.sh ${LIBUV_VERSION}
69+
else
70+
./build_rpm.sh ${LIBUV_VERSION}
71+
fi
72+
)
73+
74+
[[ -d packages ]] || mkdir packages
75+
find libuv-packaging/build -type f \( -name "*.deb" -o -name "*.rpm" \) -exec mv {} packages \;
76+
77+
if [ "${DISTRO}" = "ubuntu" ]; then
78+
sudo dpkg -i packages/libuv*.deb
79+
else
80+
sudo rpm -i packages/libuv*.rpm
81+
fi
82+
)
83+
}
84+
85+
install_dependencies() {
86+
install_libuv
87+
}
88+
89+
build_driver() {
90+
local driver_prefix=$1
91+
92+
(
93+
[[ -d build ]] || mkdir build
94+
cd build
95+
cmake -DCMAKE_BUILD_TYPE=Release -D${driver_prefix}_BUILD_SHARED=On -D${driver_prefix}_BUILD_STATIC=On -D${driver_prefix}_BUILD_EXAMPLES=On -D${driver_prefix}_BUILD_UNIT_TESTS=On ..
96+
make -j${PROCS}
97+
)
98+
}
99+
100+
install_driver() {
101+
(
102+
cd packaging
103+
104+
(
105+
if [ "${DISTRO}" = "ubuntu" ]; then
106+
./build_deb.sh
107+
else
108+
./build_rpm.sh
109+
fi
110+
)
111+
112+
[[ -d packages ]] || mkdir packages
113+
find build -type f \( -name "*.deb" -o -name "*.rpm" \) -exec mv {} packages \;
114+
115+
if [ "${DISTRO}" = "ubuntu" ]; then
116+
sudo dpkg -i packages/*cpp-driver*.deb
117+
else
118+
sudo rpm -i packages/*cpp-driver*.rpm
119+
fi
120+
)
121+
}
122+
123+
test_installed_driver() {
124+
local driver=$1
125+
126+
local test_program=$(mktemp)
127+
gcc -x c -o ${test_program} - -Wno-implicit-function-declaration -l${driver} - <<EOF
128+
#include <${driver}.h>
129+
130+
int main(int argc, char* argv[]) {
131+
CassFuture* connect_future = NULL;
132+
CassCluster* cluster = cass_cluster_new();
133+
CassSession* session = cass_session_new();
134+
135+
cass_cluster_set_contact_points(cluster, "127.0.0.1");
136+
connect_future = cass_session_connect(session, cluster);
137+
cass_future_wait(connect_future);
138+
printf("Success");
139+
return 0;
140+
}
141+
EOF
142+
143+
if [ $? -ne 0 ] ; then
144+
echo "Connection test compilation failed. Marking build as failure."
145+
exit 1
146+
fi
147+
if [ "$($test_program)" != "Success" ] ; then
148+
echo "Connection test did not return success. Marking build as failure."
149+
exit 1
150+
fi
151+
}
152+
153+
check_driver_exports() {(
154+
set +e #Disable fail fast for this subshell
155+
local driver_library=$1
156+
if [ -f ${driver_library} ]; then
157+
declare -a MISSING_FUNCTIONS
158+
for function in "${@:2}"; do
159+
nm ${driver_library} | grep ${function} > /dev/null
160+
if [ $? -ne 0 ]
161+
then
162+
MISSING_DEFINITION+=("${function}")
163+
fi
164+
done
165+
if [ ! -z "${MISSING_DEFINITION}" ]; then
166+
printf "Function(s) have no definition:\n"
167+
for function in ${MISSING_DEFINITION[@]}
168+
do
169+
printf " ${function}\n"
170+
done
171+
exit 1
172+
fi
173+
fi
174+
)}

build.yaml

Lines changed: 31 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@ schedules:
33
schedule: adhoc
44
notify:
55
slack: cpp-driver-dev-bots
6+
commit:
7+
schedule: per_commit
8+
notify:
9+
slack: cpp-driver-dev-bots
610
branches:
7-
include: [master]
11+
include: ["/CPP-\\d+/", "master"]
812
architecture:
913
- x64
1014
os:
@@ -13,120 +17,36 @@ os:
1317
- ubuntu/xenial64
1418
- centos/6-64
1519
- centos/7-64
20+
env:
21+
LIBUV_VERSION: 1.23.0
1622
build:
1723
- script: |
18-
echo "Running packaging job"
19-
package:
20-
include: # list of files and glob paths to include in the artifact, relative to the current working directory
21-
- packaging/packages/*
22-
release:
23-
notify:
24-
slack: cpp-driver-dev-bots
25-
after:
26-
each:
27-
- script: |
28-
LIBUV_VERSION=1.23.0
29-
CC=gcc
30-
TEST_PROGRAM=$(mktemp)
31-
TOKENS=($(echo ${OS_VERSION} | tr "/" " "))
32-
DISTRO=${TOKENS[0]}
33-
RELEASE=${TOKENS[1]}
34-
SHA=$(echo $GIT_COMMIT | cut -c1-7)
35-
HEADER_FILE="include/cassandra.h"
36-
37-
if [ "${DISTRO}" = "ubuntu" ]; then
38-
NAME=$(echo ${RELEASE%??})
39-
ARCHITECTURE=${RELEASE:-2}
40-
PACKAGE_TYPE=deb
41-
PACKAGE_INSTALL="dpkg -i"
42-
if [ "${NAME}" = "trusty" ]; then
43-
RELEASE=14.04
44-
elif [ "${NAME}" = "xenial" ]; then
45-
RELEASE=16.04
46-
elif [ "${NAME}" = "bionic" ] || [ "${NAME}" = "bionic64" ]; then
47-
RELEASE=18.04
48-
else
49-
printf "Unsupported Ubuntu Version: %s\n" ${RELEASE}
50-
exit 1
51-
fi
52-
elif [ "${DISTRO}" = "centos" ]; then
53-
TOKENS=($(echo ${RELEASE} | tr "-" " "))
54-
NAME=${DISTRO}
55-
RELEASE=${TOKENS[0]}
56-
ARCHITECTURE=${TOKENS[1]}
57-
PACKAGE_TYPE=rpm
58-
PACKAGE_INSTALL="rpm -i"
59-
else
60-
printf "Unsupported OS: %s\n" ${OS_VERSION}
61-
exit 1
62-
fi
24+
. .build.sh
25+
configure_environment
26+
install_dependencies
6327
64-
# Extract driver version from the header file
65-
DRIVER_VERSION=$(grep '#define[ \t]\+CASS_VERSION_\(MAJOR\|MINOR\|PATCH\|SUFFIX\)' $HEADER_FILE | awk '
66-
BEGIN { major="?"; minor="?"; patch="?" }
67-
/CASS_VERSION_MAJOR/ { major=$3 }
68-
/CASS_VERSION_MINOR/ { minor=$3 }
69-
/CASS_VERSION_PATCH/ { patch=$3 }
70-
/CASS_VERSION_SUFFIX/ { suffix=$3; gsub(/"/, "", suffix) }
71-
END {
72-
if (length(suffix) > 0)
73-
printf "%s.%s.%s-%s", major, minor, patch, suffix
74-
else
75-
printf "%s.%s.%s", major, minor, patch
76-
}
77-
')
28+
build_driver 'CASS'
7829
79-
if [[ ! $DRIVER_VERSION =~ ^[0-9]+\.[0-9]+\.[0-9]+([a-zA-Z0-9_\-]+)?$ ]]; then
80-
echo "Unable to extract version from $HEADER_FILE"
81-
exit 1
82-
fi
30+
FUNCTIONS+=($(grep -Eoh '^cass_\s*(\w+)\s*\(' include/cassandra.h | awk -F '(' '{print $1}'))
31+
check_driver_exports 'build/libcassandra_static.a' "${FUNCTIONS[@]}"
8332
84-
pushd packaging
85-
mkdir -p packages
33+
build/cassandra-unit-tests --gtest_output=xml:cassandra-unit-test-results.xml
8634
87-
echo "Building libuv Packages [${LIBUV_VERSION}] ...\n"
88-
git clone --depth 1 https://github.com/datastax/libuv-packaging.git libuv-packaging
89-
pushd libuv-packaging
90-
./build_${PACKAGE_TYPE}.sh ${LIBUV_VERSION}
91-
popd
92-
find libuv-packaging/build -type f -name "*.${PACKAGE_TYPE}" -exec mv {} packages \;
93-
sudo ${PACKAGE_INSTALL} packages/libuv*.${PACKAGE_TYPE}
35+
install_driver
36+
test_installed_driver 'cassandra'
9437
95-
echo "Building DataStax C/C++ driver ..."
96-
./build_${PACKAGE_TYPE}.sh
97-
find build -type f -name "*.${PACKAGE_TYPE}" -exec mv {} packages \;
98-
sudo ${PACKAGE_INSTALL} packages/cassandra*.${PACKAGE_TYPE}
99-
100-
# Create test file against cpp-driver and try to connect.
101-
# Should compile and throw a connection error when executed.
102-
$CC -x c -o $TEST_PROGRAM - -Wno-implicit-function-declaration -lcassandra - <<EOF
103-
#include <cassandra.h>
104-
int main(int argc, char* argv[]) {
105-
CassFuture* connect_future = NULL;
106-
CassCluster* cluster = cass_cluster_new();
107-
CassSession* session = cass_session_new();
108-
cass_cluster_set_contact_points(cluster, "127.0.0.1");
109-
connect_future = cass_session_connect(session, cluster);
110-
cass_future_wait(connect_future);
111-
printf("Success\n");
112-
return 0;
113-
}
114-
EOF
115-
116-
# Throw error if either compilation or test run fails
117-
if [ $? -ne 0 ] ; then
118-
echo "Connection test compilation failed. Marking build as failure."
119-
exit 1
120-
fi
121-
122-
if [ "$($TEST_PROGRAM)" != "Success" ] ; then
123-
echo "Connection test did not return success. Marking build as failure."
124-
exit 1
125-
fi
126-
127-
# Uploading driver packages
128-
curl -$ARTIFACTORY_CREDS -T "{$(echo packages/cassandra-cpp-driver* | tr ' ' ',')}" "https://datastax.jfrog.io/datastax/cpp-php-drivers/cpp-driver/builds/$version/$SHA/$DISTRO/$RELEASE/cassandra/v$DRIVER_VERSION/"
129-
130-
# Uploading libuv packages
131-
curl -$ARTIFACTORY_CREDS -T "{$(echo packages/libuv* | tr ' ' ',')}" "https://datastax.jfrog.io/datastax/cpp-php-drivers/cpp-driver/builds/$version/$SHA/$DISTRO/$RELEASE/dependencies/libuv/v$LIBUV_VERSION/"
132-
popd
38+
- xunit:
39+
- "*unit-test-results.xml"
40+
package:
41+
include: # list of files and glob paths to include in the artifact, relative to the current working directory
42+
- packaging/packages/*
43+
release:
44+
after:
45+
each:
46+
- script: |
47+
. .build.sh
48+
DRIVER_VERSION=$(get_driver_version 'include/cassandra.h' 'CASS')
49+
# Uploading driver packages
50+
curl -$ARTIFACTORY_CREDS -T "{$(echo packaging/packages/cassandra-cpp-driver* | tr ' ' ',')}" "https://datastax.jfrog.io/datastax/cpp-php-drivers/cpp-driver/builds/$version/$SHA/$DISTRO/$RELEASE/cassandra/v$DRIVER_VERSION/"
51+
# Uploading libuv packages
52+
curl -$ARTIFACTORY_CREDS -T "{$(echo packaging/packages/libuv* | tr ' ' ',')}" "https://datastax.jfrog.io/datastax/cpp-php-drivers/cpp-driver/builds/$version/$SHA/$DISTRO/$RELEASE/dependencies/libuv/v$LIBUV_VERSION/"

0 commit comments

Comments
 (0)