feat: add the run-build input

This commit is contained in:
Alfi Maulana 2023-06-29 19:17:47 +07:00
parent be11a3a3dd
commit 3430da8dad
No known key found for this signature in database
GPG Key ID: 2242A64C2A8DF5A4
3 changed files with 61 additions and 38 deletions

View File

@ -19,6 +19,8 @@ jobs:
- name: Use this action
uses: ./
with:
run-build: true
- name: Run the build result
run: ${{ matrix.os == 'windows' && 'build\Debug\hello_world.exe' || 'build/hello_world' }}
@ -34,6 +36,7 @@ jobs:
with:
source-dir: test
build-dir: output
run-build: true
run-test: true
test-args: -R hello_world
@ -54,10 +57,11 @@ jobs:
with:
source-dir: test
targets: test_c test_cpp
run-test: true
c-flags: ${{ matrix.compiler == 'msvc' && '/w /WX-' || '-Wno-unused-variable' }}
cxx-flags: ${{ matrix.compiler == 'msvc' && '/w /WX-' || '-Wno-unused-variable' }}
args: -D CHECK_SURPASS_WARNING=ON
run-build: true
run-test: true
test-args: -R test ${{ matrix.compiler == 'msvc' && '-C Debug' || '' }}
specified-compiler-usage:
@ -74,11 +78,12 @@ jobs:
with:
source-dir: test
targets: test_c test_cpp
run-test: true
generator: Ninja
c-compiler: clang
cxx-compiler: clang++
args: -D CHECK_USING_CLANG=ON
run-build: true
run-test: true
test-args: -R test
specified-generator-usage:
@ -94,6 +99,7 @@ jobs:
uses: ./
with:
source-dir: test
run-test: true
generator: Ninja
run-build: true
run-test: true
test-args: -R hello_world

View File

