Skip to content

Commit

Permalink
Workflow test
Browse files Browse the repository at this point in the history
  • Loading branch information
nawaz1991 committed Dec 4, 2023
1 parent 4f7791f commit fd905c4
Show file tree
Hide file tree
Showing 14 changed files with 258 additions and 26 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#name: build and test
#on: [push, workflow_dispatch]
#
#jobs:
# job:
# name: ${{ matrix.os }}-${{ github.workflow }}
# runs-on: ${{ matrix.os }}
# strategy:
# fail-fast: false
# matrix:
# os: [ubuntu-latest, macos-latest, windows-latest]
#
# steps:
# - name: Checkout cpp-oasvalidator
# uses: actions/checkout@v4
# with:
# submodules: true
# fetch-depth: 0
#
# - uses: lukka/get-cmake@latest
#
# - name: Run CMake Ninja build all release preset including example, unittests, perftests
# uses: lukka/run-cmake@v10
# id: runcmake
# with:
# workflowPreset: 'release-all'
52 changes: 52 additions & 0 deletions .github/workflows/common-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Common Build and Test Steps
on:
workflow_call:
inputs:
os:
required: true
type: string

jobs:
build:
runs-on: ${{ inputs.os }}
steps:
- name: Checkout cpp-oasvalidator
uses: actions/checkout@v4
with:
submodules: true
fetch-depth: 0

- uses: lukka/get-cmake@latest

- name: Run CMake Ninja build all release preset including example, unittests, perftests
uses: lukka/run-cmake@v10
id: runcmake
with:
workflowPreset: 'build-test-and-example'

- name: Run Example
run: |
if [ "${{ runner.os }}" = "Windows" ]; then
build/release/example/oasvalidator-example.exe
else
build/release/example/oasvalidator-example
fi
shell: bash

- name: Run Unit Tests
run: |
if [ "${{ runner.os }}" = "Windows" ]; then
build/release/test/unittest/oasvalidator-unittests.exe
else
build/release/test/unittest/oasvalidator-unittests
fi
shell: bash

- name: Run Performance Tests
run: |
if [ "${{ runner.os }}" = "Windows" ]; then
build/release/test/perftest/oasvalidator-perftests.exe
else
build/release/test/perftest/oasvalidator-perftests
fi
shell: bash
8 changes: 8 additions & 0 deletions .github/workflows/linux-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Ubuntu Build and Test
on: [push, workflow_dispatch]

jobs:
linux-build-and-test:
uses: ./.github/workflows/common-build.yml
with:
os: ubuntu-latest
8 changes: 8 additions & 0 deletions .github/workflows/mac-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Mac Build and Test
on: [push, workflow_dispatch]

jobs:
macos-build-and-test:
uses: ./.github/workflows/common-build.yml
with:
os: macos-latest
2 changes: 1 addition & 1 deletion .github/workflows/win_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
push:
branches:
- main
- '**'
#- '**'
pull_request:
branches: [ main ]

Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/windows-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Windows Build and Test
on: [push, workflow_dispatch]

