From ea28752d368c447922eb46ed52c3c73d0d111af3 Mon Sep 17 00:00:00 2001 From: Master92 Date: Wed, 30 Aug 2023 07:47:21 +0200 Subject: [PATCH 1/9] Remove comments from build script --- .github/workflows/build.yaml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 1ee97ab..bd1500f 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,6 +1,5 @@ name: CI -# Controls when the workflow will run on: # Triggers the workflow on push or pull request events but only for the "master" branch push: @@ -15,16 +14,13 @@ on: # Allows you to run this workflow manually from the Actions tab workflow_dispatch: -# A workflow run is made up of one or more jobs that can run sequentially or in parallel jobs: - # This workflow contains a single job called "build" build: # The type of runner that the job will run on runs-on: ubuntu-latest # Steps represent a sequence of tasks that will be executed as part of the job steps: - # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it - uses: actions/checkout@v3 # Runs a single command using the runners shell From cfe10096224c69054aa46f26ec26fc12b54caa30 Mon Sep 17 00:00:00 2001 From: Master92 Date: Wed, 30 Aug 2023 07:49:26 +0200 Subject: [PATCH 2/9] Use managed action for installing Conan --- .github/workflows/build.yaml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index bd1500f..226922f 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -23,20 +23,23 @@ jobs: steps: - uses: actions/checkout@v3 - # Runs a single command using the runners shell - - name: Get conan - run: | - python -m pip install conan - conan profile detect + - name: Get Conan + uses: turtlebrowser/get-conan@v1.2 + + - name: Create default Conan profile + run: conan profile detect + - name: Get dependencies run: | mkdir build cd build conan install .. --build=missing + - name: Build project run: | cd build cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON --toolchain=conan_toolchain.cmake cmake --build . --target all + - name: Run test suite run: build/tests/cppIni_tests From 51b67ebc73cfe05a43bc825546d51e5c1f4aeb06 Mon Sep 17 00:00:00 2001 From: Master92 Date: Wed, 30 Aug 2023 07:51:59 +0200 Subject: [PATCH 3/9] Run build jobs on different platforms and compilers --- .github/workflows/build.yaml | 62 +++++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 11 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 226922f..03701cf 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -16,13 +16,49 @@ on: jobs: build: - # The type of runner that the job will run on - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + + strategy: + # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. + fail-fast: false + + # Set up a matrix to run the following 3 configurations: + # 1. + # 2. + # 3. + # + # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. + matrix: + os: [ ubuntu-latest, windows-latest ] + build_type: [ Release ] + c_compiler: [ gcc, clang, cl ] + include: + - os: windows-latest + c_compiler: cl + cpp_compiler: cl + - os: ubuntu-latest + c_compiler: gcc + cpp_compiler: g++ + - os: ubuntu-latest + c_compiler: clang + cpp_compiler: clang++ + exclude: + - os: windows-latest + c_compiler: gcc + - os: windows-latest + c_compiler: clang + - os: ubuntu-latest + c_compiler: cl - # Steps represent a sequence of tasks that will be executed as part of the job steps: - uses: actions/checkout@v3 + - name: Set reusable strings + # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. + id: strings + shell: bash + run: echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + - name: Get Conan uses: turtlebrowser/get-conan@v1.2 @@ -30,16 +66,20 @@ jobs: run: conan profile detect - name: Get dependencies - run: | - mkdir build - cd build - conan install .. --build=missing + run: conan install ${{ github.workspace }} --build=missing --output-folder=build --settings compiler.cppstd=20 + + - name: Configure CMake + run: > + cmake -B ${{ steps.strings.outputs.build-output-dir }} + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} + -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} + -DBUILD_TESTING=ON + --toolchain=conan_toolchain.cmake + -S ${{ github.workspace }} - name: Build project - run: | - cd build - cmake .. -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON --toolchain=conan_toolchain.cmake - cmake --build . --target all + run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} --parallel - name: Run test suite run: build/tests/cppIni_tests From 9198d5f77a3dc43c37e4007bb70e4b33862bd9a1 Mon Sep 17 00:00:00 2001 From: Master92 Date: Tue, 29 Aug 2023 09:14:25 +0200 Subject: [PATCH 4/9] Rename ConstructionTest.cpp --- tests/CMakeLists.txt | 2 +- tests/{constructionTest.cpp => ConstructionTest.cpp} | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename tests/{constructionTest.cpp => ConstructionTest.cpp} (85%) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6c61cc8..93dec34 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -6,7 +6,7 @@ set(TEST_DRIVER_NAME TestDriver) find_package(doctest REQUIRED) -add_executable(${PROJECT_NAME}_tests constructionTest.cpp) +add_executable(${PROJECT_NAME}_tests ConstructionTest.cpp) target_link_libraries(${PROJECT_NAME}_tests doctest::doctest cppIni) target_compile_definitions(${PROJECT_NAME}_tests PUBLIC diff --git a/tests/constructionTest.cpp b/tests/ConstructionTest.cpp similarity index 85% rename from tests/constructionTest.cpp rename to tests/ConstructionTest.cpp index 4a98340..3de5fb3 100644 --- a/tests/constructionTest.cpp +++ b/tests/ConstructionTest.cpp @@ -1,9 +1,9 @@ #define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN -#include #include +#include TEST_CASE("Construction test") { - CHECK(one() == 1); + CHECK_EQ(one(), 1); } From 1953bdd2fa7616f89659ddf2e876d311c5d8b8a9 Mon Sep 17 00:00:00 2001 From: Master92 Date: Tue, 29 Aug 2023 09:15:13 +0200 Subject: [PATCH 5/9] Restructure test CMake file --- tests/CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 93dec34..e70afdd 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,12 +1,12 @@ cmake_minimum_required(VERSION 3.24) -include(CTest) - -set(TEST_DRIVER_NAME TestDriver) - find_package(doctest REQUIRED) -add_executable(${PROJECT_NAME}_tests ConstructionTest.cpp) +set(TEST_SOURCES + ConstructionTest.cpp +) + +add_executable(${PROJECT_NAME}_tests ${TEST_SOURCES}) target_link_libraries(${PROJECT_NAME}_tests doctest::doctest cppIni) target_compile_definitions(${PROJECT_NAME}_tests PUBLIC From 08107e2654a838de9f72d4fd71c3c8288835603c Mon Sep 17 00:00:00 2001 From: Master92 Date: Tue, 29 Aug 2023 09:15:45 +0200 Subject: [PATCH 6/9] Discover Doctest test cases for CTest --- CMakeLists.txt | 3 ++- tests/CMakeLists.txt | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 18e73b9..b660188 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,11 +4,12 @@ project(cppIni LANGUAGES CXX VERSION 0.0.0) set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) +option(BUILD_TESTING ON "Build test files") option(BUILD_SHARED_LIBS ON "Build shared library files") add_subdirectory(src) -include(CTest) if(BUILD_TESTING) + enable_testing() add_subdirectory(tests) endif() \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e70afdd..a067488 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -18,3 +18,11 @@ target_include_directories(${PROJECT_NAME} ${PROJECT_SOURCE_DIR}/include ${DOCTEST_INCLUDE_DIR} ) + +find_file(DOCTEST_CMAKE doctest.cmake) +if(NOT DOCTEST_CMAKE) + message(FATAL_ERROR "Could not find doctest.cmake") +else() + include(${DOCTEST_CMAKE}) + doctest_discover_tests(${PROJECT_NAME}_tests) +endif() From 40a8ec9c73af4ff27e379a2ec9e88b69aca3b125 Mon Sep 17 00:00:00 2001 From: Master92 Date: Wed, 30 Aug 2023 07:52:12 +0200 Subject: [PATCH 7/9] Run test suite in github action --- .github/workflows/build.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 03701cf..390f7d3 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -82,4 +82,5 @@ jobs: run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} --parallel - name: Run test suite - run: build/tests/cppIni_tests + working-directory: build + run: ctest --build-config ${{ matrix.build_type }} From bf33f031b9190a6638cf2f058bf1bd2cd32d6372 Mon Sep 17 00:00:00 2001 From: Master92 Date: Wed, 30 Aug 2023 07:54:31 +0200 Subject: [PATCH 8/9] Use github action for setting up Python and Conan --- .github/workflows/build.yaml | 10 +++++++--- requirements.txt | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 requirements.txt diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 390f7d3..13d5f79 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -53,15 +53,19 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Setup python + uses: actions/setup-python@v4 + with: + python-version: 3.10 + cache: pip + - run: pip install -r requirements.txt + - name: Set reusable strings # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. id: strings shell: bash run: echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" - - name: Get Conan - uses: turtlebrowser/get-conan@v1.2 - - name: Create default Conan profile run: conan profile detect diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..45f9eee --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +conan >= 2.0.10 From 0ea2a3a9b7afba6b025784b386bb4c1fbcc9f629 Mon Sep 17 00:00:00 2001 From: Master92 Date: Wed, 30 Aug 2023 08:40:12 +0200 Subject: [PATCH 9/9] Install latest and greatest gcc and clang --- .github/workflows/build.yaml | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 13d5f79..b93b9c0 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -53,10 +53,22 @@ jobs: steps: - uses: actions/checkout@v3 + - name: Install GCC + uses: egor-tensin/setup-gcc@v1.3 + if: matrix.os == 'ubuntu-latest' && matrix.c_compiler == 'gcc' + with: + version: 13 + + - name: Install Clang + uses: egor-tensin/setup-clang@v1.4 + if: matrix.os == 'ubuntu-latest' && matrix.c_compiler == 'clang' + with: + version: 16 + - name: Setup python uses: actions/setup-python@v4 with: - python-version: 3.10 + python-version: '3.10' cache: pip - run: pip install -r requirements.txt