Skip to content

Add build-dir Action Output #53

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/[email protected]

- 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/[email protected]

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