add a new run-test input option for running tests using CTest

This commit is contained in:
Alfi Maulana 2023-01-22 11:53:07 +07:00
parent cf153dc8e3
commit d59afd2844
No known key found for this signature in database
GPG Key ID: 2242A64C2A8DF5A4
2 changed files with 15 additions and 0 deletions

View File

@ -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. |

View File

@ -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 }}