Skip to content

Commit

Permalink
Setup minimal CI (#17)
Browse files Browse the repository at this point in the history
* Setup basic ci

* Add empty README

* Fix script path

* Fill out README.

* Typo.

* Add missing script name.

* Remove unnecessary packages

* Use fastbuild.

* Fix typo.

Co-authored-by: easy <g-easy@users.noreply.github.com>
  • Loading branch information
rnburn and g-easy authored Dec 23, 2019
1 parent 73fd549 commit 9b0925b
Show file tree
Hide file tree
Showing 10 changed files with 127 additions and 0 deletions.
1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.2.0
33 changes: 33 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: 2.1

jobs:
cmake_test:
resource_class: xlarge
docker:
- image: ubuntu:18.04
steps:
- checkout
- run: ./ci/setup_ci_environment.sh
- run: ./ci/setup_cmake.sh
- run: ./ci/do_ci.sh cmake.test
- store_artifacts:
path: /build/Testing/Temporary/LastTest.log
destination: Test.log

bazel_test:
resource_class: xlarge
docker:
- image: ubuntu:18.04
steps:
- checkout
- run: ./ci/setup_ci_environment.sh
- run: ./ci/install_bazelisk.sh
- run: ./ci/do_ci.sh bazel.test


workflows:
version: 2
build_and_test:
jobs:
- cmake_test
- bazel_test
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
cmake_minimum_required(VERSION 3.1)

# See https://cmake.org/cmake/help/v3.3/policy/CMP0057.html
# required by certain versions of gtest
cmake_policy(SET CMP0057 NEW)

project(opentelemetry-cpp)

set(CMAKE_CXX_STANDARD 11)
Expand Down
11 changes: 11 additions & 0 deletions ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM ubuntu:18.04

WORKDIR /setup-ci

ADD setup_ci_environment.sh /setup-ci
ADD setup_cmake.sh /setup-ci
ADD install_bazelisk.sh /setup-ci

RUN /setup-ci/setup_ci_environment.sh \
&& /setup-ci/setup_cmake.sh \
&& /setup-ci/install_bazelisk.sh
6 changes: 6 additions & 0 deletions ci/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Building and running tests as a developer
CI tests can be run on docker by invoking the script `./ci/run_docker.sh ./ci/do_ci.sh <TARGET>` where the targets are
* `cmake.test` build cmake targets and run tests
* `bazel.test` build bazel targets and run tests
Additionally, `./ci/run_docker.sh` can be invoked with no arguments to get a docker shell where tests
can be run manually.
27 changes: 27 additions & 0 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

set -e

[ -z "${SRC_DIR}" ] && export SRC_DIR="`pwd`"
[ -z "${BUILD_DIR}" ] && export BUILD_DIR=/build
mkdir -p "${BUILD_DIR}"

BAZEL_OPTIONS=""
BAZEL_TEST_OPTIONS="$BAZEL_OPTIONS --test_output=errors"

if [[ "$1" == "cmake.test" ]]; then
cd "${BUILD_DIR}"
cmake -DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_FLAGS="-Werror" \
"${SRC_DIR}"
make
make test
exit 0
elif [[ "$1" == "bazel.test" ]]; then
bazel build $BAZEL_OPTIONS -- //...
bazel test $BAZEL_TEST_OPTIONS //...
exit 0
else
echo "Invalid do_ci.sh target, see ci/README.md for valid targets."
exit 1
fi
8 changes: 8 additions & 0 deletions ci/install_bazelisk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

set -e

BAZELISK_VERSION=v1.1.0

wget -O /usr/local/bin/bazel https://github.com/bazelbuild/bazelisk/releases/download/$BAZELISK_VERSION/bazelisk-linux-amd64
chmod +x /usr/local/bin/bazel
14 changes: 14 additions & 0 deletions ci/run_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash

set -e

BUILD_IMAGE=opentelemetry-cpp-build
docker image inspect "$BUILD_IMAGE" &> /dev/null || {
docker build -t "$BUILD_IMAGE" ci
}

if [[ $# -ge 1 ]]; then
docker run -v "$PWD":/src -w /src -it "$BUILD_IMAGE" "$@"
else
docker run -v "$PWD":/src -w /src --privileged -it "$BUILD_IMAGE" /bin/bash -l
fi
8 changes: 8 additions & 0 deletions ci/setup_ci_environment.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash

set -e
apt-get update
apt-get install --no-install-recommends --no-install-suggests -y \
build-essential \
ca-certificates \
wget
15 changes: 15 additions & 0 deletions ci/setup_cmake.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -e

apt-get install --no-install-recommends --no-install-suggests -y \
cmake \
libgtest-dev

# Follows these instructions for setting up gtest
# https://www.eriksmistad.no/getting-started-with-google-test-on-ubuntu/
pushd /usr/src/gtest
cmake CMakeLists.txt
make
cp *.a /usr/lib
popd

0 comments on commit 9b0925b

Please sign in to comment.