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.3.0 Release #55

Merged
merged 13 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 22 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,22 @@ jobs:
run: mv test/* .

- name: Use the action
id: cmake-action
uses: ./

- 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' || '' }}
run: ctest --test-dir ${{ steps.cmake-action.outputs.build-dir }} --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' || '' }}
cmake --build ${{ steps.cmake-action.outputs.build-dir }}
ctest --test-dir ${{ steps.cmake-action.outputs.build-dir }} --output-on-failure --no-tests=error -R hello_world ${{ matrix.os == 'windows' && '-C Debug' || '' }}

specified-dir-usage:
runs-on: ubuntu-latest
Expand All @@ -42,6 +43,7 @@ jobs:
uses: actions/[email protected]

- name: Use the action with specified directories
id: cmake-action
uses: ./
with:
source-dir: test
Expand All @@ -53,8 +55,8 @@ jobs:

- name: Build and test the project
run: |
cmake --build output
ctest --test-dir output --output-on-failure --no-tests=error -R hello_world
cmake --build ${{ steps.cmake-action.outputs.build-dir }}
ctest --test-dir ${{ steps.cmake-action.outputs.build-dir }} --output-on-failure --no-tests=error -R hello_world

run-build-usage:
runs-on: ubuntu-latest
Expand All @@ -63,14 +65,15 @@ jobs:
uses: actions/[email protected]

- name: Use the action with run build enabled
id: cmake-action
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: ctest --test-dir ${{ steps.cmake-action.outputs.build-dir }} --output-on-failure --no-tests=error -R test

run-test-usage:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -129,3 +132,16 @@ jobs:
build-args: --target test_c --target test_cpp
run-test: true
test-args: -R test

specified-shell:
runs-on: windows-latest
steps:
- name: Checkout the repository
uses: actions/[email protected]

- name: Use the action with specified shell
uses: ./
with:
shell: bash
source-dir: test
run-build: true
46 changes: 26 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
[![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, and optionally builds the project using the `cmake --build` command and 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 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.

## Features

- 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.
- 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.
- Supports specifying multiple CMake options directly from the action inputs.

## Usage

Expand All @@ -22,6 +22,7 @@ For more information, refer to [action.yml](./action.yml) and the [GitHub Action

| Name | Value Type | Description |
| --- | --- | --- |
| `shell` | String | The shell to be used to run the commands. It defaults to `pwsh` on Windows and `bash` on Linux and macOS. Refer to [this](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell) for more information on available shell options. |
| `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]`. |
Expand All @@ -40,6 +41,12 @@ For more information, refer to [action.yml](./action.yml) and the [GitHub Action

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

### Outputs

| Name | Value Type | Description |
| --- | --- | --- |
| `build-dir` | Path | The build directory of the CMake project. |

### Examples

```yaml
Expand All @@ -54,7 +61,7 @@ jobs:
uses: actions/[email protected]

- name: Configure the project
uses: threeal/cmake-action@main
uses: threeal/cmake-action@v1.3.0

- name: Build the project
runs: cmake --build build
Expand All @@ -63,34 +70,33 @@ jobs:
runs: ctest --test-dir build
```

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

#### Specify the Source and Build Directories
#### Configure, Build, and Test in the Same Step

```yaml
- name: Configure the project
uses: threeal/cmake-action@main
- name: Configure, build, and test the project
uses: threeal/cmake-action@v1.3.0
with:
source-dir: submodules
build-dir: submodules/out
run-build: true
run-test: true
```

#### Configure, Build, and Test in the Same Step
#### Specify the Source and Build Directories

```yaml
- name: Configure, build, and test the project
uses: threeal/cmake-action@main
- name: Configure the project
uses: threeal/cmake-action@v1.3.0
with:
options: BUILD_TESTING=ON
run-build: true
run-test: true
source-dir: submodules
build-dir: submodules/out
```

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

```yaml
- name: Configure and build the project
uses: threeal/cmake-action@main
- name: Configure the project
uses: threeal/cmake-action@v1.3.0
with:
generator: Ninja
c-compiler: clang
Expand Down
37 changes: 26 additions & 11 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
name: CMake Action
description: Configure, build, and test a CMake project
description: Configure, build, and test your CMake project
author: Alfi Maulana
branding:
color: gray-dark
icon: terminal
inputs:
shell:
description: The shell to be used to run the commands
required: false
source-dir:
description: The source directory of the CMake project
required: false
Expand Down Expand Up @@ -46,13 +49,24 @@ inputs:
test-args:
description: Additional arguments to pass during the CTest run
required: false
outputs:
build-dir:
description: The build directory of the CMake project
value: ${{ steps.process-inputs.outputs.build-dir }}
runs:
using: composite
steps:
- name: Process the inputs
id: process_inputs
id: process-inputs
shell: bash
run: |
if [ -n '${{ inputs.shell }}' ]; then
SHELL='${{ inputs.shell }}'
else
SHELL='${{ runner.os == 'Windows' && 'pwsh' || 'bash' }}'
fi
echo "shell=$SHELL" >> $GITHUB_OUTPUT

SOURCE_DIR="."
if [ -n '${{ inputs.source-dir }}' ]; then
SOURCE_DIR="${{ inputs.source-dir }}"
Expand All @@ -64,6 +78,7 @@ runs:
elif [ -n "${{ inputs.source-dir }}" ]; then
BUILD_DIR="${{ inputs.source-dir }}/build"
fi
echo "build-dir=$BUILD_DIR" >> $GITHUB_OUTPUT

ARGS="'$SOURCE_DIR' -B '$BUILD_DIR'"
if [ -n '${{ inputs.generator }}' ]; then
Expand All @@ -87,22 +102,22 @@ runs:
if [ -n '${{ inputs.args }}' ]; then
ARGS="$ARGS ${{ inputs.args }}"
fi
echo "cmake_args=${ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
echo "cmake-args=${ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT

if [ '${{ inputs.run-build }}' == 'true' ] || [ '${{ inputs.run-test }}' == 'true' ]; then
BUILD_ARGS="--build '$BUILD_DIR'"
if [ -n '${{ inputs.build-args }}' ]; then
BUILD_ARGS="$BUILD_ARGS ${{ inputs.build-args }}"
fi
echo "cmake_build_args=${BUILD_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
echo "cmake-build-args=${BUILD_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
fi

if [ '${{ inputs.run-test }}' == 'true' ]; then
TEST_ARGS="--test-dir '$BUILD_DIR' --output-on-failure --no-tests=error"
if [ -n '${{ inputs.test-args }}' ]; then
TEST_ARGS="$TEST_ARGS ${{ inputs.test-args }}"
fi
echo "cmake_test_args=${TEST_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
echo "cmake-test-args=${TEST_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
fi

- name: Install Ninja
Expand All @@ -116,15 +131,15 @@ runs:
esac

- name: Configure the CMake project
shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }}
run: cmake ${{ steps.process_inputs.outputs.cmake_args }}
shell: ${{ steps.process-inputs.outputs.shell }}
run: cmake ${{ steps.process-inputs.outputs.cmake-args }}

- name: Build targets
if: inputs.run-build != 'false' || inputs.run-test != 'false'
shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }}
run: cmake ${{ steps.process_inputs.outputs.cmake_build_args }}
shell: ${{ steps.process-inputs.outputs.shell }}
run: cmake ${{ steps.process-inputs.outputs.cmake-build-args }}

- name: Run tests
if: inputs.run-test != 'false'
shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }}
run: ctest ${{ steps.process_inputs.outputs.cmake_test_args }}
shell: ${{ steps.process-inputs.outputs.shell }}
run: ctest ${{ steps.process-inputs.outputs.cmake-test-args }}
Loading