mirror of
https://github.com/threeal/cmake-action.git
synced 2025-06-08 10:11:21 +00:00
add a new run-test
input option for running tests using CTest
This commit is contained in:
parent
cf153dc8e3
commit
d59afd2844
@ -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. |
|
||||
|
14
action.yml
14
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 }}
|
||||
|
Loading…
Reference in New Issue
Block a user