Enable github CI.

Signed-off-by: Tao He <linzhu.ht@alibaba-inc.com>
This commit is contained in:
Tao He 2020-09-30 14:49:25 +08:00 committed by Tao He
parent 100eae97e9
commit 12f59ca48e
3 changed files with 106 additions and 4 deletions

95
.github/workflows/build-test.yml vendored Normal file
View File

@ -0,0 +1,95 @@
name: Build and Test
on:
# Trigger the workflow on push or pull request, but only for the master branch
push:
branches:
- ci
- master
pull_request:
branches:
- master
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04]
steps:
- uses: actions/checkout@v2
with:
submodules: true
- name: Cache for cccahe
uses: actions/cache@v2
with:
path: ~/.ccache
key: ${{ runner.os }}-ccache
restore-keys: |
${{ runner.os }}-ccache
- name: Install dependencies for Linux
if: runner.os == 'Linux'
run: |
sudo apt update -y
sudo apt install -y ca-certificates \
ccache \
cmake \
libboost-all-dev \
libcurl4-openssl-dev \
libgrpc-dev \
libgrpc++-dev \
libprotobuf-dev \
libssl-dev \
libz-dev \
lsb-release \
protobuf-compiler-grpc \
screenfetch \
wget
# install etcd
wget https://github.com/etcd-io/etcd/releases/download/v3.4.13/etcd-v3.4.13-linux-amd64.tar.gz
tar zxvf etcd-v3.4.13-linux-amd64.tar.gz
sudo mv etcd-v3.4.13-linux-amd64/etcd /usr/local/bin/
sudo mv etcd-v3.4.13-linux-amd64/etcdctl /usr/local/bin/
lsb_release -a
screenfetch
- name: Install cpprestsdk
run: |
mkdir -p build
cd build
git clone https://github.com/microsoft/cpprestsdk.git
mkdir -p cpprestsdk/build
cd cpprestsdk/build
cmake .. -DBUILD_TESTS=OFF \
-DBUILD_SAMPLES=OFF \
-DCPPREST_EXCLUDE_WEBSOCKETS=ON \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
make -j2
sudo make install
- name: Build
run: |
mkdir -p build
cd build
cmake .. -DBUILD_TESTS=ON \
-DCMAKE_C_COMPILER_LAUNCHER=ccache \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
make -j2
sudo make install
- name: Test
run: |
cd build
/usr/local/bin/etcd &
./bin/etcd_test
# note: no need to clean up on CI env
- name: Check ccache
run: |
ccache --show-stats

View File

@ -6,6 +6,8 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(etcd-cpp-api_VERSION_MAJOR 0)
set(etcd-cpp-api_VERSION_MINOR 1)
option(BUILD_TESTS "Build test cases" OFF)
find_library(CPPREST_LIB NAMES cpprest)
find_path(CPPREST_INCLUDE_DIR NAMES cpprest/http_client.h)
@ -36,7 +38,6 @@ set(GRPC_LIBRARIES ${GPR_LIBRARY} ${GRPC_LIBRARY} ${GRPC_GRPC++_LIBRARY})
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/GenerateProtobuf.cmake)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/proto)
enable_testing()
include_directories(SYSTEM ${CPPREST_INCLUDE_DIR}
${Boost_INCLUDE_DIR}
${PROTOBUF_INCLUDE_DIRS}
@ -44,9 +45,14 @@ include_directories(SYSTEM ${CPPREST_INCLUDE_DIR}
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Werror -Wno-string-compare -std=c++11")
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
add_subdirectory(src)
if (BUILD_TESTS)
enable_testing()
add_subdirectory(tst)
endif ()

View File

@ -8,7 +8,8 @@ add_executable(etcd_test
LockTest.cpp
)
set_property(TARGET etcd_test PROPERTY CXX_STANDARD 11)
target_include_directories(etcd_test PRIVATE ${CMAKE_SOURCE_DIR}/proto)
target_include_directories(etcd_test PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../proto/gen)
target_include_directories(etcd_test PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/../proto/gen/proto)
target_link_libraries(etcd_test etcd-cpp-api)