Skip to content

Commit e774bd0

Browse files
authored
chore: merge pull request #47 from threeal/default-to-no-build
Default to No Build
2 parents 39b214d + 75d5a71 commit e774bd0

File tree

3 files changed

+137
-95
lines changed

3 files changed

+137
-95
lines changed

.github/workflows/test.yml

Lines changed: 68 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,92 +8,124 @@ jobs:
88
default-usage:
99
runs-on: ${{ matrix.os }}-latest
1010
strategy:
11+
fail-fast: false
1112
matrix:
1213
os: [windows, ubuntu, macos]
1314
steps:
14-
- name: Check out this repository
15+
- name: Checkout the repository
1516
uses: actions/[email protected]
1617

17-
- name: Move test project to the working directory
18+
- name: Move the test project to the working directory
1819
run: mv test/* .
1920

20-
- name: Use this action
21+
- name: Use the action
2122
uses: ./
2223

23-
- name: Run the build result
24-
run: ${{ matrix.os == 'windows' && 'build\Debug\hello_world.exe' || 'build/hello_world' }}
24+
- name: Try to test the project
25+
id: failed-step
26+
continue-on-error: true
27+
run: ctest --test-dir build --output-on-failure --no-tests=error -R hello_world ${{ matrix.os == 'windows' && '-C Debug' || '' }}
28+
29+
- name: Check on success
30+
if: steps.failed-step.outcome == 'success'
31+
run: exit 1
32+
33+
- name: Build and test the project
34+
run: |
35+
cmake --build build
36+
ctest --test-dir build --output-on-failure --no-tests=error -R hello_world ${{ matrix.os == 'windows' && '-C Debug' || '' }}
2537
2638
specified-dir-usage:
2739
runs-on: ubuntu-latest
2840
steps:
29-
- name: Check out this repository
41+
- name: Checkout the repository
3042
uses: actions/[email protected]
3143

32-
- name: Use this action with specified directories
44+
- name: Use the action with specified directories
3345
uses: ./
3446
with:
3547
source-dir: test
3648
build-dir: output
37-
run-test: true
38-
test-args: -R hello_world
3949

4050
- name: Check if the default build directory does not exist
41-
run: test ! -d build && test ! -d test/build
51+
shell: bash
52+
run: test ! -e build && test ! -e test/build
53+
54+
- name: Build and test the project
55+
run: |
56+
cmake --build output
57+
ctest --test-dir output --output-on-failure --no-tests=error -R hello_world
58+
59+
run-build-usage:
60+
runs-on: ubuntu-latest
61+
steps:
62+
- name: Checkout the repository
63+
uses: actions/[email protected]
64+
65+
- name: Use the action with run build enabled
66+
uses: ./
67+
with:
68+
source-dir: test
69+
run-build: true
70+
build-args: --target test_c --target test_cpp
71+
72+
- name: Test the project
73+
run: ctest --test-dir test/build --output-on-failure --no-tests=error -R test
74+
75+
run-test-usage:
76+
runs-on: ubuntu-latest
77+
steps:
78+
- name: Checkout the repository
79+
uses: actions/[email protected]
80+
81+
- name: Use the action with run test enabled
82+
uses: ./
83+
with:
84+
source-dir: test
85+
run-test: true
86+
test-args: -R hello_world
4287

4388
additional-flags-usage:
4489
runs-on: ${{ matrix.compiler == 'msvc' && 'windows' || 'ubuntu' }}-latest
4590
strategy:
91+
fail-fast: false
4692
matrix:
4793
compiler: [gcc, msvc]
4894
steps:
49-
- name: Check out this repository
95+
- name: Checkout the repository
5096
uses: actions/[email protected]
5197

52-
- name: Use this action with additional compiler flags
98+
- name: Use the action with additional compiler flags
5399
uses: ./
54100
with:
55101
source-dir: test
56-
targets: test_c test_cpp
57-
run-test: true
58102
c-flags: ${{ matrix.compiler == 'msvc' && '/w /WX-' || '-Wno-unused-variable' }}
59103
cxx-flags: ${{ matrix.compiler == 'msvc' && '/w /WX-' || '-Wno-unused-variable' }}
60104
args: -D CHECK_SURPASS_WARNING=ON
105+
run-build: true
106+
build-args: --target test_c --target test_cpp
107+
run-test: true
61108
test-args: -R test ${{ matrix.compiler == 'msvc' && '-C Debug' || '' }}
62109

63-
specified-compiler-usage:
110+
specified-generator-and-compiler-usage:
64111
runs-on: ${{ matrix.os }}-latest
65112
strategy:
113+
fail-fast: false
66114
matrix:
67115
os: [windows, ubuntu, macos]
68116
steps:
69-
- name: Check out this repository
117+
- name: Checkout the repository
70118
uses: actions/[email protected]
71119

72-
- name: Use this action with specified compilers
120+
- name: Use the action with specified generator and compilers
73121
uses: ./
74122
with:
75123
source-dir: test
76-
targets: test_c test_cpp
77-
run-test: true
78124
generator: Ninja
79125
c-compiler: clang
80126
cxx-compiler: clang++
81127
args: -D CHECK_USING_CLANG=ON
82-
test-args: -R test
83-
84-
specified-generator-usage:
85-
runs-on: ${{ matrix.os }}-latest
86-
strategy:
87-
matrix:
88-
os: [windows, ubuntu, macos]
89-
steps:
90-
- name: Check out this repository
91-
uses: actions/[email protected]
92-
93-
- name: Use this action with a specified generator
94-
uses: ./
95-
with:
96-
source-dir: test
128+
run-build: true
129+
build-args: --target test_c --target test_cpp
97130
run-test: true
98-
generator: Ninja
99-
test-args: -R hello_world
131+
test-args: -R test

README.md

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
[![License](https://img.shields.io/github/license/threeal/cmake-action)](./LICENSE)
55
[![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)
66

7-
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.
7+
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.
88

99
## Features
1010

11-
- Configures and builds a project using the [cmake](https://cmake.org/cmake/help/latest/manual/cmake.1.html) command.
12-
- Option to test a project using the [ctest](https://cmake.org/cmake/help/latest/manual/ctest.1.html) command.
11+
- Configures a project using the [`cmake`](https://cmake.org/cmake/help/latest/manual/cmake.1.html) command.
12+
- Option to build a project using the `cmake --build` command.
13+
- Option to test a project using the [`ctest`](https://cmake.org/cmake/help/latest/manual/ctest.1.html) command.
1314
- Auto-detects and installs required dependencies.
1415
- Supports specifying multiple CMake options directly from the Action inputs.
1516

@@ -21,17 +22,18 @@ For more information, refer to [action.yml](./action.yml) and the [GitHub Action
2122

2223
| Name | Value Type | Description |
2324
| --- | --- | --- |
24-
| `source-dir` | Path | Source directory of the CMake project. Defaults to the current directory. |
25-
| `build-dir` | Path | Build directory of the CMake project. Defaults to the `build` directory inside the source directory. |
26-
| `targets` | Multiple strings | List of build targets. |
27-
| `run-test` | `true` or `false` | If enabled, runs testing using [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html). Defaults to `false`. |
28-
| `generator` | String | Build system generator for the CMake project. |
29-
| `c-compiler` | String | Preferred executable for compiling C language files. |
30-
| `cxx-compiler` | String | Preferred executable for compiling C++ language files. |
31-
| `c-flags` | Multiple strings | Additional flags passed when compiling C language files. |
32-
| `cxx-flags` | Multiple strings | Additional flags passed when compiling C++ language files. |
33-
| `args` | Multiple strings | Additional arguments passed during CMake configuration. |
34-
| `test-args` | Multiple strings | Additional arguments passed during the CTest run. |
25+
| `source-dir` | Path | The source directory of the CMake project. It defaults to the current directory. |
26+
| `build-dir` | Path | The build directory of the CMake project. It defaults to the `build` directory inside the source directory. |
27+
| `generator` | String | The build system generator for the CMake project. |
28+
| `c-compiler` | String | The preferred executable for compiling C language files. |
29+
| `cxx-compiler` | String | The preferred executable for compiling C++ language files. |
30+
| `c-flags` | Multiple strings | Additional flags to pass when compiling C language files. |
31+
| `cxx-flags` | Multiple strings | Additional flags to pass when compiling C++ language files. |
32+
| `args` | Multiple strings | Additional arguments to pass during the CMake configuration. |
33+
| `run-build` | `true` or `false` | If enabled, it builds the project using [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html). It defaults to `false`. |
34+
| `build-args` | Multiple strings | Additional arguments to pass during the CMake build. |
35+
| `run-test` | `true` or `false` | If enabled, it runs testing using [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html). It defaults to `false`. |
36+
| `test-args` | Multiple strings | Additional arguments to pass during the CTest run. |
3537

3638
> 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.
3739
@@ -47,48 +49,46 @@ jobs:
4749
build-project:
4850
runs-on: ubuntu-latest
4951
steps:
50-
- name: Check out this repository
52+
- name: Checkout the repository
5153
uses: actions/[email protected]
5254

53-
- name: Configure and build this project
55+
- name: Configure the project
5456
uses: threeal/cmake-action@latest
57+
58+
- name: Build the project
59+
runs: cmake --build build
60+
61+
- name: Test the project
62+
runs: ctest --test-dir build
5563
```
5664
5765
> Note: You can replace `@latest` with any version you prefer. See [this](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsuses).
5866

5967
#### Specify the Source and Build Directories
6068

6169
```yaml
62-
- name: Configure and build this project
70+
- name: Configure the project
6371
uses: threeal/cmake-action@latest
6472
with:
6573
source-dir: submodules
6674
build-dir: submodules/out
6775
```
6876

69-
#### Specify the Build Targets
70-
71-
```yaml
72-
- name: Configure and build this project
73-
uses: threeal/cmake-action@latest
74-
with:
75-
targets: hello_mars hello_sun
76-
```
77-
78-
#### Run Unit Tests After Build
77+
#### Configure, Build, and Test in the Same Step
7978

8079
```yaml
81-
- name: Configure, build, and test this project
80+
- name: Configure, build, and test the project
8281
uses: threeal/cmake-action@latest
8382
with:
8483
args: -DBUILD_TESTING=ON
84+
run-build: true
8585
run-test: true
8686
```
8787

8888
#### Using Ninja as the Generator and Clang as the Compiler
8989

9090
```yaml
91-
- name: Configure and build this project
91+
- name: Configure and build the project
9292
uses: threeal/cmake-action@latest
9393
with:
9494
generator: Ninja

action.yml

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,42 @@ branding:
66
icon: terminal
77
inputs:
88
source-dir:
9-
description: Source directory of the CMake project
9+
description: The source directory of the CMake project
1010
required: false
1111
build-dir:
12-
description: Build directory of the CMake project
12+
description: The build directory of the CMake project
1313
required: false
14-
targets:
15-
description: List of build targets
16-
required: false
17-
run-test:
18-
description: If enabled, run testing using CTest (true/false)
19-
required: false
20-
default: false
2114
generator:
22-
description: Build system generator of the CMake project
15+
description: The build system generator for the CMake project
2316
required: false
2417
c-compiler:
25-
description: Preferred executable for compiling C language files
18+
description: The preferred executable for compiling C language files
2619
required: false
2720
cxx-compiler:
28-
description: Preferred executable for compiling C++ language files
21+
description: The preferred executable for compiling C++ language files
2922
required: false
3023
c-flags:
31-
description: Additional flags passed when compiling C language files
24+
description: Additional flags to pass when compiling C language files
3225
required: false
3326
cxx-flags:
34-
description: Additional flags passed when compiling C++ language files
27+
description: Additional flags to pass when compiling C++ language files
3528
required: false
3629
args:
37-
description: Additional arguments passed during the CMake configuration
30+
description: Additional arguments to pass during the CMake configuration
31+
required: false
32+
run-build:
33+
description: If enabled, it builds the project using CMake (true/false)
34+
required: false
35+
default: false
36+
build-args:
37+
description: Additional arguments to pass during the CMake build
38+
required: false
39+
run-test:
40+
description: If enabled, it runs testing using CTest (true/false)
3841
required: false
42+
default: false
3943
test-args:
40-
description: Additional arguments passed during the CTest run
44+
description: Additional arguments to pass during the CTest run
4145
required: false
4246
runs:
4347
using: composite
@@ -50,21 +54,15 @@ runs:
5054
if [ -n '${{ inputs.source-dir }}' ]; then
5155
SOURCE_DIR="${{ inputs.source-dir }}"
5256
fi
57+
5358
BUILD_DIR="build"
5459
if [ -n '${{ inputs.build-dir }}' ]; then
5560
BUILD_DIR="${{ inputs.build-dir }}"
5661
elif [ -n "${{ inputs.source-dir }}" ]; then
5762
BUILD_DIR="${{ inputs.source-dir }}/build"
5863
fi
64+
5965
ARGS="'$SOURCE_DIR' -B '$BUILD_DIR'"
60-
BUILD_ARGS="--build '$BUILD_DIR'"
61-
TEST_ARGS=""
62-
if [ -n '${{ inputs.targets }}' ]; then
63-
BUILD_ARGS="$BUILD_ARGS --target ${{ inputs.targets }}"
64-
fi
65-
if [ '${{ inputs.run-test }}' == 'true' ]; then
66-
TEST_ARGS="--test-dir '$BUILD_DIR' --output-on-failure --no-tests=error"
67-
fi
6866
if [ -n '${{ inputs.generator }}' ]; then
6967
ARGS="$ARGS -G '${{ inputs.generator }}'"
7068
fi
@@ -83,12 +81,23 @@ runs:
8381
if [ -n '${{ inputs.args }}' ]; then
8482
ARGS="$ARGS ${{ inputs.args }}"
8583
fi
86-
if [ -n '${{ inputs.test-args }}' ]; then
87-
TEST_ARGS="$TEST_ARGS ${{ inputs.test-args }}"
88-
fi
8984
echo "cmake_args=${ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
90-
echo "cmake_build_args=${BUILD_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
91-
echo "cmake_test_args=${TEST_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
85+
86+
if [ '${{ inputs.run-build }}' == 'true' ] || [ '${{ inputs.run-test }}' == 'true' ]; then
87+
BUILD_ARGS="--build '$BUILD_DIR'"
88+
if [ -n '${{ inputs.build-args }}' ]; then
89+
BUILD_ARGS="$BUILD_ARGS ${{ inputs.build-args }}"
90+
fi
91+
echo "cmake_build_args=${BUILD_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
92+
fi
93+
94+
if [ '${{ inputs.run-test }}' == 'true' ]; then
95+
TEST_ARGS="--test-dir '$BUILD_DIR' --output-on-failure --no-tests=error"
96+
if [ -n '${{ inputs.test-args }}' ]; then
97+
TEST_ARGS="$TEST_ARGS ${{ inputs.test-args }}"
98+
fi
99+
echo "cmake_test_args=${TEST_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
100+
fi
92101
93102
- name: Install Ninja
94103
if: ${{ inputs.generator == 'Ninja' }}
@@ -105,10 +114,11 @@ runs:
105114
run: cmake ${{ steps.process_inputs.outputs.cmake_args }}
106115

107116
- name: Build targets
117+
if: inputs.run-build != 'false' || inputs.run-test != 'false'
108118
shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }}
109119
run: cmake ${{ steps.process_inputs.outputs.cmake_build_args }}
110120

111121
- name: Run tests
112-
if: steps.process_inputs.outputs.cmake_test_args != ''
122+
if: inputs.run-test != 'false'
113123
shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }}
114124
run: ctest ${{ steps.process_inputs.outputs.cmake_test_args }}

0 commit comments

Comments
 (0)