Skip to content

Commit

Permalink
Add GitHub Actions CI/CD Run for liblog (#16)
Browse files Browse the repository at this point in the history
* Added github actions workflow and tests folder

Signed-off-by: Christoph <[email protected]>

* Fixed lint issue in examples

Signed-off-by: Christoph <[email protected]>

* Fixed test include issue

Signed-off-by: Christoph <[email protected]>

* Removed unused cmake link in tests

Signed-off-by: Christoph <[email protected]>

* Cleaned up on calls for build and test

Signed-off-by: Christoph <[email protected]>

* Trying to fix CI run on PR

Signed-off-by: Christoph <[email protected]>

* Updating install and test ci script as per PR review change request

Signed-off-by: Christoph <[email protected]>

* Rolled back unrelated update to test trace example

Signed-off-by: Christoph <[email protected]>

* Rolled back unrelated update to test trace example

Signed-off-by: Christoph <[email protected]>

* Updated test names to follow EVerest conventions

Signed-off-by: Christoph <[email protected]>

* Update tests/liblog_test.cpp

Co-authored-by: Andreas Heinrich <[email protected]>
Signed-off-by: Christoph <[email protected]>

* Update .github/workflows/build_and_test.yaml

Co-authored-by: Andreas Heinrich <[email protected]>
Signed-off-by: Christoph <[email protected]>

* Update .github/workflows/build_and_test.yaml

Co-authored-by: Andreas Heinrich <[email protected]>
Signed-off-by: Christoph <[email protected]>

---------

Signed-off-by: Christoph <[email protected]>
Co-authored-by: Andreas Heinrich <[email protected]>
  • Loading branch information
folkengine and andistorm authored Mar 27, 2024
1 parent 19dce0e commit 6e80d58
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 1 deletion.
15 changes: 15 additions & 0 deletions .ci/build-kit/install_and_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

set -e

cmake \
-B build \
-S "$EXT_MOUNT/source" \
-G Ninja \
-DBUILD_TESTING=ON \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_INSTALL_PREFIX="$WORKSPACE_PATH/dist"

ninja -j$(nproc) -C build install

ninja -j$(nproc) -C build test
61 changes: 61 additions & 0 deletions .github/workflows/build_and_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Please reference work here https://github.com/EVerest/everest-core/tree/main/.github/workflows
# TODO: modify to reuse the above workflow to DRY up CI.

name: Build and test liblog
on:
push:
pull_request:
workflow_dispatch:
inputs:
runner:
description: Which runner to use
type: choice
default: 'ubuntu-22.04'
required: true
options:
- 'ubuntu-22.04'
- 'large-ubuntu-22.04-xxl'
jobs:
lint:
name: Lint
runs-on: ${{ inputs.runner || 'ubuntu-22.04' }}
steps:
- name: Checkout liblog
uses: actions/checkout@v3
with:
path: source
- name: Run clang-format
uses: everest/everest-ci/github-actions/[email protected]
with:
source-dir: source
extensions: hpp,cpp
exclude: cache
install_and_test:
name: Install and test
runs-on: ${{ inputs.runner || 'ubuntu-22.04' }}
steps:
- name: Checkout liblog
uses: actions/checkout@v3
with:
path: source
- name: Setup run scripts
run: |
mkdir scripts
rsync -a source/.ci/build-kit/ scripts
- name: Pull docker container
run: |
docker pull --platform=linux/x86_64 --quiet ghcr.io/everest/build-kit-alpine:latest
docker image tag ghcr.io/everest/build-kit-alpine:latest build-kit
- name: Run install with tests
run: |
docker run \
--volume "$(pwd):/ext" \
--name test-container \
build-kit run-script install_and_test
- name: Archive test results
if: always()
uses: actions/upload-artifact@v3
with:
name: ctest-report
path: /workspace/build/tests/Testing/Temporary/LastTest.log

5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ find_package(everest-cmake 0.1 REQUIRED

# options
option(BUILD_BACKTRACE_SUPPORT "Build with backtrace support from libbacktrace" OFF)
option(${PROJECT_NAME}_BUILD_TESTING "Build unit tests, used if included as dependency" OFF)
option(BUILD_TESTING "Run unit tests" OFF)
option(BUILD_EXAMPLES "Build liblog example binaries." OFF)
option(LOG_INSTALL "Install the library (shared data might be installed anyway)" ${EVC_MAIN_PROJECT})
Expand Down Expand Up @@ -67,8 +68,10 @@ endif()


# testing
if(BUILD_TESTING)
if((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME} OR ${PROJECT_NAME}_BUILD_TESTING) AND BUILD_TESTING)
include(CTest)
add_subdirectory(tests)

set(CMAKE_BUILD_TYPE Debug CACHE STRING "Build type" FORCE)

evc_include(CodeCoverage)
Expand Down
17 changes: 17 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
find_package(GTest REQUIRED)

set(TEST_TARGET_NAME ${PROJECT_NAME}_tests)
add_executable(${TEST_TARGET_NAME} liblog_test.cpp)

target_include_directories(${TEST_TARGET_NAME} PUBLIC ${GTEST_INCLUDE_DIRS})
target_include_directories(log
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/lib>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
target_link_libraries(${TEST_TARGET_NAME} PRIVATE
${GTEST_LIBRARIES}
${GTEST_MAIN_LIBRARIES}
)

gtest_discover_tests(${TEST_TARGET_NAME})
22 changes: 22 additions & 0 deletions tests/liblog_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2020 - 2023 Pionix GmbH and Contributors to EVerest
#include <gtest/gtest.h>

namespace Everest {
namespace Logging {

class LibLogUnitTest : public ::testing::Test {
protected:
void SetUp() override {
}

void TearDown() override {
}
};

TEST(LibLogUnitTest, test_truth) {
ASSERT_TRUE(1 == 1);
}

} // namespace Logging
} // namespace Everest

0 comments on commit 6e80d58

Please sign in to comment.