Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 1.2.0 Release #49

Merged
merged 34 commits into from
Jun 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
b6684cd
Bump actions/checkout from 3.3.0 to 3.4.0
dependabot[bot] Mar 16, 2023
0bbf0f6
MERGE: pull request #37 from `threeal/dependabot/github_actions/actio…
threeal Mar 20, 2023
9ac87be
ci: add `chore` prefix in Dependabot commit message
threeal Mar 20, 2023
65da660
ci: `.gitignore` ignore all dot-prefixed files except for Git files
threeal Mar 20, 2023
86b3043
MERGE: pull request #38 from `threeal/modify-dependabot-commit`
threeal Mar 20, 2023
d84a2ac
MERGE: pull request #39 from `threeal/ignore-dotfiles`
threeal Mar 20, 2023
6a826ca
ci: trigger `test.yml` workflow on pull request and push only on late…
threeal Mar 21, 2023
f4c54a3
MERGE: pull request #40 from `threeal/modify-workflow-trigger`
threeal Mar 21, 2023
8e1c81b
chore: bump actions/checkout from 3.4.0 to 3.5.0
dependabot[bot] Mar 24, 2023
a3b01b2
MERGE: pull request #41 from `threeal/dependabot/github_actions/actio…
threeal Mar 26, 2023
76cdde0
chore: bump actions/checkout from 3.5.0 to 3.5.2
dependabot[bot] Apr 14, 2023
326a107
MERGE: pull request #43 from `threeal/dependabot/github_actions/actio…
threeal Apr 19, 2023
d9fbdd6
chore: bump actions/checkout from 3.5.2 to 3.5.3
dependabot[bot] Jun 12, 2023
45522e7
chore: merge pull request #44 from `threeal/dependabot/github_actions…
threeal Jun 23, 2023
c2edc89
docs: improve wordings in the `README.md`
threeal Jun 29, 2023
1d02cad
docs: improve wordings in the `CMakeLists.txt`
threeal Jun 29, 2023
39b214d
chore: Merge pull request #46 from `threeal/misc-chores`
threeal Jun 29, 2023
be11a3a
style: modify the order of `run-test` input
threeal Jun 29, 2023
3430da8
feat: add the `run-build` input
threeal Jun 29, 2023
f1910e1
feat: replace `targets` input with the more general `build-args` input
threeal Jun 29, 2023
62ad241
ci: expand jobs to test for `run-build` and `run-test` inputs
threeal Jun 29, 2023
b5b08ab
ci: disable fail fast in job with matrix strategy
threeal Jun 29, 2023
09bf642
ci: fix by specified test to run
threeal Jun 29, 2023
4e05d6c
ci: fix by specified test configuration on Windows
threeal Jun 29, 2023
cc3b1b7
feat: modify how build targets and run tests steps got enabled
threeal Jun 29, 2023
baf303f
ci: merge jobs for testing action with specified generator and compilers
threeal Jun 29, 2023
d0fef38
feat: auto enable `run-build` if `run-test` is enabled
threeal Jun 29, 2023
a320b8e
style: use a better step names in `test.yml` workflow
threeal Jun 29, 2023
75d5a71
docs: add cmake build and ctest steps example
threeal Jun 29, 2023
e774bd0
chore: merge pull request #47 from `threeal/default-to-no-build`
threeal Jun 29, 2023
f599e74
feat: add `options` input
threeal Jun 30, 2023
fc5e82e
docs: describe how each inputs append the CMake arguments
threeal Jun 30, 2023
ce8b638
docs: replace `@latest` with `@main`
threeal Jun 30, 2023
f1a0479
chore: merge pull request #48 from `threeal/add-options-input`
threeal Jun 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ updates:
directory: /
schedule:
interval: daily
commit-message:
prefix: chore
118 changes: 76 additions & 42 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,97 +1,131 @@
name: test
on:
workflow_dispatch:
pull_request:
push:
branches: [latest, main]
jobs:
default-usage:
runs-on: ${{ matrix.os }}-latest
strategy:
fail-fast: false
matrix:
os: [windows, ubuntu, macos]
steps:
- name: Check out this repository
uses: actions/checkout@v3.3.0
- name: Checkout the repository
uses: actions/checkout@v3.5.3

