Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/setup ci #5

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ Checks:
boost-*,
bugprone-*,
cert-*,
-cert-env33-c,
-cert-err58-cpp,
clang-analyzer-*,
cppcoreguidelines-*,
-cppcoreguidelines-avoid-*,
Expand All @@ -22,6 +20,7 @@ Checks:
-hicpp-signed-bitwise,
-hicpp-vararg,
misc-*,
google-*,
-misc-non-private-member-variables-in-classes,
modernize-*,
-modernize-macro-to-enum,
Expand All @@ -34,11 +33,12 @@ Checks:
-readability-identifier-length,
-*avoid-c-arrays,
-*magic-numbers,
-bugprone-narrowing-conversions,-cppcoreguidelines-narrowing-conversions
'

HeaderFilterRegex:
'.*'

#TODO: this is not realy pedantic! CK
#TODO: this isn't realy pedantic today! CK
WarningsAsErrors:
'clang-diagnostic-error'
'*'
62 changes: 42 additions & 20 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
name: CMake

on:
push:
branches: ["develop"]
pull_request:
branches: ["develop"]
merge_group:
push:
branches:
- 'master'
- 'releases/**'

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Debug
# XXX BUILD_TYPE: Debug
CTEST_OUTPUT_ON_FAILURE: 1
CMAKE_EXPORT_COMPILE_COMMANDS: 1
CCACHE_DIR: ${{ github.workspace }}/.ccache
CPM_SOURCE_CACHE: ${{ github.workspace }}/cpm_modules

jobs:
Expand All @@ -20,6 +24,7 @@ jobs:

matrix:
os: [macos, ubuntu]
BUILD_TYPE: [Debug, Release]

runs-on: ${{ matrix.os }}-latest

Expand All @@ -28,46 +33,63 @@ jobs:

- uses: actions/cache@v3
with:
path: "**/cpm_modules"
path: |
"**/.ccache"
"**/cpm_modules"
key: ${{ github.workflow }}-cpm-modules-${{ hashFiles('**/CMakeLists.txt', '**/*.cmake') }}

# - uses: actions/setup-python@v4
# with:
# python-version: '3.11'
# cache: 'pip' # caching pip dependencies
# # pip but doesn't exist on disk: /home/runner/.cache/pip

- name: Setup python3
run: |
sudo python3 -m pip install --upgrade pip
sudo python3 -m pip install -U -r requirements.txt
# /root/.cache/pip/

- name: Setup Cpp
if: startsWith(matrix.os, 'ubuntu')
uses: aminya/setup-cpp@v1
with:
cmake: true
ninja: true
gcovr: true
clangtidy: true
clangformat: true

- name: Install boost filesystem libs and python3 tftpy module on macos
- name: Install boost libs and ccache on macos
if: startsWith(matrix.os, 'macos')
shell: bash
run: |
sudo pip3 install tftpy gcovr
brew install boost ccache cmake ninja
brew install boost ccache

- name: Install boost tftpy module on ubuntu
- name: Install boost filesystem libs on ubuntu
if: startsWith(matrix.os, 'ubuntu')
shell: bash
run: |
sudo pip3 install tftpy
sudo apt-get install libboost-filesystem-dev ccache
sudo apt-get install libboost-filesystem-dev

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: cmake -G Ninja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
run: |
which cmake ninja
cmake --version
cmake --version
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rem duplicate line!

cmake -G Ninja -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{matrix.BUILD_TYPE}}

- name: Build
# Build your program with the given configuration
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
run: cmake --build ${{github.workspace}}/build --config ${{matrix.BUILD_TYPE}}

- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: sudo ctest -C ${{env.BUILD_TYPE}} --verbose
run: sudo ctest -C ${{matrix.BUILD_TYPE}}

- name: TestCoverage
if: startsWith(matrix.BUILD_TYPE, 'Debug')
run: gcovr -e option_test.cpp -e tftpd_test.cpp .

- name: Install
if: startsWith(matrix.BUILD_TYPE, 'Rel')
working-directory: ${{github.workspace}}/build
run: cpack -C ${{matrix.BUILD_TYPE}}
35 changes: 30 additions & 5 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,31 @@
# This specific template is located at:
# https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/ci/templates/Getting-Started.gitlab-ci.yml

# Configure pipeline workflow / execution accordingly:
# - Tag pipelines always.
# - Merge request pipelines when a merge request is open for the branch.
# - Branch pipelines when a merge request is not open for the branch.
# https://docs.gitlab.com/ee/ci/yaml/workflow.html#
# switch-between-branch-pipelines-and-merge-request-pipelines
---
workflow:
rules:
- if: $CI_COMMIT_TAG
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS
when: never
- if: $CI_COMMIT_BRANCH

variables:
PIP_INDEX_URL: "https://pypi.rsint.net/api/pypi/rs_pypi_virtual/simple"
# GIT_SUBMODULE_STRATEGY: normal
# GIT_SUBMODULE_DEPTH: 1
# Required CPU's for execution in Kubernetes cluster
KUBERNETES_CPU_LIMIT: 2
CICD_BUILD_ARCH: x86_64
CICD_USER: $SERVICE_USER
CICD_PASSWORD: $SERVICE_USER_API_KEY

