Skip to content

Commit c02c70c

Browse files
authored
chore: CI Build & Test (#8)
1 parent 2203788 commit c02c70c

File tree

14 files changed

+208
-3
lines changed

14 files changed

+208
-3
lines changed

.github/actions/ci/action.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This is a composite to allow sharing these steps into other workflows.
2+
# It isn't a shared workflow, because then it isn't convenient to add
3+
# additional package-specific steps.
4+
5+
# The CMake project should follow a convention where the test project is
6+
# gtest_LIBNAME for instance gtest_launchdarkly-cpp-common.
7+
name: Shared CI Workflow
8+
description: 'Shared CI workflow used by C++ packages.'
9+
inputs:
10+
cmake_target:
11+
description: 'The name of the CMake target. i.e. launchdarkly-cpp-common'
12+
required: true
13+
14+
runs:
15+
using: composite
16+
steps:
17+
- name: Install boost
18+
uses: MarkusJx/[email protected]
19+
id: install-boost
20+
with:
21+
boost_version: 1.81.0
22+
platform_version: 22.04
23+
boost_install_dir: /home/runner/boost
24+
- name: Build Library
25+
shell: bash
26+
run: ./scripts/build.sh ${{ inputs.cmake_target }} ON
27+
env:
28+
BOOST_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }}
29+
- name: Build Tests
30+
shell: bash
31+
run: ./scripts/build.sh gtest_${{ inputs.cmake_target }} ON
32+
env:
33+
BOOST_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }}
34+
- name: Run Tests
35+
shell: bash
36+
# This uses the binary, versus "make tests" because the binary
37+
# has better performance and output.
38+
run: ./build/gtest_${{ inputs.cmake_target }}

.github/workflows/client.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: libs/client-sdk
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths-ignore:
7+
- '**.md' #Do not need to run CI for markdown changes.
8+
pull_request:
9+
branches: [main]
10+
paths-ignore:
11+
- '**.md'
12+
13+
jobs:
14+
build-test-common:
15+
runs-on: ubuntu-22.04
16+
steps:
17+
- uses: actions/checkout@v3
18+
- uses: ./.github/actions/ci
19+
with:
20+
cmake_target: launchdarkly-cpp-client

.github/workflows/common.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: libs/common
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths-ignore:
7+
- '**.md' #Do not need to run CI for markdown changes.
8+
pull_request:
9+
branches: [main]
10+
paths-ignore:
11+
- '**.md'
12+
13+
jobs:
14+
build-test-common:
15+
runs-on: ubuntu-22.04
16+
steps:
17+
- uses: actions/checkout@v3
18+
- uses: ./.github/actions/ci
19+
with:
20+
cmake_target: launchdarkly-cpp-common

.github/workflows/lint-pr-title.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: Lint PR title
2+
3+
on:
4+
pull_request_target:
5+
types:
6+
- opened
7+
- edited
8+
- synchronize
9+
10+
jobs:
11+
main:
12+
name: Verify the PR title matches conventional commit spec.
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: amannn/action-semantic-pull-request@v5
16+
env:
17+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/sse.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: libs/server-sent-events
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths-ignore:
7+
- '**.md' #Do not need to run CI for markdown changes.
8+
pull_request:
9+
branches: [main]
10+
paths-ignore:
11+
- '**.md'
12+
13+
jobs:
14+
build-test-common:
15+
runs-on: ubuntu-22.04
16+
steps:
17+
- uses: actions/checkout@v3
18+
- uses: ./.github/actions/ci
19+
with:
20+
cmake_target: launchdarkly-sse-client

libs/client-sdk/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,7 @@ include(FetchContent)
2929

3030
# Add main SDK sources.
3131
add_subdirectory(src)
32+
33+
if(BUILD_TESTING)
34+
add_subdirectory(tests)
35+
endif()

libs/client-sdk/tests/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
include(GoogleTest)
3+
4+
include_directories("${PROJECT_SOURCE_DIR}/include")
5+
6+
file(GLOB tests "${PROJECT_SOURCE_DIR}/tests/*.cpp")
7+
8+
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
9+
10+
add_executable(gtest_${LIBNAME}
11+
${tests})
12+
target_link_libraries(gtest_${LIBNAME} launchdarkly::client GTest::gtest_main)
13+
14+
gtest_discover_tests(gtest_${LIBNAME})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <gtest/gtest.h>
2+
3+
// Demonstrate some basic assertions.
4+
TEST(HelloTest, BasicAssertions) {
5+
// Expect two strings not to be equal.
6+
EXPECT_STRNE("hello", "world");
7+
// Expect equality.
8+
EXPECT_EQ(7 * 6, 42);
9+
}

libs/common/tests/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ include_directories("${PROJECT_SOURCE_DIR}/include")
55

66
file(GLOB tests "${PROJECT_SOURCE_DIR}/tests/*.cpp")
77

8-
add_executable("google_tests_common"
8+
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
9+
10+
add_executable(gtest_${LIBNAME}
911
${tests})
10-
target_link_libraries(google_tests_common launchdarkly::common GTest::gtest_main)
12+
target_link_libraries(gtest_${LIBNAME} launchdarkly::common GTest::gtest_main)
1113

12-
gtest_discover_tests(google_tests_common)
14+
gtest_discover_tests(gtest_${LIBNAME})

libs/server-sent-events/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,7 @@ message(STATUS "LaunchDarkly: using Boost v${Boost_VERSION}")
4242

4343

4444
add_subdirectory(src)
45+
46+
if (BUILD_TESTING)
47+
add_subdirectory(tests)
48+
endif ()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
cmake_minimum_required(VERSION 3.10)
2+
include(GoogleTest)
3+
4+
include_directories("${PROJECT_SOURCE_DIR}/include")
5+
6+
file(GLOB tests "${PROJECT_SOURCE_DIR}/tests/*.cpp")
7+
8+
set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
9+
10+
add_executable(gtest_${LIBNAME}
11+
${tests})
12+
target_link_libraries(gtest_${LIBNAME} launchdarkly::sse GTest::gtest_main)
13+
14+
gtest_discover_tests(gtest_${LIBNAME})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#include <gtest/gtest.h>
2+
3+
// Demonstrate some basic assertions.
4+
TEST(HelloTest, BasicAssertions) {
5+
// Expect two strings not to be equal.
6+
EXPECT_STRNE("hello", "world");
7+
// Expect equality.
8+
EXPECT_EQ(7 * 6, 42);
9+
}

scripts/build.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash -e
2+
3+
# This script builds a specific cmake target.
4+
# This script should be ran from the root directory of the project.
5+
# ./scripts/build.sh my-build-target ON
6+
#
7+
# $1 the name of the target. For example "launchdarkly-cpp-common".
8+
# $2 ON/OFF which enables/disables building in a test configuration.
9+
10+
function cleanup {
11+
cd ..
12+
}
13+
14+
mkdir -p build
15+
cd build
16+
# After we enter the directory we want to make sure we always exit it when the
17+
# script ends.
18+
trap cleanup EXIT
19+
20+
cmake -D BUILD_TESTING="$2" ..
21+
22+
cmake --build . --target "$1"

scripts/clean.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash -e
2+
3+
function cleanup {
4+
cd ..
5+
}
6+
7+
cd build
8+
# After we enter the directory we want to make sure we always exit it when the
9+
# script ends.
10+
trap cleanup EXIT
11+
12+
cmake --build . --target clean

0 commit comments

Comments
 (0)