Skip to content

Commit 19d48eb

Browse files
authored
chore: merge pull request #53 from threeal/add-build-dir-output
Add `build-dir` Action Output
2 parents 555658b + 0a52a2a commit 19d48eb

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

.github/workflows/test.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,22 @@ jobs:
1919
run: mv test/* .
2020

2121
- name: Use the action
22+
id: cmake-action
2223
uses: ./
2324

2425
- name: Try to test the project
2526
id: failed-step
2627
continue-on-error: true
27-
run: ctest --test-dir build --output-on-failure --no-tests=error -R hello_world ${{ matrix.os == 'windows' && '-C Debug' || '' }}
28+
run: ctest --test-dir ${{ steps.cmake-action.outputs.build-dir }} --output-on-failure --no-tests=error -R hello_world ${{ matrix.os == 'windows' && '-C Debug' || '' }}
2829

2930
- name: Check on success
3031
if: steps.failed-step.outcome == 'success'
3132
run: exit 1
3233

3334
- name: Build and test the project
3435
run: |
35-
cmake --build build
36-
ctest --test-dir build --output-on-failure --no-tests=error -R hello_world ${{ matrix.os == 'windows' && '-C Debug' || '' }}
36+
cmake --build ${{ steps.cmake-action.outputs.build-dir }}
37+
ctest --test-dir ${{ steps.cmake-action.outputs.build-dir }} --output-on-failure --no-tests=error -R hello_world ${{ matrix.os == 'windows' && '-C Debug' || '' }}
3738
3839
specified-dir-usage:
3940
runs-on: ubuntu-latest
@@ -42,6 +43,7 @@ jobs:
4243
uses: actions/[email protected]
4344

4445
- name: Use the action with specified directories
46+
id: cmake-action
4547
uses: ./
4648
with:
4749
source-dir: test
@@ -53,8 +55,8 @@ jobs:
5355

5456
- name: Build and test the project
5557
run: |
56-
cmake --build output
57-
ctest --test-dir output --output-on-failure --no-tests=error -R hello_world
58+
cmake --build ${{ steps.cmake-action.outputs.build-dir }}
59+
ctest --test-dir ${{ steps.cmake-action.outputs.build-dir }} --output-on-failure --no-tests=error -R hello_world
5860
5961
run-build-usage:
6062
runs-on: ubuntu-latest
@@ -63,14 +65,15 @@ jobs:
6365
uses: actions/[email protected]
6466

6567
- name: Use the action with run build enabled
68+
id: cmake-action
6669
uses: ./
6770
with:
6871
source-dir: test
6972
run-build: true
7073
build-args: --target test_c --target test_cpp
7174

7275
- name: Test the project
73-
run: ctest --test-dir test/build --output-on-failure --no-tests=error -R test
76+
run: ctest --test-dir ${{ steps.cmake-action.outputs.build-dir }} --output-on-failure --no-tests=error -R test
7477

7578
run-test-usage:
7679
runs-on: ubuntu-latest

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ For more information, refer to [action.yml](./action.yml) and the [GitHub Action
4040
4141
> **Note**: All inputs are optional.
4242
43+
### Outputs
44+
45+
| Name | Value Type | Description |
46+
| --- | --- | --- |
47+
| `build-dir` | Path | The build directory of the CMake project. |
48+
4349
### Examples
4450

4551
```yaml

action.yml

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,15 @@ inputs:
4646
test-args:
4747
description: Additional arguments to pass during the CTest run
4848
required: false
49+
outputs:
50+
build-dir:
51+
description: The build directory of the CMake project
52+
value: ${{ steps.process-inputs.outputs.build-dir }}
4953
runs:
5054
using: composite
5155
steps:
5256
- name: Process the inputs
53-
id: process_inputs
57+
id: process-inputs
5458
shell: bash
5559
run: |
5660
SOURCE_DIR="."
@@ -64,6 +68,7 @@ runs:
6468
elif [ -n "${{ inputs.source-dir }}" ]; then
6569
BUILD_DIR="${{ inputs.source-dir }}/build"
6670
fi
71+
echo "build-dir=$BUILD_DIR" >> $GITHUB_OUTPUT
6772
6873
ARGS="'$SOURCE_DIR' -B '$BUILD_DIR'"
6974
if [ -n '${{ inputs.generator }}' ]; then
@@ -87,22 +92,22 @@ runs:
8792
if [ -n '${{ inputs.args }}' ]; then
8893
ARGS="$ARGS ${{ inputs.args }}"
8994
fi
90-
echo "cmake_args=${ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
95+
echo "cmake-args=${ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
9196
9297
if [ '${{ inputs.run-build }}' == 'true' ] || [ '${{ inputs.run-test }}' == 'true' ]; then
9398
BUILD_ARGS="--build '$BUILD_DIR'"
9499
if [ -n '${{ inputs.build-args }}' ]; then
95100
BUILD_ARGS="$BUILD_ARGS ${{ inputs.build-args }}"
96101
fi
97-
echo "cmake_build_args=${BUILD_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
102+
echo "cmake-build-args=${BUILD_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
98103
fi
99104
100105
if [ '${{ inputs.run-test }}' == 'true' ]; then
101106
TEST_ARGS="--test-dir '$BUILD_DIR' --output-on-failure --no-tests=error"
102107
if [ -n '${{ inputs.test-args }}' ]; then
103108
TEST_ARGS="$TEST_ARGS ${{ inputs.test-args }}"
104109
fi
105-
echo "cmake_test_args=${TEST_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
110+
echo "cmake-test-args=${TEST_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
106111
fi
107112
108113
- name: Install Ninja
@@ -117,14 +122,14 @@ runs:
117122
118123
- name: Configure the CMake project
119124
shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }}
120-
run: cmake ${{ steps.process_inputs.outputs.cmake_args }}
125+
run: cmake ${{ steps.process-inputs.outputs.cmake-args }}
121126

122127
- name: Build targets
123128
if: inputs.run-build != 'false' || inputs.run-test != 'false'
124129
shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }}
125-
run: cmake ${{ steps.process_inputs.outputs.cmake_build_args }}
130+
run: cmake ${{ steps.process-inputs.outputs.cmake-build-args }}
126131

127132
- name: Run tests
128133
if: inputs.run-test != 'false'
129134
shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }}
130-
run: ctest ${{ steps.process_inputs.outputs.cmake_test_args }}
135+
run: ctest ${{ steps.process-inputs.outputs.cmake-test-args }}

0 commit comments

Comments
 (0)