@ -4,11 +4,12 @@
[![License](https://img.shields.io/github/license/threeal/cmake-action)](./LICENSE)
[![Test Status](https://img.shields.io/github/actions/workflow/status/threeal/cmake-action/test.yml?label=test&branch=main)](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, builds the project using the `cmake --build` command, and optionally 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 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.
## Features
- Configures and builds a project using the [cmake](https://cmake.org/cmake/help/latest/manual/cmake.1.html) command.
- 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.
- Auto-detects and installs required dependencies.
- Supports specifying multiple CMake options directly from the Action inputs.
@ -21,16 +22,17 @@ For more information, refer to [action.yml](./action.yml) and the [GitHub Action
| Name | Value Type | Description |
| --- | --- | --- |
| `source-dir` | Path | Source directory of the CMake project. Defaults to the current directory. |
| `build-dir` | Path | Build directory of the CMake project. Defaults to the `build` directory inside the source directory. |
| `targets` | Multiple strings | List of build targets. |
| `generator` | String | Build system generator for the CMake project. |
| `c-compiler` | String | Preferred executable for compiling C language files. |
| `cxx-compiler` | String | Preferred executable for compiling C++ language files. |
| `source-dir` | Path | The source directory of the CMake project. Defaults to the current directory. |
| `build-dir` | Path | The source directory of the CMake project.. Defaults to the `build` directory inside the source directory. |
| `targets` | Multiple strings | A list of build targets. |
| `generator` | String | The build system generator for the CMake project. |
| `c-compiler` | String | The preferred executable for compiling C language files. |
| `cxx-compiler` | String | The preferred executable for compiling C++ language files. |
| `c-flags` | Multiple strings | Additional flags passed when compiling C language files. |
| `cxx-flags` | Multiple strings | Additional flags passed when compiling C++ language files. |
| `args` | Multiple strings | Additional arguments passed during CMake configuration. |
| `run-test` | `true` or `false` | If enabled, runs testing using [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html). Defaults to `false`. |
| `args` | Multiple strings | Additional arguments passed during the CMake configuration. |
| `run-build` | `true` or `false` | If enabled, it builds the project using [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html). Defaults to `false`. |
| `run-test` | `true` or `false` | If enabled, it runs testing using [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html). Defaults to `false`. |
| `test-args` | Multiple strings | Additional arguments passed during the CTest run. |
> Note: Multiple strings mean that the input can be specified with more than one value. Separate each value with a space or a new line.
@ -47,10 +49,10 @@ jobs:
build-project:
runs-on: ubuntu-latest
steps:
- name: Check out this repository
- name: Check out the repository
uses: actions/checkout@v3.3.0
- name: Configure and build this project
- name: Configure the project
uses: threeal/cmake-action@latest
```
@ -59,32 +61,34 @@ jobs:
#### Specify the Source and Build Directories
```yaml
- name: Configure and build this project
- name: Configure the project
uses: threeal/cmake-action@latest
with:
source-dir: submodules
build-dir: submodules/out
```
#### Configure, Build, and Test in the Same Step
```yaml
- name: Configure, build, and test the project
uses: threeal/cmake-action@latest
with:
args: -DBUILD_TESTING=ON
run-build: true
run-test: true
```
#### Specify the Build Targets
```yaml
- name: Configure and build this project
uses: threeal/cmake-action@latest
with:
run-build: true
targets: hello_mars hello_sun
```
#### Run Unit Tests After Build
```yaml
- name: Configure, build, and test this project
uses: threeal/cmake-action@latest
with:
args: -DBUILD_TESTING=ON
run-test: true
```
#### Using Ninja as the Generator and Clang as the Compiler
```yaml

View File

@ -6,22 +6,22 @@ branding:
icon: terminal
inputs:
source-dir:
description: Source directory of the CMake project
description: The source directory of the CMake project
required: false
build-dir:
description: Build directory of the CMake project
description: The source directory of the CMake project.
required: false
targets:
description: List of build targets
description: A list of build targets
required: false
generator:
description: Build system generator of the CMake project
description: The build system generator for the CMake project
required: false
c-compiler:
description: Preferred executable for compiling C language files
description: The preferred executable for compiling C language files
required: false
cxx-compiler:
description: Preferred executable for compiling C++ language files
description: The preferred executable for compiling C++ language files
required: false
c-flags:
description: Additional flags passed when compiling C language files
@ -32,8 +32,12 @@ inputs:
args:
description: Additional arguments passed during the CMake configuration
required: false
run-build:
description: If enabled, it builds the project using CMake (true/false)
required: false
default: false
run-test:
description: If enabled, run testing using CTest (true/false)
description: If enabled, it runs testing using CTest (true/false)
required: false
default: false
test-args:
@ -50,18 +54,15 @@ runs:
if [ -n '${{ inputs.source-dir }}' ]; then
SOURCE_DIR="${{ inputs.source-dir }}"
fi
BUILD_DIR="build"
if [ -n '${{ inputs.build-dir }}' ]; then
BUILD_DIR="${{ inputs.build-dir }}"
elif [ -n "${{ inputs.source-dir }}" ]; then
BUILD_DIR="${{ inputs.source-dir }}/build"
fi
ARGS="'$SOURCE_DIR' -B '$BUILD_DIR'"
BUILD_ARGS="--build '$BUILD_DIR'"
TEST_ARGS=""
if [ -n '${{ inputs.targets }}' ]; then
BUILD_ARGS="$BUILD_ARGS --target ${{ inputs.targets }}"
fi
if [ -n '${{ inputs.generator }}' ]; then
ARGS="$ARGS -G '${{ inputs.generator }}'"
fi
@ -80,12 +81,23 @@ runs:
if [ -n '${{ inputs.args }}' ]; then
ARGS="$ARGS ${{ inputs.args }}"
fi
BUILD_ARGS=""
if [ '${{ inputs.run-build }}' == 'true' ]; then
BUILD_ARGS="--build '$BUILD_DIR'"
fi
if [ -n '${{ inputs.targets }}' ]; then
BUILD_ARGS="$BUILD_ARGS --target ${{ inputs.targets }}"
fi
TEST_ARGS=""
if [ '${{ inputs.run-test }}' == 'true' ]; then
TEST_ARGS="--test-dir '$BUILD_DIR' --output-on-failure --no-tests=error"
fi
if [ -n '${{ inputs.test-args }}' ]; then
TEST_ARGS="$TEST_ARGS ${{ inputs.test-args }}"
fi
echo "cmake_args=${ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
echo "cmake_build_args=${BUILD_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
echo "cmake_test_args=${TEST_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
@ -105,6 +117,7 @@ runs:
run: cmake ${{ steps.process_inputs.outputs.cmake_args }}
- name: Build targets
if: steps.process_inputs.outputs.cmake_build_args != ''
shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }}
run: cmake ${{ steps.process_inputs.outputs.cmake_build_args }}