mirror of
https://github.com/threeal/cmake-action.git
synced 2025-06-08 10:11:21 +00:00
commit
b684818e31
28
.github/workflows/test.yml
vendored
28
.github/workflows/test.yml
vendored
@ -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
|
||||
@ -129,3 +132,16 @@ jobs:
|
||||
build-args: --target test_c --target test_cpp
|
||||
run-test: true
|
||||
test-args: -R test
|
||||
|
||||
specified-shell:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: Checkout the repository
|
||||
uses: actions/checkout@v3.5.3
|
||||
|
||||
- name: Use the action with specified shell
|
||||
uses: ./
|
||||
with:
|
||||
shell: bash
|
||||
source-dir: test
|
||||
run-build: true
|
||||
|
48
README.md
48
README.md
@ -4,15 +4,15 @@
|
||||
[](./LICENSE)
|
||||
[](https://github.com/threeal/cmake-action/actions/workflows/test.yml)
|
||||
|
||||
Configure, build, and test your [CMake](https://cmake.org/) project using [GitHub Actions](https://github.com/features/actions). This action simplifies the workflow for your CMake project. It configures the build environment using the `cmake` command, and optionally builds the project using the `cmake --build` command and tests the project using the `ctest` command.
|
||||
Configure, build, and test your [CMake](https://cmake.org/) project using [GitHub Actions](https://github.com/features/actions). This action simplifies the workflow for configuring the build environment of a CMake project. It can also be optionally specified to build a CMake project using the `cmake --build` command and test it using the `ctest` command.
|
||||
|
||||
## Features
|
||||
|
||||
- Configures a project using the [`cmake`](https://cmake.org/cmake/help/latest/manual/cmake.1.html) command.
|
||||
- Option to build a project using the `cmake --build` command.
|
||||
- Option to test a project using the [`ctest`](https://cmake.org/cmake/help/latest/manual/ctest.1.html) command.
|
||||
- Configures a CMake project using the [`cmake`](https://cmake.org/cmake/help/latest/manual/cmake.1.html) command.
|
||||
- Optionally builds a CMake project using the `cmake --build` command.
|
||||
- Optionally tests a CMake project using the [`ctest`](https://cmake.org/cmake/help/latest/manual/ctest.1.html) command.
|
||||
- Auto-detects and installs required dependencies.
|
||||
- Supports specifying multiple CMake options directly from the Action inputs.
|
||||
- Supports specifying multiple CMake options directly from the action inputs.
|
||||
|
||||
## Usage
|
||||
|
||||
@ -22,6 +22,7 @@ For more information, refer to [action.yml](./action.yml) and the [GitHub Action
|
||||
|
||||
| Name | Value Type | Description |
|
||||
| --- | --- | --- |
|
||||
| `shell` | String | The shell to be used to run the commands. It defaults to `pwsh` on Windows and `bash` on Linux and macOS. Refer to [this](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell) for more information on available shell options. |
|
||||
| `source-dir` | Path | The source directory of the CMake project. It defaults to the current directory. |
|
||||
| `build-dir` | Path | The build directory of the CMake project. It defaults to the `build` directory inside the source directory. |
|
||||
| `generator` | String | The build system generator for the CMake project. It appends the CMake configuration arguments with `-G [val]`. |
|
||||
@ -40,6 +41,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
|
||||
@ -54,7 +61,7 @@ jobs:
|
||||
uses: actions/checkout@v3.5.3
|
||||
|
||||
- name: Configure the project
|
||||
uses: threeal/cmake-action@main
|
||||
uses: threeal/cmake-action@v1.3.0
|
||||
|
||||
- name: Build the project
|
||||
runs: cmake --build build
|
||||
@ -63,34 +70,33 @@ jobs:
|
||||
runs: ctest --test-dir build
|
||||
```
|
||||
|
||||
> **Note**: You can replace `@main` with any version you prefer. See [this](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsuses).
|
||||
|
||||
#### Specify the Source and Build Directories
|
||||
|
||||
```yaml
|
||||
- name: Configure the project
|
||||
uses: threeal/cmake-action@main
|
||||
with:
|
||||
source-dir: submodules
|
||||
build-dir: submodules/out
|
||||
```
|
||||
> **Note**: You can replace [`v1.3.0`](https://github.com/threeal/cmake-action/releases/tag/v1.3.0) with any version you prefer. See [this](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsuses).
|
||||
|
||||
#### Configure, Build, and Test in the Same Step
|
||||
|
||||
```yaml
|
||||
- name: Configure, build, and test the project
|
||||
uses: threeal/cmake-action@main
|
||||
uses: threeal/cmake-action@v1.3.0
|
||||
with:
|
||||
options: BUILD_TESTING=ON
|
||||
run-build: true
|
||||
run-test: true
|
||||
```
|
||||
|
||||
#### Specify the Source and Build Directories
|
||||
|
||||
```yaml
|
||||
- name: Configure the project
|
||||
uses: threeal/cmake-action@v1.3.0
|
||||
with:
|
||||
source-dir: submodules
|
||||
build-dir: submodules/out
|
||||
```
|
||||
|
||||
#### Using Ninja as the Generator and Clang as the Compiler
|
||||
|
||||
```yaml
|
||||
- name: Configure and build the project
|
||||
uses: threeal/cmake-action@main
|
||||
- name: Configure the project
|
||||
uses: threeal/cmake-action@v1.3.0
|
||||
with:
|
||||
generator: Ninja
|
||||
c-compiler: clang
|
||||
|
37
action.yml
37
action.yml
@ -1,10 +1,13 @@
|
||||
name: CMake Action
|
||||
description: Configure, build, and test a CMake project
|
||||
description: Configure, build, and test your CMake project
|
||||
author: Alfi Maulana
|
||||
branding:
|
||||
color: gray-dark
|
||||
icon: terminal
|
||||
inputs:
|
||||
shell:
|
||||
description: The shell to be used to run the commands
|
||||
required: false
|
||||
source-dir:
|
||||
description: The source directory of the CMake project
|
||||
required: false
|
||||
@ -46,13 +49,24 @@ 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: |
|
||||
if [ -n '${{ inputs.shell }}' ]; then
|
||||
SHELL='${{ inputs.shell }}'
|
||||
else
|
||||
SHELL='${{ runner.os == 'Windows' && 'pwsh' || 'bash' }}'
|
||||
fi
|
||||
echo "shell=$SHELL" >> $GITHUB_OUTPUT
|
||||
|
||||
SOURCE_DIR="."
|
||||
if [ -n '${{ inputs.source-dir }}' ]; then
|
||||
SOURCE_DIR="${{ inputs.source-dir }}"
|
||||
@ -64,6 +78,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 +102,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 +117,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
|
||||
@ -116,15 +131,15 @@ runs:
|
||||
esac
|
||||
|
||||
- name: Configure the CMake project
|
||||
shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }}
|
||||
run: cmake ${{ steps.process_inputs.outputs.cmake_args }}
|
||||
shell: ${{ steps.process-inputs.outputs.shell }}
|
||||
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 }}
|
||||
shell: ${{ steps.process-inputs.outputs.shell }}
|
||||
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 }}
|
||||
shell: ${{ steps.process-inputs.outputs.shell }}
|
||||
run: ctest ${{ steps.process-inputs.outputs.cmake-test-args }}
|
||||
|
Loading…
Reference in New Issue
Block a user