Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: CI

on:
push:
branches: [ main, develop, copilot/*, feature/* ]
pull_request:
branches: [ main, develop, feature/* ]

permissions:
contents: read

jobs:
build-and-test:
runs-on: ubuntu-latest
container:
image: chocotechnologies/dmod:1.0.2

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install dependencies
run: |
apt-get update
apt-get install -y lcov

- name: Configure CMake
run: |
mkdir -p build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DDMENV_BUILD_TESTS=ON

- name: Build
run: |
cd build
make -j$(nproc)

- name: Run tests
run: |
cd build
ctest --output-on-failure --verbose

- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: build/Testing/
retention-days: 30

coverage:
runs-on: ubuntu-latest
container:
image: chocotechnologies/dmod:1.0.2
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: recursive

- name: Install dependencies
run: |
apt-get update
apt-get install -y lcov

- name: Configure CMake with coverage
run: |
mkdir -p build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug -DENABLE_COVERAGE=ON -DDMENV_BUILD_TESTS=ON

- name: Build with coverage
run: |
cd build
make -j$(nproc)

- name: Run tests
run: |
cd build
ctest --output-on-failure

- name: Generate coverage report
run: |
cd build
lcov --directory . --capture --output-file coverage.info
lcov --remove coverage.info '/usr/*' '*/build/_deps/*' --output-file coverage_filtered.info --ignore-errors unused
lcov --list coverage_filtered.info

- name: Generate HTML coverage report
run: |
cd build
mkdir -p coverage_html
genhtml coverage_filtered.info --output-directory coverage_html

- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: build/coverage_html/
retention-days: 30

- name: Coverage summary
run: |
cd build
echo "## Coverage Summary" >> $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
lcov --summary coverage_filtered.info 2>&1 | tee -a $GITHUB_STEP_SUMMARY
echo "\`\`\`" >> $GITHUB_STEP_SUMMARY
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ compile_commands.json
CTestTestfile.cmake
_deps
CMakeUserPresets.json
build/
_codeql_build_dir/
_codeql_detected_source_root

# CLion
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
Expand Down
90 changes: 90 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# =====================================================================
# DMOD ENV CMake Configuration
# =====================================================================
cmake_minimum_required(VERSION 3.10)

# ======================================================================
# DMOD ENV
# ======================================================================
project(dmenv
VERSION 1.0
DESCRIPTION "DMOD Environment Variables Manager"
LANGUAGES C CXX)

set(DMENV_DONT_IMPLEMENT_DMOD_API OFF CACHE BOOL "Do not implement DMOD API in dmenv library")


# ======================================================================
# Fetch DMOD repository
# ======================================================================
include(FetchContent)

# Only fetch and build dmod if it's not already available as a target
if(NOT TARGET dmod_inc)
FetchContent_Declare(
dmod
GIT_REPOSITORY https://github.com/choco-technologies/dmod.git
GIT_TAG develop
)

# ======================================================================
# DMOD Configuration
# ======================================================================
set(DMOD_MODE "DMOD_SYSTEM" CACHE STRING "DMOD build mode")
set(DMOD_BUILD_TESTS OFF CACHE BOOL "Build tests")
set(DMOD_BUILD_EXAMPLES OFF CACHE BOOL "Build examples")
set(DMOD_BUILD_TOOLS OFF CACHE BOOL "Build tools")
set(DMOD_BUILD_TEMPLATES OFF CACHE BOOL "Build templates")

# Pass coverage flags to DMOD if enabled
if(ENABLE_COVERAGE)
set(DMOD_ENABLE_COVERAGE ON CACHE BOOL "Enable DMOD coverage")
endif()

FetchContent_MakeAvailable(dmod)
set(DMOD_DIR ${dmod_SOURCE_DIR} CACHE PATH "DMOD source directory" FORCE)
else()
message(STATUS "dmod target already exists, skipping FetchContent")
endif()

# ======================================================================
# DMOD ENV Library
# ======================================================================
set(MODULE_NAME dmenv)
add_library(${MODULE_NAME} STATIC
src/dmenv.c
)

target_compile_definitions(${MODULE_NAME}
PRIVATE
$<$<BOOL:${DMENV_DONT_IMPLEMENT_DMOD_API}>:DMENV_DONT_IMPLEMENT_DMOD_API>
DMENV_VERSION="${PROJECT_VERSION}"
)

target_include_directories(${MODULE_NAME}
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
)

target_link_libraries(${MODULE_NAME}
PRIVATE
dmod_inc
)

# Enable coverage for dmenv library if requested
if(ENABLE_COVERAGE)
target_compile_options(${MODULE_NAME} PRIVATE --coverage)
target_link_options(${MODULE_NAME} PRIVATE --coverage)
endif()

create_library_makefile(${MODULE_NAME})

# ======================================================================
# Tests
# ======================================================================
option(DMENV_BUILD_TESTS "Build tests" OFF)

if(DMENV_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif()
Loading