From 657a82ee9f70899eae04d21be382facf6deb950d Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Tue, 17 Jan 2023 12:34:58 +0700 Subject: [PATCH 01/22] fix missing `CHECK_SUPASS_WARNING` in `additional-flags-uasage` job --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e51b54a..5fa73b6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -52,6 +52,7 @@ jobs: targets: test_c test_cpp c-flags: -Wno-unused-variable cxx-flags: -Wno-unused-variable + args: -D CHECK_SURPASS_WARNING=ON - name: Run the build results run: build/test_c && build/test_cpp From 250f59da815a35529395041f2b62adf129cb4e81 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Tue, 17 Jan 2023 12:46:36 +0700 Subject: [PATCH 02/22] run `additional-flags-usage` job on both GCC and MSVC --- .github/workflows/test.yml | 9 ++++++--- test/CMakeLists.txt | 9 +++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5fa73b6..0a1ddd0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,7 +40,10 @@ jobs: run: test ! -d build additional-flags-usage: - runs-on: ubuntu-latest + runs-on: ${{ matrix.compiler == 'msvc' && 'windows' || 'ubuntu' }}-latest + strategy: + matrix: + compiler: [gcc, msvc] steps: - name: Check out this repository uses: actions/checkout@v3.3.0 @@ -50,8 +53,8 @@ jobs: with: source-dir: test targets: test_c test_cpp - c-flags: -Wno-unused-variable - cxx-flags: -Wno-unused-variable + c-flags: ${{ matrix.compiler == 'msvc' && '/w' || '-Wno-unused-variable' }} + cxx-flags: ${{ matrix.compiler == 'msvc' && '/w' || '-Wno-unused-variable' }} args: -D CHECK_SURPASS_WARNING=ON - name: Run the build results diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 434f472..1f6ccca 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -5,8 +5,13 @@ option(CHECK_USING_CLANG "check if target is compiled using Clang" OFF) option(CHECK_SURPASS_WARNING "check if target could surpass a compiler warning" OFF) if(CHECK_SURPASS_WARNING) - set(CMAKE_C_FLAGS "-Werror -Wunused-variable ${CMAKE_C_FLAGS}") - set(CMAKE_CXX_FLAGS "-Werror -Wunused-variable ${CMAKE_CXX_FLAGS}") + if(MSVC) + set(CMAKE_C_FLAGS "/WX /W4 ${CMAKE_C_FLAGS}") + set(CMAKE_CXX_FLAGS "/WX /W4 ${CMAKE_CXX_FLAGS}") + else() + set(CMAKE_C_FLAGS "-Werror -Wunused-variable ${CMAKE_C_FLAGS}") + set(CMAKE_CXX_FLAGS "-Werror -Wunused-variable ${CMAKE_CXX_FLAGS}") + endif() endif() add_executable(hello_world hello_world.cpp) From 8da16854fcdc8f617ad5af70e31a0d2ccce1f1cf Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Tue, 17 Jan 2023 12:51:31 +0700 Subject: [PATCH 03/22] guard most input values with single quotation --- action.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/action.yml b/action.yml index 97eff0d..40d0287 100644 --- a/action.yml +++ b/action.yml @@ -41,25 +41,25 @@ runs: id: process_inputs shell: bash run: | - ARGS="${{ inputs.source-dir }} -B ${{ inputs.build-dir }}" - BUILD_ARGS="--build ${{ inputs.build-dir }}" + ARGS="'${{ inputs.source-dir }}' -B '${{ inputs.build-dir }}'" + BUILD_ARGS="--build '${{ inputs.build-dir }}'" if [ -n '${{ inputs.targets }}' ]; then BUILD_ARGS="$BUILD_ARGS --target ${{ inputs.targets }}" fi if [ -n '${{ inputs.generator }}' ]; then - ARGS="$ARGS -G ${{ inputs.generator }}" + ARGS="$ARGS -G '${{ inputs.generator }}'" fi if [ -n '${{ inputs.c-compiler }}' ]; then - ARGS="$ARGS -D CMAKE_C_COMPILER=${{ inputs.c-compiler }}" + ARGS="$ARGS -D CMAKE_C_COMPILER='${{ inputs.c-compiler }}'" fi if [ -n '${{ inputs.cxx-compiler }}' ]; then - ARGS="$ARGS -D CMAKE_CXX_COMPILER=${{ inputs.cxx-compiler }}" + ARGS="$ARGS -D CMAKE_CXX_COMPILER='${{ inputs.cxx-compiler }}'" fi if [ -n '${{ inputs.c-flags }}' ]; then - ARGS="$ARGS -D CMAKE_C_FLAGS=${{ inputs.c-flags }}" + ARGS="$ARGS -D CMAKE_C_FLAGS='${{ inputs.c-flags }}'" fi if [ -n '${{ inputs.cxx-flags }}' ]; then - ARGS="$ARGS -D CMAKE_CXX_FLAGS=${{ inputs.cxx-flags }}" + ARGS="$ARGS -D CMAKE_CXX_FLAGS='${{ inputs.cxx-flags }}'" fi if [ -n '${{ inputs.args }}' ]; then ARGS="$ARGS ${{ inputs.args }}" From 6548c2aab5d0d3af47595bd65cae5f76bbae704f Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Tue, 17 Jan 2023 13:01:24 +0700 Subject: [PATCH 04/22] specify shell to use PowerShell on Windows --- action.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index 40d0287..af61157 100644 --- a/action.yml +++ b/action.yml @@ -78,9 +78,9 @@ runs: esac - name: Configure the CMake project - shell: bash + shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }} run: cmake ${{ steps.process_inputs.outputs.cmake_args }} - name: Build targets - shell: bash + shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }} run: cmake ${{ steps.process_inputs.outputs.cmake_build_args }} From 716f237b518d36f29c5c8aeae89fea02e34221bc Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Tue, 17 Jan 2023 13:06:32 +0700 Subject: [PATCH 05/22] disable warning as error on MSVC test --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0a1ddd0..664d181 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -53,8 +53,8 @@ jobs: with: source-dir: test targets: test_c test_cpp - c-flags: ${{ matrix.compiler == 'msvc' && '/w' || '-Wno-unused-variable' }} - cxx-flags: ${{ matrix.compiler == 'msvc' && '/w' || '-Wno-unused-variable' }} + c-flags: ${{ matrix.compiler == 'msvc' && '/w /WX-' || '-Wno-unused-variable' }} + cxx-flags: ${{ matrix.compiler == 'msvc' && '/w /WX-' || '-Wno-unused-variable' }} args: -D CHECK_SURPASS_WARNING=ON - name: Run the build results From c51d734eb9b1f820ee89c94ab6bef0254b085c99 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Tue, 17 Jan 2023 13:07:40 +0700 Subject: [PATCH 06/22] fix build results location on MSVC test --- .github/workflows/test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 664d181..442a728 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -58,7 +58,9 @@ jobs: args: -D CHECK_SURPASS_WARNING=ON - name: Run the build results - run: build/test_c && build/test_cpp + run: | + ${{ matrix.compiler == 'msvc' && 'build\Debug\test_c.exe' || 'build/test_c' }} + ${{ matrix.compiler == 'msvc' && 'build\Debug\test_cpp.exe' || 'build/test_cpp' }} specified-compiler-usage: runs-on: ${{ matrix.os }}-latest From 186353f77abb20f640d384fba16e94378b85de05 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 22 Jan 2023 11:13:03 +0700 Subject: [PATCH 07/22] handle the default source dir in the process inputs step --- action.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index af61157..5d70903 100644 --- a/action.yml +++ b/action.yml @@ -8,7 +8,6 @@ inputs: source-dir: description: Source directory of the CMake project required: false - default: . build-dir: description: Build directory of the CMake project required: false @@ -41,7 +40,11 @@ runs: id: process_inputs shell: bash run: | - ARGS="'${{ inputs.source-dir }}' -B '${{ inputs.build-dir }}'" + SOURCE_DIR="." + if [ -n '${{ inputs.source-dir }}' ]; then + SOURCE_DIR="${{ inputs.source-dir }}" + fi + ARGS="'$SOURCE_DIR' -B '${{ inputs.build-dir }}'" BUILD_ARGS="--build '${{ inputs.build-dir }}'" if [ -n '${{ inputs.targets }}' ]; then BUILD_ARGS="$BUILD_ARGS --target ${{ inputs.targets }}" From 584ef59aade4444991a4f3cf2e84a7818b73b039 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 22 Jan 2023 11:23:52 +0700 Subject: [PATCH 08/22] handle the default build dir to be relative to the source dir --- .github/workflows/test.yml | 14 +++++++------- action.yml | 11 ++++++++--- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 442a728..c58c1ae 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,13 +31,13 @@ jobs: uses: ./ with: source-dir: test - build-dir: test/build + build-dir: output - name: Run the build result - run: test/build/hello_world + run: output/hello_world - name: Check if the default build directory does not exist - run: test ! -d build + run: test ! -d build && test ! -d test/build additional-flags-usage: runs-on: ${{ matrix.compiler == 'msvc' && 'windows' || 'ubuntu' }}-latest @@ -59,8 +59,8 @@ jobs: - name: Run the build results run: | - ${{ matrix.compiler == 'msvc' && 'build\Debug\test_c.exe' || 'build/test_c' }} - ${{ matrix.compiler == 'msvc' && 'build\Debug\test_cpp.exe' || 'build/test_cpp' }} + ${{ matrix.compiler == 'msvc' && 'test\build\Debug\test_c.exe' || 'test/build/test_c' }} + ${{ matrix.compiler == 'msvc' && 'test\build\Debug\test_cpp.exe' || 'test/build/test_cpp' }} specified-compiler-usage: runs-on: ${{ matrix.os }}-latest @@ -82,7 +82,7 @@ jobs: args: -D CHECK_USING_CLANG=ON - name: Run the build results - run: build/test_c && build/test_cpp + run: test/build/test_c && test/build/test_cpp specified-generator-usage: runs-on: ${{ matrix.os }}-latest @@ -100,4 +100,4 @@ jobs: generator: Ninja - name: Run the build result - run: build/hello_world + run: test/build/hello_world diff --git a/action.yml b/action.yml index 5d70903..1461fcd 100644 --- a/action.yml +++ b/action.yml @@ -11,7 +11,6 @@ inputs: build-dir: description: Build directory of the CMake project required: false - default: build targets: description: List of build targets required: false @@ -44,8 +43,14 @@ runs: if [ -n '${{ inputs.source-dir }}' ]; then SOURCE_DIR="${{ inputs.source-dir }}" fi - ARGS="'$SOURCE_DIR' -B '${{ inputs.build-dir }}'" - BUILD_ARGS="--build '${{ inputs.build-dir }}'" + BUILD_DIR="build" + if [ -n '${{ inputs.build-dir }}' ]; then + BUILD_DIR="${{ inputs.build-dir }}" + elif [ -n "${{ inputs.source-dir }}" ]; then + BUILD_DIR="${{ inputs.source-dir }}/build" + fi + ARGS="'$SOURCE_DIR' -B '$BUILD_DIR'" + BUILD_ARGS="--build '$BUILD_DIR'" if [ -n '${{ inputs.targets }}' ]; then BUILD_ARGS="$BUILD_ARGS --target ${{ inputs.targets }}" fi From d59afd284435ef69dc9e2ed392e0a73e750ddff9 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 22 Jan 2023 11:53:07 +0700 Subject: [PATCH 09/22] add a new `run-test` input option for running tests using CTest --- README.md | 1 + action.yml | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/README.md b/README.md index e81da89..a6b4d81 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ For more information, see [action.yml](./action.yml) and [GitHub Actions guide]( | `source-dir` | Path | Source directory of the CMake project. Defaults to current directory. | | `build-dir` | Path | Build directory of the CMake project. Defaults to `build` directory in current directory. | | `targets` | Multiple strings | List of build targets. | +| `run-test` | `true` or `false` | If enabled, run testing using [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html). Defaults to `false`. | | `generator` | String | Build system generator of the CMake project. | | `c-compiler` | String | Preferred executable for compiling C language files. | | `cxx-compiler` | String | Preferred executable for compiling C++ language files. | diff --git a/action.yml b/action.yml index 1461fcd..8a5be0a 100644 --- a/action.yml +++ b/action.yml @@ -14,6 +14,10 @@ inputs: targets: description: List of build targets required: false + run-test: + description: If enabled, run testing using CTest (true/false) + required: false + default: false generator: description: Build system generator of the CMake project required: false @@ -51,9 +55,13 @@ runs: fi ARGS="'$SOURCE_DIR' -B '$BUILD_DIR'" BUILD_ARGS="--build '$BUILD_DIR'" + TEST_ARGS="" if [ -n '${{ inputs.targets }}' ]; then BUILD_ARGS="$BUILD_ARGS --target ${{ inputs.targets }}" fi + if [ '${{ inputs.run-test }}' == 'true' ]; then + TEST_ARGS="--test-dir '$BUILD_DIR' --output-on-failure --no-tests=error" + fi if [ -n '${{ inputs.generator }}' ]; then ARGS="$ARGS -G '${{ inputs.generator }}'" fi @@ -74,6 +82,7 @@ runs: fi echo "cmake_args=${ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT echo "cmake_build_args=${BUILD_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT + echo "cmake_test_args=${TEST_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT - name: Install Ninja if: ${{ inputs.generator == 'Ninja' }} @@ -92,3 +101,8 @@ runs: - name: Build targets shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }} run: cmake ${{ steps.process_inputs.outputs.cmake_build_args }} + + - name: Run tests + if: steps.process_inputs.outputs.cmake_test_args != '' + shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }} + run: ctest ${{ steps.process_inputs.outputs.cmake_test_args }} From 633b25cfad6f3b791c2a115b23a5d11b125a1b88 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 22 Jan 2023 12:32:23 +0700 Subject: [PATCH 10/22] add support to run hello world target as a CMake test --- .github/workflows/test.yml | 8 ++------ test/CMakeLists.txt | 2 ++ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c58c1ae..927c660 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,9 +32,7 @@ jobs: with: source-dir: test build-dir: output - - - name: Run the build result - run: output/hello_world + run_test: true - name: Check if the default build directory does not exist run: test ! -d build && test ! -d test/build @@ -98,6 +96,4 @@ jobs: with: source-dir: test generator: Ninja - - - name: Run the build result - run: test/build/hello_world + run-test: true diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 1f6ccca..c031db3 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -14,7 +14,9 @@ if(CHECK_SURPASS_WARNING) endif() endif() +enable_testing() add_executable(hello_world hello_world.cpp) +add_test(NAME hello_world COMMAND $) list(APPEND LANGS c cpp) foreach(LANG ${LANGS}) From 03870ba3b09bcdad90044cf60fe5d8c4ea670398 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 22 Jan 2023 12:44:19 +0700 Subject: [PATCH 11/22] add a new `test-args` action input for passing additional arguments during the CTest run --- README.md | 1 + action.yml | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/README.md b/README.md index a6b4d81..5923fd7 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,7 @@ For more information, see [action.yml](./action.yml) and [GitHub Actions guide]( | `c-flags` | Multiple strings | Additional flags passed when compiling C language files. | | `cxx-flags` | Multiple strings | Additional flags passed when compiling C++ language files. | | `args` | Multiple strings | Additional arguments passed during the CMake configuration. | +| `test-args` | Multiple strings | Additional arguments passed during the CTest run. | > Note: Multiple strings mean that the input could be specified with more than one value. Separate each value with a space or a new line. diff --git a/action.yml b/action.yml index 8a5be0a..3759521 100644 --- a/action.yml +++ b/action.yml @@ -36,6 +36,9 @@ inputs: args: description: Additional arguments passed during the CMake configuration required: false + test-args: + description: Additional arguments passed during the CTest run + required: false runs: using: composite steps: @@ -80,6 +83,9 @@ runs: if [ -n '${{ inputs.args }}' ]; then ARGS="$ARGS ${{ inputs.args }}" fi + if [ -n '${{ inputs.test-args }}' ]; then + TEST_ARGS="$TEST_ARGS ${{ inputs.test-args }}" + fi echo "cmake_args=${ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT echo "cmake_build_args=${BUILD_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT echo "cmake_test_args=${TEST_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT From c04ca4c05abf6055ec907c73701a4ef5dd522c01 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 22 Jan 2023 12:47:03 +0700 Subject: [PATCH 12/22] add support to run `test_c` and `test_cpp` targets as a CMake test --- .github/workflows/test.yml | 14 +++++--------- test/CMakeLists.txt | 1 + 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 927c660..e468e23 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -32,7 +32,7 @@ jobs: with: source-dir: test build-dir: output - run_test: true + run-test: true - name: Check if the default build directory does not exist run: test ! -d build && test ! -d test/build @@ -51,14 +51,11 @@ jobs: with: source-dir: test targets: test_c test_cpp + run-test: true c-flags: ${{ matrix.compiler == 'msvc' && '/w /WX-' || '-Wno-unused-variable' }} cxx-flags: ${{ matrix.compiler == 'msvc' && '/w /WX-' || '-Wno-unused-variable' }} args: -D CHECK_SURPASS_WARNING=ON - - - name: Run the build results - run: | - ${{ matrix.compiler == 'msvc' && 'test\build\Debug\test_c.exe' || 'test/build/test_c' }} - ${{ matrix.compiler == 'msvc' && 'test\build\Debug\test_cpp.exe' || 'test/build/test_cpp' }} + test-args: -C test specified-compiler-usage: runs-on: ${{ matrix.os }}-latest @@ -74,13 +71,12 @@ jobs: with: source-dir: test targets: test_c test_cpp + run-test: true generator: Ninja c-compiler: clang cxx-compiler: clang++ args: -D CHECK_USING_CLANG=ON - - - name: Run the build results - run: test/build/test_c && test/build/test_cpp + test-args: -C test specified-generator-usage: runs-on: ${{ matrix.os }}-latest diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c031db3..93afcfd 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -28,4 +28,5 @@ foreach(LANG ${LANGS}) $<$:CHECK_USING_CLANG> $<$:CHECK_SURPASS_WARNING> ) + add_test(NAME test_${LANG} CONFIGURATIONS test COMMAND $) endforeach() From c2bf81f4d36809faf45315e434c747ba07070b98 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 22 Jan 2023 12:53:38 +0700 Subject: [PATCH 13/22] ignore testing `hello_world` if building `test_c` and `test_cpp` --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e468e23..5583744 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -55,7 +55,7 @@ jobs: c-flags: ${{ matrix.compiler == 'msvc' && '/w /WX-' || '-Wno-unused-variable' }} cxx-flags: ${{ matrix.compiler == 'msvc' && '/w /WX-' || '-Wno-unused-variable' }} args: -D CHECK_SURPASS_WARNING=ON - test-args: -C test + test-args: -C test -E hello_world specified-compiler-usage: runs-on: ${{ matrix.os }}-latest @@ -76,7 +76,7 @@ jobs: c-compiler: clang cxx-compiler: clang++ args: -D CHECK_USING_CLANG=ON - test-args: -C test + test-args: -C test -E hello_world specified-generator-usage: runs-on: ${{ matrix.os }}-latest From 354c02b686a4d81e3775b1658ffa7ce4a4cc0acb Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 22 Jan 2023 13:07:56 +0700 Subject: [PATCH 14/22] replace test configuration with regex match --- .github/workflows/test.yml | 8 +++++--- test/CMakeLists.txt | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5583744..26df2cf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,6 +33,7 @@ jobs: source-dir: test build-dir: output run-test: true + test-args: -R hello_world - name: Check if the default build directory does not exist run: test ! -d build && test ! -d test/build @@ -55,7 +56,7 @@ jobs: c-flags: ${{ matrix.compiler == 'msvc' && '/w /WX-' || '-Wno-unused-variable' }} cxx-flags: ${{ matrix.compiler == 'msvc' && '/w /WX-' || '-Wno-unused-variable' }} args: -D CHECK_SURPASS_WARNING=ON - test-args: -C test -E hello_world + test-args: -R test specified-compiler-usage: runs-on: ${{ matrix.os }}-latest @@ -76,7 +77,7 @@ jobs: c-compiler: clang cxx-compiler: clang++ args: -D CHECK_USING_CLANG=ON - test-args: -C test -E hello_world + test-args: -R test specified-generator-usage: runs-on: ${{ matrix.os }}-latest @@ -91,5 +92,6 @@ jobs: uses: ./ with: source-dir: test - generator: Ninja run-test: true + generator: Ninja + test-args: -R hello_world diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 93afcfd..9c512eb 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -28,5 +28,5 @@ foreach(LANG ${LANGS}) $<$:CHECK_USING_CLANG> $<$:CHECK_SURPASS_WARNING> ) - add_test(NAME test_${LANG} CONFIGURATIONS test COMMAND $) + add_test(NAME test_${LANG} COMMAND $) endforeach() From ac31ad47dee7e1ac2d645be4c802aed4c0e01dac Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 22 Jan 2023 13:45:46 +0700 Subject: [PATCH 15/22] fix debug config when running test on MSVC --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 26df2cf..3096ece 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -56,7 +56,7 @@ jobs: c-flags: ${{ matrix.compiler == 'msvc' && '/w /WX-' || '-Wno-unused-variable' }} cxx-flags: ${{ matrix.compiler == 'msvc' && '/w /WX-' || '-Wno-unused-variable' }} args: -D CHECK_SURPASS_WARNING=ON - test-args: -R test + test-args: -R test ${{ matrix.compiler == 'msvc' && '-C Debug' || '' }} specified-compiler-usage: runs-on: ${{ matrix.os }}-latest From c421afa648cac4a833cec61ea88308c544b634ec Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Mon, 23 Jan 2023 14:39:51 +0700 Subject: [PATCH 16/22] modify action short description to include testing a project --- README.md | 2 +- action.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5923fd7..420f0ce 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![license](https://img.shields.io/github/license/threeal/cmake-action)](./LICENSE) [![test status](https://img.shields.io/github/actions/workflow/status/threeal/cmake-action/test.yml?label=test&branch=main)](https://github.com/threeal/cmake-action/actions/workflows/test.yml) -Configure and build a [CMake](https://cmake.org/) project on [GitHub Actions](https://github.com/features/actions). +Configure, build, and test a [CMake](https://cmake.org/) project on [GitHub Actions](https://github.com/features/actions). ## Usage diff --git a/action.yml b/action.yml index 3759521..ec6c6aa 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ name: CMake Action -description: Configure and build a CMake project +description: Configure, build, and test a CMake project author: Alfi Maulana branding: color: gray-dark From cb46ab8971d82bfe23cbf78efb850dbf5d97bdd7 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Mon, 23 Jan 2023 14:41:35 +0700 Subject: [PATCH 17/22] expand project description --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 420f0ce..c95538e 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,10 @@ [![test status](https://img.shields.io/github/actions/workflow/status/threeal/cmake-action/test.yml?label=test&branch=main)](https://github.com/threeal/cmake-action/actions/workflows/test.yml) Configure, build, and test a [CMake](https://cmake.org/) project on [GitHub Actions](https://github.com/features/actions). +Use this action to simplify the workflow run of your CMake project. +This action will configure a build environment for your project using the `cmake` command, + then it will build your project by running a `cmake --build` command, + and last it could test your project using the `ctest` command. ## Usage From 38a05924280d848a8a65e7a670177fbb9ca502ed Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Mon, 23 Jan 2023 14:54:21 +0700 Subject: [PATCH 18/22] add a new feature section in the `README.md` --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index c95538e..13bbb8e 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,13 @@ This action will configure a build environment for your project using the `cmake then it will build your project by running a `cmake --build` command, and last it could test your project using the `ctest` command. +## Features + +- Configure and build a project using the [cmake](https://cmake.org/cmake/help/latest/manual/cmake.1.html) command. +- Optionally test a project using the [ctest](https://cmake.org/cmake/help/latest/manual/ctest.1.html) command. +- Auto-detect and install required dependencies. +- Specify multiple CMake options directly from the Action inputs. + ## Usage For more information, see [action.yml](./action.yml) and [GitHub Actions guide](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions). From 0a9428a22b618641338e9cd4fc8367d94cd91ae2 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Mon, 23 Jan 2023 15:02:08 +0700 Subject: [PATCH 19/22] update the default value info of `build-dir` action input --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 13bbb8e..6288681 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ For more information, see [action.yml](./action.yml) and [GitHub Actions guide]( | Name | Value Type | Description | | --- | --- | --- | | `source-dir` | Path | Source directory of the CMake project. Defaults to current directory. | -| `build-dir` | Path | Build directory of the CMake project. Defaults to `build` directory in current directory. | +| `build-dir` | Path | Build directory of the CMake project. Defaults to `build` directory inside the source directory. | | `targets` | Multiple strings | List of build targets. | | `run-test` | `true` or `false` | If enabled, run testing using [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html). Defaults to `false`. | | `generator` | String | Build system generator of the CMake project. | From 4ee1d5d7fc6ee19e878d20e5aedce71c74df62f4 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Mon, 23 Jan 2023 15:31:39 +0700 Subject: [PATCH 20/22] add detailed info about using the action version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6288681..c780911 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ jobs: uses: threeal/cmake-action@latest ``` -> Note: You can replace `@latest` with any version you like. +> Note: You can replace `@latest` with any version you like. See [this](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsuses). #### Specify the Source and the Build Directories From 921b31dcf42da1dc0d09ca909891b398c6481c40 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Mon, 23 Jan 2023 15:37:40 +0700 Subject: [PATCH 21/22] add a run unit tests example in the `README.md` --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index c780911..776bee3 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,16 @@ jobs: -DBUILD_TESTING=ON ``` +#### Run Unit Tests After Build + +```yaml +- name: Configure, build, and test this project + uses: threeal/cmake-action@latest + with: + args: -DBUILD_TESTING=ON + run-test: true +``` + #### Using Ninja as the Generator and Clang as the Compiler ```yaml From 42dedb750753cb1ed08aef319011e45fd213daf6 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Mon, 23 Jan 2023 15:39:29 +0700 Subject: [PATCH 22/22] audit examples in the `README.md` --- README.md | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 776bee3..cc25a92 100644 --- a/README.md +++ b/README.md @@ -67,21 +67,16 @@ jobs: uses: threeal/cmake-action@latest with: source-dir: submodules - build-dir: submodules/build + build-dir: submodules/out ``` -#### Specify the Build Targets and Additional Options +#### Specify the Build Targets ```yaml - name: Configure and build this project uses: threeal/cmake-action@latest with: - targets: hello_world_test fibonacci_test - c-flags: -Werror - cxx-flags: -Werror - args: | - -DCMAKE_BUILD_TYPE=Debug - -DBUILD_TESTING=ON + targets: hello_mars hello_sun ``` #### Run Unit Tests After Build