jobs:
windows-build-and-test:
uses: ./.github/workflows/common-build.yml
with:
os: windows-latest
29 changes: 15 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ set(OASVALIDATOR_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(OASVALIDATOR_README "${CMAKE_CURRENT_SOURCE_DIR}/README.md")
message(STATUS "Building oasvalidator version ${OASVALIDATOR_VERSION_STRING}")

project(oasvalidator LANGUAGES CXX
project(cpp-oasvalidator LANGUAGES CXX
VERSION "${OASVALIDATOR_VERSION_STRING}"
DESCRIPTION "A FAST C++ library to validate the HTTP requests against the OpenAPI specifications of the REST server")

set(OASVALIDATOR oasvalidator)

# Default to release build type with specific optimization flags
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE)
Expand All @@ -49,8 +51,6 @@ elseif (OASVALIDATOR_BUILD_CXX17)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
endif()

message(STATUS "EXTRA_CXX_FLAGS: ${EXTRA_CXX_FLAGS}")

find_program(CCACHE_FOUND ccache)
if (CCACHE_FOUND)
message(STATUS "Using ccache")
Expand Down Expand Up @@ -137,10 +137,10 @@ endif()
#add extra search paths for libraries and includes
SET(INCLUDE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "The directory the headers are installed in")
SET(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE STRING "Directory where lib will install")
SET(DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/doc/${PROJECT_NAME}" CACHE PATH "Path to the documentation")
SET(DOC_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/share/doc/${OASVALIDATOR}" CACHE PATH "Path to the documentation")

if (UNIX OR CYGWIN)
SET(_CMAKE_INSTALL_DIR "${LIB_INSTALL_DIR}/cmake/${PROJECT_NAME}")
SET(_CMAKE_INSTALL_DIR "${LIB_INSTALL_DIR}/cmake/${OASVALIDATOR}")
elseif (WIN32)
SET(_CMAKE_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/cmake")
endif ()
Expand All @@ -161,21 +161,21 @@ endif ()

set(OAS_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")

target_include_directories(${PROJECT_NAME}
target_include_directories(${OASVALIDATOR}
PRIVATE
${RAPIDJSON_INCLUDE_DIRS}
${OAS_INCLUDE_DIR}
)

set_target_properties(${PROJECT_NAME} PROPERTIES
set_target_properties(${OASVALIDATOR} PROPERTIES
SOVERSION "${OASVALIDATOR_VERSION_STRING}"
VERSION "${OASVALIDATOR_VERSION_STRING}"
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
)

############################# Installation #############################
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}-targets
install(TARGETS ${OASVALIDATOR}
EXPORT ${OASVALIDATOR}-targets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
)
Expand All @@ -191,22 +191,23 @@ install(FILES LICENSE

############################# Subprojects #############################
# Export package for use from the build tree
EXPORT(PACKAGE ${PROJECT_NAME})
EXPORT(PACKAGE ${OASVALIDATOR})
if (BUILD_COVERAGE)
set(PROJECT_TEST_NAME ${PROJECT_NAME}-unittests)
set(PROJECT_TEST_NAME ${OASVALIDATOR}-unittests)
include(cmake/CodeCoverage.cmake)
enable_testing()
append_coverage_compiler_flags()
setup_target_for_coverage_gcovr_html(
NAME covhtml-${PROJECT_NAME}
EXECUTABLE ${PROJECT_NAME}-unittests
NAME covhtml-${OASVALIDATOR}
EXECUTABLE ${OASVALIDATOR}-unittests
BASE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
EXCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/rapidjson/*
EXCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/*
)
endif ()

if (BUILD_TESTS OR BUILD_COVERAGE)
add_subdirectory(test/unittest)
include(CTest)
endif ()

if(BUILD_PERF)
Expand Down
129 changes: 129 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
{
"version": 6,
"configurePresets": [
{
"name": "debug",
"displayName": "Debug configuration for code coverage and docs",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"BUILD_COVERAGE": "ON",
"BUILD_DOCS": "ON",
"CMAKE_BUILD_TYPE": "Debug"
}
},
{
"name": "release",
"displayName": "Release configuration for oasvalidator, tests and example",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"BUILD_SHARED_LIB": "OFF",
"BUILD_TESTS": "ON",
"BUILD_PERF": "ON",
"BUILD_EXAMPLE": "ON",
"CMAKE_BUILD_TYPE": "Release"
}
}
],
"buildPresets": [
{
"name": "oasvalidator-build",
"displayName": "Build oasvalidator Release",
"configurePreset": "release",
"targets": [
"oasvalidator"
]
},
{
"name": "tests-build",
"displayName": "Build oasvalidator tests Release",
"configurePreset": "release",
"targets": [
"oasvalidator-unittests",
"oasvalidator-perftests"
]
},
{
"name": "example-build",
"displayName": "Build oasvalidator example",
"configurePreset": "release",
"targets": [
"oasvalidator-example"
]
},
{
"name": "docs-build",
"displayName": "Build oasvalidator docs",
"configurePreset": "debug",
"targets": [
"docs"
]
},
{
"name": "codecov-build",
"displayName": "Build oasvalidator codecov",
"configurePreset": "debug",
"targets": [
"covhtml-oasvalidator"
]
}
],
"testPresets": [
{
"name": "test-oasvalidator",
"displayName": "Test oasvalidator",
"configurePreset": "release",
"output": {
"shortProgress": true,
"verbosity": "extra"
},
"execution": {
"noTestsAction": "error",
"testMode": "exclusive"
}
}
],
"workflowPresets": [
{
"name": "build-docs-and-codecov",
"displayName": "Build oasvalidator, docs and code coverage in Debug mode",
"steps": [
{
"type": "configure",
"name": "debug"
},
{
"type": "build",
"name": "docs-build"
},
{
"type": "build",
"name": "codecov-build"
}
]
},
{
"name": "build-test-and-example",
"displayName": "Build oasvalidator, unittest, perftests and example in Release mode",
"steps": [
{
"type": "configure",
"name": "release"
},
{
"type": "build",
"name": "oasvalidator-build"
},
{
"type": "build",
"name": "example-build"
},
{
"type": "build",
"name": "tests-build"
}
]
}
]
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ To run the example, follow the steps below:
2. Run the following commands:
```bash
cmake -S . -B build -DBUILD_EXAMPLE=ON
cmake --build build --target example -j $(nproc)
build/example/example
cmake --build build --target oasvalidator-example -j $(nproc)
build/example/oasvalidator-example
```

### 5.1.7 Generating API Documentation
Expand Down
2 changes: 2 additions & 0 deletions docs/classdiagram.puml.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@startuml
skinparam linetype ortho
skinparam backgroundColor transparent


' Classes
class ArrayDeserializer {
Expand Down
2 changes: 1 addition & 1 deletion docs/classdiagram.rst.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
Class Diagram
--------------------

.. uml:: classdiagram.puml
.. plantuml:: classdiagram.puml
6 changes: 3 additions & 3 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)

# Project description
project(oasvalidator-example LANGUAGES CXX)
project(${OASVALIDATOR}-example LANGUAGES CXX)

include_directories(${OAS_INCLUDE_DIR})

# Create the executable
add_executable(example example.cpp)
add_executable(${PROJECT_NAME} example.cpp)

# Link the executable with the library
target_link_libraries(example oasvalidator)
target_link_libraries(${PROJECT_NAME} oasvalidator)

set(SPEC_FILE_ABSOLUTE_PATH "${CMAKE_SOURCE_DIR}/data/openAPI_example.json")
add_definitions(-DSPEC_PATH="${SPEC_FILE_ABSOLUTE_PATH}")
2 changes: 1 addition & 1 deletion test/perftest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project(${PROJECT_NAME}-perftests LANGUAGES CXX)
project(${OASVALIDATOR}-perftests LANGUAGES CXX)

file(GLOB_RECURSE SOURCES "src/*.cpp")
include_directories(${CMAKE_SOURCE_DIR}/include)
Expand Down
Loading

0 comments on commit fd905c4

Please sign in to comment.