chore: merge pull request #55 from threeal/main

Version 1.3.0 Release
This commit is contained in:
Alfi Maulana 2023-08-10 09:55:29 +07:00 committed by GitHub
commit b684818e31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 75 additions and 38 deletions

View File

@ -19,12 +19,13 @@ jobs:
run: mv test/* . run: mv test/* .
- name: Use the action - name: Use the action
id: cmake-action
uses: ./ uses: ./
- name: Try to test the project - name: Try to test the project
id: failed-step id: failed-step
continue-on-error: true 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 - name: Check on success
if: steps.failed-step.outcome == 'success' if: steps.failed-step.outcome == 'success'
@ -32,8 +33,8 @@ jobs:
- name: Build and test the project - name: Build and test the project
run: | run: |
cmake --build build cmake --build ${{ steps.cmake-action.outputs.build-dir }}
ctest --test-dir build --output-on-failure --no-tests=error -R hello_world ${{ matrix.os == 'windows' && '-C Debug' || '' }} 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: specified-dir-usage:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -42,6 +43,7 @@ jobs:
uses: actions/checkout@v3.5.3 uses: actions/checkout@v3.5.3
- name: Use the action with specified directories - name: Use the action with specified directories
id: cmake-action
uses: ./ uses: ./
with: with:
source-dir: test source-dir: test
@ -53,8 +55,8 @@ jobs:
- name: Build and test the project - name: Build and test the project
run: | run: |
cmake --build output cmake --build ${{ steps.cmake-action.outputs.build-dir }}
ctest --test-dir output --output-on-failure --no-tests=error -R hello_world ctest --test-dir ${{ steps.cmake-action.outputs.build-dir }} --output-on-failure --no-tests=error -R hello_world
run-build-usage: run-build-usage:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -63,6 +65,7 @@ jobs:
uses: actions/checkout@v3.5.3 uses: actions/checkout@v3.5.3
- name: Use the action with run build enabled - name: Use the action with run build enabled
id: cmake-action
uses: ./ uses: ./
with: with:
source-dir: test source-dir: test
@ -70,7 +73,7 @@ jobs:
build-args: --target test_c --target test_cpp build-args: --target test_c --target test_cpp
- name: Test the project - 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: run-test-usage:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -129,3 +132,16 @@ jobs:
build-args: --target test_c --target test_cpp build-args: --target test_c --target test_cpp
run-test: true run-test: true
test-args: -R test test-args: -R test
specified-shell:
runs-on: windows-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3.5.3
- name: Use the action with specified shell
uses: ./
with:
shell: bash
source-dir: test
run-build: true

View File

@ -4,15 +4,15 @@
[![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, 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 ## Features
- Configures a project using the [`cmake`](https://cmake.org/cmake/help/latest/manual/cmake.1.html) command. - Configures a CMake 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. - Optionally builds a CMake 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. - 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. - 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 ## Usage
@ -22,6 +22,7 @@ For more information, refer to [action.yml](./action.yml) and the [GitHub Action
| Name | Value Type | Description | | 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. | | `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. | | `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]`. | | `generator` | String | The build system generator for the CMake project. It appends the CMake configuration arguments with `-G [val]`. |
@ -40,6 +41,12 @@ For more information, refer to [action.yml](./action.yml) and the [GitHub Action
> **Note**: All inputs are optional. > **Note**: All inputs are optional.
### Outputs
| Name | Value Type | Description |
| --- | --- | --- |
| `build-dir` | Path | The build directory of the CMake project. |
### Examples ### Examples
```yaml ```yaml
@ -54,7 +61,7 @@ jobs:
uses: actions/checkout@v3.5.3 uses: actions/checkout@v3.5.3
- name: Configure the project - name: Configure the project
uses: threeal/cmake-action@main uses: threeal/cmake-action@v1.3.0
- name: Build the project - name: Build the project
runs: cmake --build build runs: cmake --build build
@ -63,34 +70,33 @@ jobs:
runs: ctest --test-dir build 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
```yaml
- name: Configure the project
uses: threeal/cmake-action@main
with:
source-dir: submodules
build-dir: submodules/out
```
#### Configure, Build, and Test in the Same Step #### Configure, Build, and Test in the Same Step
```yaml ```yaml
- name: Configure, build, and test the project - name: Configure, build, and test the project
uses: threeal/cmake-action@main uses: threeal/cmake-action@v1.3.0
with: with:
options: BUILD_TESTING=ON
run-build: true run-build: true
run-test: true run-test: true
``` ```
#### Specify the Source and Build Directories
```yaml
- name: Configure the project
uses: threeal/cmake-action@v1.3.0
with:
source-dir: submodules
build-dir: submodules/out
```
#### Using Ninja as the Generator and Clang as the Compiler #### Using Ninja as the Generator and Clang as the Compiler
```yaml ```yaml
- name: Configure and build the project - name: Configure the project
uses: threeal/cmake-action@main uses: threeal/cmake-action@v1.3.0
with: with:
generator: Ninja generator: Ninja
c-compiler: clang c-compiler: clang

View File

@ -1,10 +1,13 @@
name: CMake Action name: CMake Action
description: Configure, build, and test a CMake project description: Configure, build, and test your CMake project
author: Alfi Maulana author: Alfi Maulana
branding: branding:
color: gray-dark color: gray-dark
icon: terminal icon: terminal
inputs: inputs:
shell:
description: The shell to be used to run the commands
required: false
source-dir: source-dir:
description: The source directory of the CMake project description: The source directory of the CMake project
required: false required: false
@ -46,13 +49,24 @@ inputs:
test-args: test-args:
description: Additional arguments to pass during the CTest run description: Additional arguments to pass during the CTest run
required: false required: false
outputs:
build-dir:
description: The build directory of the CMake project
value: ${{ steps.process-inputs.outputs.build-dir }}
runs: runs:
using: composite using: composite
steps: steps:
- name: Process the inputs - name: Process the inputs
id: process_inputs id: process-inputs
shell: bash shell: bash
run: | run: |
if [ -n '${{ inputs.shell }}' ]; then
SHELL='${{ inputs.shell }}'
else
SHELL='${{ runner.os == 'Windows' && 'pwsh' || 'bash' }}'
fi
echo "shell=$SHELL" >> $GITHUB_OUTPUT
SOURCE_DIR="." SOURCE_DIR="."
if [ -n '${{ inputs.source-dir }}' ]; then if [ -n '${{ inputs.source-dir }}' ]; then
SOURCE_DIR="${{ inputs.source-dir }}" SOURCE_DIR="${{ inputs.source-dir }}"
@ -64,6 +78,7 @@ runs:
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
echo "build-dir=$BUILD_DIR" >> $GITHUB_OUTPUT
ARGS="'$SOURCE_DIR' -B '$BUILD_DIR'" ARGS="'$SOURCE_DIR' -B '$BUILD_DIR'"
if [ -n '${{ inputs.generator }}' ]; then if [ -n '${{ inputs.generator }}' ]; then
@ -87,14 +102,14 @@ runs:
if [ -n '${{ inputs.args }}' ]; then if [ -n '${{ inputs.args }}' ]; then
ARGS="$ARGS ${{ inputs.args }}" ARGS="$ARGS ${{ inputs.args }}"
fi 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 if [ '${{ inputs.run-build }}' == 'true' ] || [ '${{ inputs.run-test }}' == 'true' ]; then
BUILD_ARGS="--build '$BUILD_DIR'" BUILD_ARGS="--build '$BUILD_DIR'"
if [ -n '${{ inputs.build-args }}' ]; then if [ -n '${{ inputs.build-args }}' ]; then
BUILD_ARGS="$BUILD_ARGS ${{ inputs.build-args }}" BUILD_ARGS="$BUILD_ARGS ${{ inputs.build-args }}"
fi fi
echo "cmake_build_args=${BUILD_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT echo "cmake-build-args=${BUILD_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
fi fi
if [ '${{ inputs.run-test }}' == 'true' ]; then if [ '${{ inputs.run-test }}' == 'true' ]; then
@ -102,7 +117,7 @@ runs:
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_test_args=${TEST_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT echo "cmake-test-args=${TEST_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
fi fi
- name: Install Ninja - name: Install Ninja
@ -116,15 +131,15 @@ runs:
esac esac
- name: Configure the CMake project - name: Configure the CMake project
shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }} shell: ${{ steps.process-inputs.outputs.shell }}
run: cmake ${{ steps.process_inputs.outputs.cmake_args }} run: cmake ${{ steps.process-inputs.outputs.cmake-args }}
- name: Build targets - name: Build targets
if: inputs.run-build != 'false' || inputs.run-test != 'false' if: inputs.run-build != 'false' || inputs.run-test != 'false'
shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }} shell: ${{ steps.process-inputs.outputs.shell }}
run: cmake ${{ steps.process_inputs.outputs.cmake_build_args }} run: cmake ${{ steps.process-inputs.outputs.cmake-build-args }}
- name: Run tests - name: Run tests
if: inputs.run-test != 'false' if: inputs.run-test != 'false'
shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }} shell: ${{ steps.process-inputs.outputs.shell }}
run: ctest ${{ steps.process_inputs.outputs.cmake_test_args }} run: ctest ${{ steps.process-inputs.outputs.cmake-test-args }}