- name: Move test project to the working directory
- name: Move the test project to the working directory
run: mv test/* .

- name: Use this action
- name: Use the action
uses: ./

- name: Run the build result
run: ${{ matrix.os == 'windows' && 'build\Debug\hello_world.exe' || 'build/hello_world' }}
- 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' || '' }}

- name: Check on success
if: steps.failed-step.outcome == 'success'
run: exit 1

- 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' || '' }}

specified-dir-usage:
runs-on: ubuntu-latest
steps:
- name: Check out this repository
uses: actions/checkout@v3.3.0
- name: Checkout the repository
uses: actions/checkout@v3.5.3

- name: Use this action with specified directories
- name: Use the action with specified directories
uses: ./
with:
source-dir: test
build-dir: output
run-test: true
test-args: -R hello_world

- name: Check if the default build directory does not exist
run: test ! -d build && test ! -d test/build
shell: bash
run: test ! -e build && test ! -e test/build

- name: Build and test the project
run: |
cmake --build output
ctest --test-dir output --output-on-failure --no-tests=error -R hello_world

run-build-usage:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3.5.3

- name: Use the action with run build enabled
uses: ./
with:
source-dir: test
run-build: true
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-test-usage:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3.5.3

- name: Use the action with run test enabled
uses: ./
with:
source-dir: test
run-test: true
test-args: -R hello_world

additional-flags-usage:
runs-on: ${{ matrix.compiler == 'msvc' && 'windows' || 'ubuntu' }}-latest
strategy:
fail-fast: false
matrix:
compiler: [gcc, msvc]
steps:
- name: Check out this repository
uses: actions/checkout@v3.3.0
- name: Checkout the repository
uses: actions/checkout@v3.5.3

- name: Use this action with additional compiler flags
- name: Use the action with additional compiler flags
uses: ./
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
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' || '' }}

specified-compiler-usage:
specified-generator-and-compiler-usage:
runs-on: ${{ matrix.os }}-latest
strategy:
fail-fast: false
matrix:
os: [windows, ubuntu, macos]
steps:
- name: Check out this repository
uses: actions/checkout@v3.3.0
- name: Checkout the repository
uses: actions/checkout@v3.5.3

- name: Use this action with specified compilers
- name: Use the action with specified generator and compilers
uses: ./
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
test-args: -R test

specified-generator-usage:
runs-on: ${{ matrix.os }}-latest
strategy:
matrix:
os: [windows, ubuntu, macos]
steps:
- name: Check out this repository
uses: actions/checkout@v3.3.0

- name: Use this action with a specified generator
uses: ./
with:
source-dir: test
options: CHECK_USING_CLANG=ON
run-build: true
build-args: --target test_c --target test_cpp
run-test: true
generator: Ninja
test-args: -R hello_world
test-args: -R test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.*
!.git*

build
101 changes: 49 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,99 +1,96 @@
# CMake Action

[![latest version](https://img.shields.io/github/v/release/threeal/cmake-action)](https://github.com/threeal/cmake-action/releases/)
[![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)
[![Latest Version](https://img.shields.io/github/v/release/threeal/cmake-action)](https://github.com/threeal/cmake-action/releases/)
[![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 a [CMake](https://cmake.org/) project on [GitHub Actions](https://github.com/features/actions).
Use this action to simplify the workflow run of your CMake project.
This action will configure a build environment for your project using the `cmake` command,
then it will build your project by running a `cmake --build` command,
and last it could test your 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

- Configure and build a project using the [cmake](https://cmake.org/cmake/help/latest/manual/cmake.1.html) command.
- Optionally test a project using the [ctest](https://cmake.org/cmake/help/latest/manual/ctest.1.html) command.
- Auto-detect and install required dependencies.
- Specify multiple CMake options directly from the Action inputs.
- 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.

## Usage

For more information, see [action.yml](./action.yml) and [GitHub Actions guide](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions).
For more information, refer to [action.yml](./action.yml) and the [GitHub Actions guide](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions).

### Inputs

| Name | Value Type | Description |
| --- | --- | --- |
| `source-dir` | Path | Source directory of the CMake project. Defaults to current directory. |
| `build-dir` | Path | Build directory of the CMake project. Defaults to `build` directory inside the source directory. |
| `targets` | Multiple strings | List of build targets. |
| `run-test` | `true` or `false` | If enabled, run testing using [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html). Defaults to `false`. |
| `generator` | String | Build system generator of the CMake project. |
| `c-compiler` | String | Preferred executable for compiling C language files. |
| `cxx-compiler` | String | 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 the CMake configuration. |
| `test-args` | Multiple strings | Additional arguments passed during the CTest run. |

> Note: Multiple strings mean that the input could be specified with more than one value. Separate each value with a space or a new line.

> Note: All inputs are optional.
| `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]`. |
| `c-compiler` | String | The preferred executable for compiling C language files. It appends the CMake configuration arguments with `-D CMAKE_C_COMPILER=[val]`. |
| `cxx-compiler` | String | The preferred executable for compiling C++ language files. It appends the CMake configuration arguments with `-D CMAKE_CXX_COMPILER=[val]`. |
| `c-flags` | Multiple strings | Additional flags to pass when compiling C language files. It appends the CMake configuration arguments with `-D CMAKE_C_FLAGS=[vals]`. |
| `cxx-flags` | Multiple strings | Additional flags to pass when compiling C++ language files. It appends the CMake configuration arguments with `-D CMAKE_CXX_FLAGS=[vals]`. |
| `options` | Multiple strings | Additional options to pass during the CMake configuration. It appends the CMake configuration arguments with each of `-D [val]`. |
| `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.

> **Note**: All inputs are optional.

### Examples

```yaml
name: build
name: Build
on:
push:
jobs:
build-project:
runs-on: ubuntu-latest
steps:
- name: Check out this repository
uses: actions/checkout@v3.3.0
- name: Checkout the repository
uses: actions/checkout@v3.5.3

- name: Configure and build this project
uses: threeal/cmake-action@latest
- name: Configure the project
uses: threeal/cmake-action@main

- name: Build the project
runs: cmake --build build

- name: Test the project
runs: ctest --test-dir build
```

> Note: You can replace `@latest` with any version you like. See [this](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsuses).
> **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 the Build Directories
#### Specify the Source and Build Directories

```yaml
- name: Configure and build this project
uses: threeal/cmake-action@latest
- name: Configure the project
uses: threeal/cmake-action@main
with:
source-dir: submodules
build-dir: submodules/out
```

#### Specify the Build Targets

```yaml
- name: Configure and build this project
uses: threeal/cmake-action@latest
with:
targets: hello_mars hello_sun
```

#### Run Unit Tests After Build
#### Configure, Build, and Test in the Same Step

```yaml
- name: Configure, build, and test this project
uses: threeal/cmake-action@latest
- name: Configure, build, and test the project
uses: threeal/cmake-action@main
with:
args: -DBUILD_TESTING=ON
options: BUILD_TESTING=ON
run-build: true
run-test: true
```

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

```yaml
- name: Configure and build this project
uses: threeal/cmake-action@latest
- name: Configure and build the project
uses: threeal/cmake-action@main
with:
generator: Ninja
c-compiler: clang
Expand Down
Loading