diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cff567a..c719d16 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,12 +19,13 @@ jobs: run: mv test/* . - name: Use the action + id: cmake-action uses: ./ - name: Try to test the project id: failed-step continue-on-error: true - run: ctest --test-dir build --output-on-failure --no-tests=error -R hello_world ${{ matrix.os == 'windows' && '-C Debug' || '' }} + run: ctest --test-dir ${{ steps.cmake-action.outputs.build-dir }} --output-on-failure --no-tests=error -R hello_world ${{ matrix.os == 'windows' && '-C Debug' || '' }} - name: Check on success if: steps.failed-step.outcome == 'success' @@ -32,8 +33,8 @@ jobs: - name: Build and test the project run: | - cmake --build build - ctest --test-dir build --output-on-failure --no-tests=error -R hello_world ${{ matrix.os == 'windows' && '-C Debug' || '' }} + cmake --build ${{ steps.cmake-action.outputs.build-dir }} + ctest --test-dir ${{ steps.cmake-action.outputs.build-dir }} --output-on-failure --no-tests=error -R hello_world ${{ matrix.os == 'windows' && '-C Debug' || '' }} specified-dir-usage: runs-on: ubuntu-latest @@ -42,6 +43,7 @@ jobs: uses: actions/checkout@v3.5.3 - name: Use the action with specified directories + id: cmake-action uses: ./ with: source-dir: test @@ -53,8 +55,8 @@ jobs: - name: Build and test the project run: | - cmake --build output - ctest --test-dir output --output-on-failure --no-tests=error -R hello_world + cmake --build ${{ steps.cmake-action.outputs.build-dir }} + ctest --test-dir ${{ steps.cmake-action.outputs.build-dir }} --output-on-failure --no-tests=error -R hello_world run-build-usage: runs-on: ubuntu-latest @@ -63,6 +65,7 @@ jobs: uses: actions/checkout@v3.5.3 - name: Use the action with run build enabled + id: cmake-action uses: ./ with: source-dir: test @@ -70,7 +73,7 @@ jobs: build-args: --target test_c --target test_cpp - name: Test the project - run: ctest --test-dir test/build --output-on-failure --no-tests=error -R test + run: ctest --test-dir ${{ steps.cmake-action.outputs.build-dir }} --output-on-failure --no-tests=error -R test run-test-usage: runs-on: ubuntu-latest diff --git a/README.md b/README.md index 2ee3227..9ab76aa 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,12 @@ For more information, refer to [action.yml](./action.yml) and the [GitHub Action > **Note**: All inputs are optional. +### Outputs + +| Name | Value Type | Description | +| --- | --- | --- | +| `build-dir` | Path | The build directory of the CMake project. | + ### Examples ```yaml diff --git a/action.yml b/action.yml index 51a8bd8..8332bff 100644 --- a/action.yml +++ b/action.yml @@ -46,11 +46,15 @@ inputs: test-args: description: Additional arguments to pass during the CTest run required: false +outputs: + build-dir: + description: The build directory of the CMake project + value: ${{ steps.process-inputs.outputs.build-dir }} runs: using: composite steps: - name: Process the inputs - id: process_inputs + id: process-inputs shell: bash run: | SOURCE_DIR="." @@ -64,6 +68,7 @@ runs: elif [ -n "${{ inputs.source-dir }}" ]; then BUILD_DIR="${{ inputs.source-dir }}/build" fi + echo "build-dir=$BUILD_DIR" >> $GITHUB_OUTPUT ARGS="'$SOURCE_DIR' -B '$BUILD_DIR'" if [ -n '${{ inputs.generator }}' ]; then @@ -87,14 +92,14 @@ runs: if [ -n '${{ inputs.args }}' ]; then ARGS="$ARGS ${{ inputs.args }}" fi - echo "cmake_args=${ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT + echo "cmake-args=${ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT if [ '${{ inputs.run-build }}' == 'true' ] || [ '${{ inputs.run-test }}' == 'true' ]; then BUILD_ARGS="--build '$BUILD_DIR'" if [ -n '${{ inputs.build-args }}' ]; then BUILD_ARGS="$BUILD_ARGS ${{ inputs.build-args }}" fi - echo "cmake_build_args=${BUILD_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT + echo "cmake-build-args=${BUILD_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT fi if [ '${{ inputs.run-test }}' == 'true' ]; then @@ -102,7 +107,7 @@ runs: if [ -n '${{ inputs.test-args }}' ]; then TEST_ARGS="$TEST_ARGS ${{ inputs.test-args }}" fi - echo "cmake_test_args=${TEST_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT + echo "cmake-test-args=${TEST_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT fi - name: Install Ninja @@ -117,14 +122,14 @@ runs: - name: Configure the CMake project shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }} - run: cmake ${{ steps.process_inputs.outputs.cmake_args }} + run: cmake ${{ steps.process-inputs.outputs.cmake-args }} - name: Build targets if: inputs.run-build != 'false' || inputs.run-test != 'false' shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }} - run: cmake ${{ steps.process_inputs.outputs.cmake_build_args }} + run: cmake ${{ steps.process-inputs.outputs.cmake-build-args }} - name: Run tests if: inputs.run-test != 'false' shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }} - run: ctest ${{ steps.process_inputs.outputs.cmake_test_args }} + run: ctest ${{ steps.process-inputs.outputs.cmake-test-args }}