Skip to content

Commit

Permalink
chore: CI to test CPP SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaKasar committed Dec 3, 2024
1 parent 9ad3187 commit 72a5812
Show file tree
Hide file tree
Showing 5 changed files with 212 additions and 26 deletions.
144 changes: 123 additions & 21 deletions .github/workflows/cxx-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,31 @@ on:
- opened
- synchronize

defaults:
run:
shell: bash

env:
HUSKY: 0
jobs:
thunder:
name: Build Thunder Libraries
runs-on: ubuntu-latest
container:
image: kevinshahfws/node-c:3.0
image: node:23.3.0
steps:
- name: Checkout
- name: Checkout firebolt-apis
uses: actions/checkout@v2

- name: Clone and Install Thunder
id: install_thunder
run: |
apt update
apt install -y cmake ninja-build python3-pip python3.11-venv
python3 -m venv firebolt-env
source firebolt-env/bin/activate
pip install jsonref
.github/workflows/utils.sh cloneAndInstallThunder
- name: Upload the library artifact
uses: actions/upload-artifact@v3
with:
Expand All @@ -36,9 +44,12 @@ jobs:

openrpc:
name: Build Openrpc Artifacts
needs: thunder
runs-on: ubuntu-latest
container:
image: kevinshahfws/node-c:3.0
image: node:23.3.0
permissions:
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -62,7 +73,7 @@ jobs:
key: deps-node-modules-${{ hashFiles('package-lock.json') }}

- name: Install dependencies
run: npm ci
run: npm install

- name: Set file permissions
run: |
Expand All @@ -84,19 +95,19 @@ jobs:
with:
name: manage
path: src/sdks/manage

- name: Upload Discovery SDK
uses: actions/upload-artifact@v3
with:
name: discovery
path: src/sdks/discovery
path: src/sdks/discovery

core_sdk:
name: Build Core SDK
needs: [thunder, openrpc]
runs-on: ubuntu-latest
container:
image: kevinshahfws/node-c:3.0
image: node:23.3.0
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -107,7 +118,6 @@ jobs:
name: core
path: /__w/firebolt-apis/firebolt-apis/src/sdks/core


- name: Download Thunder
uses: actions/download-artifact@v3
with:
Expand All @@ -121,27 +131,58 @@ jobs:
key: deps-node-modules-${{ hashFiles('package-lock.json') }}

- name: Install npm dependencies
run: npm ci
run: |
apt update
apt install -y cmake
npm install
- name: Generate core SDK source code
run: |
.github/workflows/utils.sh generate_cpp_core_sdk_source_code
- name: Build CXX Core SDK
- name: Build CXX Core SDK
run: |
apt install -y python3-pip python3.11-venv
python3 -m venv firebolt-env
source firebolt-env/bin/activate
pip install gcovr
.github/workflows/utils.sh build_core_cpp_sdk
- name: Test and Generate coverage report
run: .github/workflows/utils.sh generate_core_sdk_coverage_report

- name: Display coverage report
uses: irongut/[email protected]
with:
filename: coverage/coverage.cobertura.xml
badge: true
fail_below_min: true
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: '80 40'

- name: Add coverage PR comment
uses: marocchino/sticky-pull-request-comment@v2
with:
recreate: true
path: code-coverage-results.md


manage_sdk:
name: Build Manage SDK
needs: [thunder, openrpc]
runs-on: ubuntu-latest
container:
image: kevinshahfws/node-c:3.0
image: node:23.3.0
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Download Manage SDK
- name: Download Manage SDK
uses: actions/download-artifact@v3
with:
name: manage
Expand All @@ -160,22 +201,52 @@ jobs:
key: deps-node-modules-${{ hashFiles('package-lock.json') }}

- name: Install npm dependencies
run: npm ci
run: |
apt update
apt install -y cmake
npm install
- name: Generate manage SDK source code
run: |
.github/workflows/utils.sh generate_cpp_manage_sdk_source_code
- name: Build CXX manage SDK
- name: Build CXX Manage SDK
run: |
apt install -y python3-pip python3.11-venv
python3 -m venv firebolt-env
source firebolt-env/bin/activate
pip install gcovr
.github/workflows/utils.sh build_manage_cpp_sdk
dicovery_sdk:
- name: Test and Generate coverage report
run: .github/workflows/utils.sh generate_manage_sdk_coverage_report

- name: Display coverage report
uses: irongut/[email protected]
with:
filename: coverage/coverage.cobertura.xml
badge: true
fail_below_min: true
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: '80 40'

- name: Add coverage PR comment
uses: marocchino/sticky-pull-request-comment@v2
with:
recreate: true
path: code-coverage-results.md

discovery_sdk:
name: Build Discovery SDK
needs: [thunder, openrpc]
runs-on: ubuntu-latest
container:
image: kevinshahfws/node-c:3.0
image: node:23.3.0
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -199,12 +270,43 @@ jobs:
key: deps-node-modules-${{ hashFiles('package-lock.json') }}

- name: Install npm dependencies
run: npm ci
run: |
apt update
apt install -y cmake
npm install
- name: Generate discovery SDK source code
run: |
.github/workflows/utils.sh generate_cpp_discovery_sdk_source_code
- name: Build CXX Discovery SDK
- name: Build CXX Discovery SDK
run: |
.github/workflows/utils.sh build_discovery_cpp_sdk
apt install -y python3-pip python3.11-venv
python3 -m venv firebolt-env
source firebolt-env/bin/activate
pip install gcovr
.github/workflows/utils.sh build_discovery_cpp_sdk
- name: Test and Generate coverage report
run: .github/workflows/utils.sh generate_discovery_sdk_coverage_report

