Skip to content

Commit

Permalink
chore: merge pull request #53 from threeal/add-build-dir-output
Browse files Browse the repository at this point in the history
Add `build-dir` Action Output
  • Loading branch information
threeal authored Jul 2, 2023
2 parents 555658b + 0a52a2a commit 19d48eb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@ 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'
run: exit 1

- 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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -63,14 +65,15 @@ jobs:
uses: actions/checkout@v3.5.3

- name: Use the action with run build enabled
id: cmake-action
uses: ./
with:
source-dir: test
run-build: true
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
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 12 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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="."
Expand All @@ -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
Expand All @@ -87,22 +92,22 @@ 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
TEST_ARGS="--test-dir '$BUILD_DIR' --output-on-failure --no-tests=error"
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
Expand All @@ -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 }}

0 comments on commit 19d48eb

Please # to comment.