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

View File

@ -4,11 +4,12 @@
[![License](https://img.shields.io/github/license/threeal/cmake-action)](./LICENSE) [![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) [![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 ## 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. - 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. - 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.
@ -21,16 +22,17 @@ For more information, refer to [action.yml](./action.yml) and the [GitHub Action
| Name | Value Type | Description | | Name | Value Type | Description |
| --- | --- | --- | | --- | --- | --- |
| `source-dir` | Path | Source directory of the CMake project. Defaults to the current directory. | | `source-dir` | Path | The 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. | | `build-dir` | Path | The source directory of the CMake project.. Defaults to the `build` directory inside the source directory. |
| `targets` | Multiple strings | List of build targets. | | `targets` | Multiple strings | A list of build targets. |
| `generator` | String | Build system generator for the CMake project. | | `generator` | String | The build system generator for the CMake project. |
| `c-compiler` | String | Preferred executable for compiling C language files. | | `c-compiler` | String | The preferred executable for compiling C language files. |
| `cxx-compiler` | String | 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. | | `c-flags` | Multiple strings | Additional flags passed when compiling C language files. |
| `cxx-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. | | `args` | Multiple strings | Additional arguments passed during the 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`. | | `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. | | `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. > 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: build-project:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Check out this repository - name: Check out the repository
uses: actions/checkout@v3.3.0 uses: actions/checkout@v3.3.0
- name: Configure and build this project - name: Configure the project
uses: threeal/cmake-action@latest uses: threeal/cmake-action@latest
``` ```
@ -59,32 +61,34 @@ jobs:
#### Specify the Source and Build Directories #### Specify the Source and Build Directories
```yaml ```yaml
- name: Configure and build this project - name: Configure the project
uses: threeal/cmake-action@latest uses: threeal/cmake-action@latest
with: with:
source-dir: submodules source-dir: submodules
build-dir: submodules/out 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 #### Specify the Build Targets
```yaml ```yaml
- name: Configure and build this project - name: Configure and build this project
uses: threeal/cmake-action@latest uses: threeal/cmake-action@latest
with: with:
run-build: true
targets: hello_mars hello_sun 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 #### Using Ninja as the Generator and Clang as the Compiler
```yaml ```yaml

View File

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