- name: Display coverage report
uses: irongut/[email protected]
with:
filename: coverage/coverage.cobertura.xml
badge: true
fail_below_min: true
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: '80 40'

- name: Add coverage PR comment
uses: marocchino/sticky-pull-request-comment@v2
with:
recreate: true
path: code-coverage-results.md

22 changes: 21 additions & 1 deletion .github/workflows/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ function unzipArtifact(){
}

function cloneAndInstallThunder() {
printenv

cd ..

git clone https://github.com/rdkcentral/Thunder.git
Expand Down Expand Up @@ -269,12 +271,27 @@ function build_cpp_sdk() {

echo " ************ Build ${sdk_name^} CPP SDK ************"

cd /__w/firebolt-apis/firebolt-apis/src/sdks/${sdk_name}/build/cpp/src/firebolt-${sdk_name}-native-sdk-${FIREBOLT_VERSION}/
tar -xvf /__w/firebolt-apis/firebolt-apis/src/sdks/${sdk_name}/build/cpp/src/firebolt-${sdk_name}-native-sdk-${FIREBOLT_VERSION}.tgz -C /__w/firebolt-apis/firebolt-apis/
cd /__w/firebolt-apis/firebolt-apis/firebolt-${sdk_name}-native-sdk-${FIREBOLT_VERSION}
chmod +x ./build.sh

./build.sh -s "/__w/thunder/install/" || exit 9999
}


function generate_coverage_report(){
FIREBOLT_VERSION=$(node -p "require('./package.json').version")
echo "The version from package.json is $FIREBOLT_VERSION"
local sdk_name=$1

echo " ************ Generate coverage report for ${sdk_name^} CPP SDK ************"

cd /__w/firebolt-apis/firebolt-apis/firebolt-${sdk_name}-native-sdk-${FIREBOLT_VERSION}
cmake --build build --target coverage

mv /__w/firebolt-apis/firebolt-apis/firebolt-${sdk_name}-native-sdk-${FIREBOLT_VERSION}/build/test/coverage /__w/firebolt-apis/firebolt-apis/
}

# Check argument and call corresponding function
case "$1" in
runTests) runTests ;;
Expand All @@ -288,6 +305,9 @@ case "$1" in
build_core_cpp_sdk) build_cpp_sdk "core" ;;
build_manage_cpp_sdk) build_cpp_sdk "manage" ;;
build_discovery_cpp_sdk) build_cpp_sdk "discovery" ;;
generate_core_sdk_coverage_report) generate_coverage_report "core" ;;
generate_manage_sdk_coverage_report) generate_coverage_report "manage" ;;
generate_discovery_sdk_coverage_report) generate_coverage_report "discovery" ;;
*)
echo "Invalid function specified."
exit 1
Expand Down
29 changes: 29 additions & 0 deletions src/sdks/core/src/cpp/sdk/cpptest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,35 @@ if(ENABLE_UNIT_TESTS)
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include/>
)

set_target_properties(${UNIT_TESTS_APP} PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED YES
)

include(GoogleTest)
gtest_discover_tests(${UNIT_TESTS_APP})
endif()

if(ENABLE_COVERAGE)
include(${CMAKE_SOURCE_DIR}/cmake/CodeCoverage.cmake)

set(COVERAGE_MAIN "coverage")
set(COVERAGE_EXCLUDES
"${CMAKE_SOURCE_DIR}/build/*"
"${CMAKE_SOURCE_DIR}/cmake/*"
"${CMAKE_SOURCE_DIR}/include/*"
"${CMAKE_SOURCE_DIR}/test/*"
"/usr/include/*")

set(COVERAGE_EXTRA_FLAGS)
set(COVERAGE_DEPENDENCIES ${UNIT_TESTS_APP})

setup_target_for_coverage_gcovr_html(
NAME ${COVERAGE_MAIN}
BASE_DIRECTORY ${CMAKE_SOURCE_DIR}
EXECUTABLE ctest
EXECUTABLE_ARGS "--test-dir ../build/ --output-on-failure"
DEPENDENCIES ${COVERAGE_DEPENDENCIES}
)

endif()
12 changes: 9 additions & 3 deletions src/sdks/discovery/src/cpp/sdk/cpptest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,21 @@ target_link_libraries(${TESTAPP}
PRIVATE
${NAMESPACE}Core::${NAMESPACE}Core
${FIREBOLT_NAMESPACE}SDK::${FIREBOLT_NAMESPACE}SDK
nlohmann_json_schema_validator
gtest_main
)

target_include_directories(${TESTAPP}
PRIVATE
$<BUILD_INTERFACE:${FIREBOLT_PATH}/usr/include/${FIREBOLT_NAMESPACE}SDK>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SRC_DIR}/>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SRC_DIR}/../>
$<BUILD_INTERFACE:${CMAKE_SOURCE_DIR}/include/>
)

if (POLYMORPHICS_REDUCER_METHODS)
target_compile_definitions(${TESTAPP}
PUBLIC
POLYMORPHICS_REDUCER_METHODS=1)
endif()

set_target_properties(${TESTAPP} PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED YES
Expand Down
Loading

0 comments on commit 72a5812

Please sign in to comment.