Skip to content

Commit

Permalink
feat: remove support for testing CMake projects (#256)
Browse files Browse the repository at this point in the history
* feat: remove `run-test` and `test-args` action inputs

* docs: remove description for supporting testing
  • Loading branch information
threeal authored Mar 22, 2024
1 parent b1c63dc commit ebf367c
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 79 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,26 +141,6 @@ jobs:
- name: Test Project
run: ctest --test-dir ${{ steps.cmake-action.outputs.build-dir }} --output-on-failure --no-tests=error -R test

test-action-with-run-test:
name: Test Action With Run Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4.1.2
with:
sparse-checkout: |
action.yml
dist
test
sparse-checkout-cone-mode: false

- name: Configure, Build, and Test Project
uses: ./
with:
source-dir: test
run-test: true
test-args: -R hello_world

test-action-with-additional-args:
name: Test Action With Additional Arguments
runs-on: ${{ matrix.compiler == 'msvc' && 'windows' || 'ubuntu' }}-latest
Expand All @@ -187,8 +167,6 @@ jobs:
options: CHECK_SURPASS_WARNING=ON
run-build: true
build-args: --target test_c --target test_cpp
run-test: true
test-args: -R test ${{ matrix.compiler == 'msvc' && '-C Debug' || '' }}

test-action-with-custom-tools:
name: Test Action With Custom Tools
Expand Down Expand Up @@ -217,5 +195,3 @@ jobs:
options: CHECK_USING_CLANG=ON
run-build: true
build-args: --target test_c --target test_cpp
run-test: true
test-args: -R test
13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# CMake Action

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.
Configure and build 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.

## Features

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

Expand All @@ -29,8 +28,6 @@ For more information, refer to [action.yml](./action.yml) and the [GitHub Action
| `args` | Multiple strings | Additional arguments to pass during the CMake configuration. |
| `run-build` | `true` or `false` | If enabled, it builds the project using CMake. It defaults to `false`. |
| `build-args` | Multiple strings | Additional arguments to pass during the CMake build. |
| `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`. |
| `test-args` | Multiple strings | Additional arguments to pass 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.
Expand Down Expand Up @@ -61,21 +58,17 @@ jobs:

- name: Build Project
runs: cmake --build build

- name: Test Project
runs: ctest --test-dir build
```
> **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
#### Configure and Build in the Same Step

```yaml
- name: Configure, Build, and Test Project
- name: Configure and Build Project
uses: threeal/cmake-action@v1.3.0
with:
run-build: true
run-test: true
```

#### Specify the Source and Build Directories
Expand Down
7 changes: 1 addition & 6 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: CMake Action
description: Configure, build, and test your CMake project
description: Configure and build your CMake project
author: Alfi Maulana
branding:
color: gray-dark
Expand Down Expand Up @@ -28,11 +28,6 @@ inputs:
default: false
build-args:
description: Additional arguments to pass during the CMake build
run-test:
description: If enabled, it runs testing using CTest (true/false)
default: false
test-args:
description: Additional arguments to pass during the CTest run
outputs:
build-dir:
description: The build directory of the CMake project
Expand Down
13 changes: 1 addition & 12 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 1 addition & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,9 @@ async function main() {
await exec("cmake", configureArgs);
core.setOutput("build-dir", inputs.buildDir);

if (inputs.runBuild || inputs.runTest) {
if (inputs.runBuild) {
await exec("cmake", ["--build", inputs.buildDir, ...inputs.buildArgs]);
}

if (inputs.runTest) {
await exec("ctest", [
"--test-dir",
inputs.buildDir,
"--output-on-failure",
"--no-tests=error",
...inputs.testArgs,
]);
}
}

main().catch((err) => core.setFailed(err));
12 changes: 0 additions & 12 deletions src/inputs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ describe("get action inputs", () => {
args: [],
runBuild: false,
buildArgs: [],
runTest: false,
testArgs: [],
});
});
});
Expand All @@ -51,8 +49,6 @@ describe("get action inputs", () => {
switch (name) {
case "run-build":
return true;
case "run-test":
return true;
}
throw new Error(`invalid input name: ${name}`);
});
Expand Down Expand Up @@ -88,8 +84,6 @@ describe("get action inputs", () => {
"some-build-args another-build-args",
"some-other-build-args",
];
case "test-args":
return ["some-test-args another-test-args", "some-other-test-args"];
}
throw new Error(`invalid input name: ${name}`);
});
Expand All @@ -116,12 +110,6 @@ describe("get action inputs", () => {
"another-build-args",
"some-other-build-args",
],
runTest: true,
testArgs: [
"some-test-args",
"another-test-args",
"some-other-test-args",
],
});
});
});
Expand Down
4 changes: 0 additions & 4 deletions src/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export interface Inputs {
args: string[];
runBuild: boolean;
buildArgs: string[];
runTest: boolean;
testArgs: string[];
}

export function getInputs(): Inputs {
Expand All @@ -31,7 +29,5 @@ export function getInputs(): Inputs {
buildArgs: getMultilineInput("build-args").flatMap((args) =>
args.split(" "),
),
testArgs: getMultilineInput("test-args").flatMap((args) => args.split(" ")),
runTest: getBooleanInput("run-test"),
};
}

0 comments on commit ebf367c

Please sign in to comment.