default:
image: saas-linux-small-amd64
tags: [linux]
Expand All @@ -38,18 +63,18 @@ build-job: # This job runs in the build stage, which runs first.
extends:
- .standard-rules # Reuse the configuration in `.standard-rules` here
script:
- echo "Compiling the code..."
- cmake --preset default
- cmake --build --preset default
- echo "Compile complete."
- echo "Build Release workflow ..."
- cmake --workflow --preset Release --fresh
- echo "Build workflow complete."

unit-test-job: # This job runs in the test stage.
stage: test # It only starts when the job in the build stage completes successfully.
extends:
- .standard-rules # Reuse the configuration in `.standard-rules` here
script:
- echo "Running unit tests... This will take about a view seconds."
- cmake --build --preset default --target test
- cmake --preset Release --fresh
- cmake --build --preset Release --target test
- gcovr .

lint-test-job: # This job also runs in the test stage.
Expand Down
61 changes: 50 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ include(GNUInstallDirs)
# COMPONENTS filesystem asio headers
# REQUIRED
# )

# ---- Add other dependencies via CPM ----
# see https://github.com/cpm-cmake/CPM.cmake for more info

Expand Down Expand Up @@ -67,19 +66,54 @@ target_include_directories(
)

if(PROJECT_IS_TOP_LEVEL AND CMAKE_BUILD_TYPE STREQUAL "Debug")
# ProjectOptions will be used for compiler settings and appropriate CMake options
# NOTE(CK): Set GIT_SUBMODULES to empty string to NOT initializes submodules!
cmake_policy(SET CMP0097 NEW)
CPMAddPackage(
NAME ProjectOptions
GIT_TAG v0.32.1
GITHUB_REPOSITORY
aminya/project_options
GIT_SUBMODULES
"docs" # NOTE(CK): Workaround existing dir to prevent load of submodule
)
if(ProjectOptions_SOURCE_DIR)
message(DEBUG "${ProjectOptions_SOURCE_DIR} added")
list(APPEND CMAKE_MODULE_PATH ${ProjectOptions_SOURCE_DIR}/src)
endif()

# Enable sanitizers and static analyzers when running the tests
set(ENABLE_CLANG_TIDY NO)
if(DEFINED ENV{CI})
set(ENABLE_CLANG_TIDY "ENABLE_CLANG_TIDY")
set(ENABLE_SANITIZER_THREAD "ENABLE_SANITIZER_THREAD")
else()
check_sanitizers_support(
ENABLE_SANITIZER_ADDRESS ENABLE_SANITIZER_UNDEFINED_BEHAVIOR ENABLE_SANITIZER_LEAK
ENABLE_SANITIZER_THREAD ENABLE_SANITIZER_MEMORY
)
endif()

if(APPLE)
set(ENABLE_SANITIZER_LEAK NO)
endif()

project_options(
PREFIX
${PROJECT_NAME}
ENABLE_CACHE
ENABLE_COVERAGE
ENABLE_CLANG_TIDY
ENABLE_SANITIZER_ADDRESS
ENABLE_SANITIZER_UNDEFINED_BEHAVIOR
# ENABLE_SANITIZER_LEAK
# ENABLE_SANITIZER_THREAD
# ENABLE_SANITIZER_MEMORY
${ENABLE_CLANG_TIDY}
${ENABLE_SANITIZER_ADDRESS}
${ENABLE_SANITIZER_LEAK}
${ENABLE_SANITIZER_MEMORY}
${ENABLE_SANITIZER_THREAD}
${ENABLE_SANITIZER_UNDEFINED_BEHAVIOR}
ENABLE_CONTROL_FLOW_PROTECTION
ENABLE_STACK_PROTECTION
ENABLE_OVERFLOW_PROTECTION
ENABLE_INCLUDE_WHAT_YOU_USE
# XXX NO! WARNINGS_AS_ERRORS
# ENABLE_INCLUDE_WHAT_YOU_USE
)

target_link_libraries(
Expand All @@ -94,6 +128,9 @@ endif()
# Install and export tftpd-targets
#---------------------------------------------------------------------------------------
if(NOT CMAKE_SKIP_INSTALL_RULES)
# PackageProject.cmake will be used to make our target installable
CPMAddPackage("gh:TheLartians/[email protected]")

packageProject(
NAME ${PROJECT_NAME}
VERSION ${PROJECT_VERSION}
Expand Down Expand Up @@ -136,17 +173,19 @@ if(NETKIT_TFTP_TESTS)
enable_testing()

add_executable(option_test option_test.cpp async_tftpd_server.hpp)
#NO! CK target_include_directories(option_test SYSTEM PRIVATE include)
target_link_libraries(option_test PRIVATE tftpd)
add_test(NAME option_test COMMAND option_test)

if(NOT DEFINED ENV{CI})
add_test(NAME option_test COMMAND option_test)
endif()

add_executable(tftpd_test tftpd_test.cpp async_tftpd_server.hpp)
target_link_libraries(tftpd_test PRIVATE tftpd)

if(UNIX)
add_test(
NAME tftpd_test
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test.sh
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/test.sh $<TARGET_FILE:tftpd_test>
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
endif()
Expand Down
Loading
Loading