chore: merge pull request #49 from threeal/main

Version 1.2.0 Release
This commit is contained in:
Alfi Maulana 2023-06-30 13:31:14 +07:00 committed by GitHub
commit 59b65a5b38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 176 additions and 124 deletions

View File

@ -4,3 +4,5 @@ updates:
directory: / directory: /
schedule: schedule:
interval: daily interval: daily
commit-message:
prefix: chore

View File

@ -1,97 +1,131 @@
name: test name: test
on: on:
workflow_dispatch: workflow_dispatch:
pull_request:
push: push:
branches: [latest, main]
jobs: jobs:
default-usage: default-usage:
runs-on: ${{ matrix.os }}-latest runs-on: ${{ matrix.os }}-latest
strategy: strategy:
fail-fast: false
matrix: matrix:
os: [windows, ubuntu, macos] os: [windows, ubuntu, macos]
steps: steps:
- name: Check out this repository - name: Checkout the repository
uses: actions/checkout@v3.3.0 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/* . run: mv test/* .
- name: Use this action - name: Use the action
uses: ./ uses: ./
- name: Run the build result - name: Try to test the project
run: ${{ matrix.os == 'windows' && 'build\Debug\hello_world.exe' || 'build/hello_world' }} 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: specified-dir-usage:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Check out this repository - name: Checkout the repository
uses: actions/checkout@v3.3.0 uses: actions/checkout@v3.5.3
- name: Use this action with specified directories - name: Use the action with specified directories
uses: ./ uses: ./
with: with:
source-dir: test source-dir: test
build-dir: output build-dir: output
run-test: true
test-args: -R hello_world
- name: Check if the default build directory does not exist - 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: additional-flags-usage:
runs-on: ${{ matrix.compiler == 'msvc' && 'windows' || 'ubuntu' }}-latest runs-on: ${{ matrix.compiler == 'msvc' && 'windows' || 'ubuntu' }}-latest
strategy: strategy:
fail-fast: false
matrix: matrix:
compiler: [gcc, msvc] compiler: [gcc, msvc]
steps: steps:
- name: Check out this repository - name: Checkout the repository
uses: actions/checkout@v3.3.0 uses: actions/checkout@v3.5.3
- name: Use this action with additional compiler flags - name: Use the action with additional compiler flags
uses: ./ uses: ./
with: with:
source-dir: test source-dir: test
targets: test_c test_cpp
run-test: true
c-flags: ${{ matrix.compiler == 'msvc' && '/w /WX-' || '-Wno-unused-variable' }} c-flags: ${{ matrix.compiler == 'msvc' && '/w /WX-' || '-Wno-unused-variable' }}
cxx-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' || '' }} test-args: -R test ${{ matrix.compiler == 'msvc' && '-C Debug' || '' }}
specified-compiler-usage: specified-generator-and-compiler-usage:
runs-on: ${{ matrix.os }}-latest runs-on: ${{ matrix.os }}-latest
strategy: strategy:
fail-fast: false
matrix: matrix:
os: [windows, ubuntu, macos] os: [windows, ubuntu, macos]
steps: steps:
- name: Check out this repository - name: Checkout the repository
uses: actions/checkout@v3.3.0 uses: actions/checkout@v3.5.3
- name: Use this action with specified compilers - name: Use the action with specified generator and compilers
uses: ./ uses: ./
with: with:
source-dir: test source-dir: test
targets: test_c test_cpp
run-test: true
generator: Ninja generator: Ninja
c-compiler: clang c-compiler: clang
cxx-compiler: clang++ cxx-compiler: clang++
args: -D CHECK_USING_CLANG=ON options: CHECK_USING_CLANG=ON
test-args: -R test run-build: true
build-args: --target test_c --target test_cpp
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
run-test: true run-test: true
generator: Ninja test-args: -R test
test-args: -R hello_world

3
.gitignore vendored
View File

@ -1 +1,4 @@
.*
!.git*
build build

View File

@ -1,99 +1,96 @@
# CMake Action # CMake Action
[![latest version](https://img.shields.io/github/v/release/threeal/cmake-action)](https://github.com/threeal/cmake-action/releases/) [![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) [![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 a [CMake](https://cmake.org/) project on [GitHub Actions](https://github.com/features/actions). 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.
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.
## Features ## Features
- Configure and build a project using the [cmake](https://cmake.org/cmake/help/latest/manual/cmake.1.html) command. - Configures 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. - Option to build a project using the `cmake --build` command.
- Auto-detect and install required dependencies. - Option to test a project using the [`ctest`](https://cmake.org/cmake/help/latest/manual/ctest.1.html) command.
- Specify multiple CMake options directly from the Action inputs. - Auto-detects and installs required dependencies.
- Supports specifying multiple CMake options directly from the Action inputs.
## Usage ## 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 ### Inputs
| Name | Value Type | Description | | Name | Value Type | Description |
| --- | --- | --- | | --- | --- | --- |
| `source-dir` | Path | Source directory of the CMake project. Defaults to current directory. | | `source-dir` | Path | The source directory of the CMake project. It defaults to the current directory. |
| `build-dir` | Path | Build directory of the CMake project. Defaults to `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. |
| `targets` | Multiple strings | List of build targets. | | `generator` | String | The build system generator for the CMake project. It appends the CMake configuration arguments with `-G [val]`. |
| `run-test` | `true` or `false` | If enabled, run testing using [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html). Defaults to `false`. | | `c-compiler` | String | The preferred executable for compiling C language files. It appends the CMake configuration arguments with `-D CMAKE_C_COMPILER=[val]`. |
| `generator` | String | Build system generator of the CMake project. | | `cxx-compiler` | String | The preferred executable for compiling C++ language files. It appends the CMake configuration arguments with `-D CMAKE_CXX_COMPILER=[val]`. |
| `c-compiler` | String | Preferred executable for compiling C language files. | | `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-compiler` | String | Preferred executable for compiling C++ language files. | | `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]`. |
| `c-flags` | Multiple strings | Additional flags passed when compiling C language files. | | `options` | Multiple strings | Additional options to pass during the CMake configuration. It appends the CMake configuration arguments with each of `-D [val]`. |
| `cxx-flags` | Multiple strings | Additional flags passed when compiling C++ language files. | | `args` | Multiple strings | Additional arguments to pass during the CMake configuration. |
| `args` | Multiple strings | Additional arguments passed during the CMake configuration. | | `run-build` | `true` or `false` | If enabled, it builds the project using CMake. It defaults to `false`. |
| `test-args` | Multiple strings | Additional arguments passed during the CTest run. | | `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 could be specified with more than one value. Separate each value with a space or a new line. > **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. > **Note**: All inputs are optional.
### Examples ### Examples
```yaml ```yaml
name: build name: Build
on: on:
push: push:
jobs: jobs:
build-project: build-project:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Check out this repository - name: Checkout the repository
uses: actions/checkout@v3.3.0 uses: actions/checkout@v3.5.3
- name: Configure and build this project - name: Configure the project
uses: threeal/cmake-action@latest 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 ```yaml
- name: Configure and build this project - name: Configure the project
uses: threeal/cmake-action@latest uses: threeal/cmake-action@main
with: with:
source-dir: submodules source-dir: submodules
build-dir: submodules/out build-dir: submodules/out
``` ```
#### Specify the Build Targets #### Configure, Build, and Test in the Same Step
```yaml ```yaml
- name: Configure and build this project - name: Configure, build, and test the project
uses: threeal/cmake-action@latest uses: threeal/cmake-action@main
with: with:
targets: hello_mars hello_sun options: BUILD_TESTING=ON
``` run-build: true
#### Run Unit Tests After Build
```yaml
- name: Configure, build, and test this project
uses: threeal/cmake-action@latest
with:
args: -DBUILD_TESTING=ON
run-test: true run-test: true
``` ```
#### 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 this project - name: Configure and build the project
uses: threeal/cmake-action@latest uses: threeal/cmake-action@main
with: with:
generator: Ninja generator: Ninja
c-compiler: clang c-compiler: clang

View File

@ -6,38 +6,45 @@ branding:
icon: terminal icon: terminal
inputs: inputs:
source-dir: source-dir:
description: Source directory of the CMake project description: The source directory of the CMake project
required: false required: false
build-dir: build-dir:
description: Build directory of the CMake project description: The build directory of the CMake project
required: false required: false
targets:
description: List of build targets
required: false
run-test:
description: If enabled, run testing using CTest (true/false)
required: false
default: false
generator: generator:
description: Build system generator of the CMake project description: The build system generator for the CMake project
required: false required: false
c-compiler: c-compiler:
description: Preferred executable for compiling C language files description: The preferred executable for compiling C language files
required: false required: false
cxx-compiler: cxx-compiler:
description: Preferred executable for compiling C++ language files description: The preferred executable for compiling C++ language files
required: false required: false
c-flags: c-flags:
description: Additional flags passed when compiling C language files description: Additional flags to pass when compiling C language files
required: false required: false
cxx-flags: cxx-flags:
description: Additional flags passed when compiling C++ language files description: Additional flags to pass when compiling C++ language files
required: false
options:
description: Additional options to pass during the CMake configuration
required: false required: false
args: args:
description: Additional arguments passed during the CMake configuration description: Additional arguments to pass during the CMake configuration
required: false required: false
run-build:
description: If enabled, it builds the project using CMake (true/false)
required: false
default: false
build-args:
description: Additional arguments to pass during the CMake build
required: false
run-test:
description: If enabled, it runs testing using CTest (true/false)
required: false
default: false
test-args: test-args:
description: Additional arguments passed during the CTest run description: Additional arguments to pass during the CTest run
required: false required: false
runs: runs:
using: composite using: composite
@ -50,21 +57,15 @@ runs:
if [ -n '${{ inputs.source-dir }}' ]; then if [ -n '${{ inputs.source-dir }}' ]; then
SOURCE_DIR="${{ inputs.source-dir }}" SOURCE_DIR="${{ inputs.source-dir }}"
fi fi
BUILD_DIR="build" BUILD_DIR="build"
if [ -n '${{ inputs.build-dir }}' ]; then if [ -n '${{ inputs.build-dir }}' ]; then
BUILD_DIR="${{ inputs.build-dir }}" BUILD_DIR="${{ inputs.build-dir }}"
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
ARGS="'$SOURCE_DIR' -B '$BUILD_DIR'" ARGS="'$SOURCE_DIR' -B '$BUILD_DIR'"
BUILD_ARGS="--build '$BUILD_DIR'"
TEST_ARGS=""
if [ -n '${{ inputs.targets }}' ]; then
BUILD_ARGS="$BUILD_ARGS --target ${{ inputs.targets }}"
fi
if [ '${{ inputs.run-test }}' == 'true' ]; then
TEST_ARGS="--test-dir '$BUILD_DIR' --output-on-failure --no-tests=error"
fi
if [ -n '${{ inputs.generator }}' ]; then if [ -n '${{ inputs.generator }}' ]; then
ARGS="$ARGS -G '${{ inputs.generator }}'" ARGS="$ARGS -G '${{ inputs.generator }}'"
fi fi
@ -80,15 +81,29 @@ runs:
if [ -n '${{ inputs.cxx-flags }}' ]; then if [ -n '${{ inputs.cxx-flags }}' ]; then
ARGS="$ARGS -D CMAKE_CXX_FLAGS='${{ inputs.cxx-flags }}'" ARGS="$ARGS -D CMAKE_CXX_FLAGS='${{ inputs.cxx-flags }}'"
fi fi
for OPT in ${{ inputs.options }}; do
ARGS="$ARGS -D $OPT"
done
if [ -n '${{ inputs.args }}' ]; then if [ -n '${{ inputs.args }}' ]; then
ARGS="$ARGS ${{ inputs.args }}" ARGS="$ARGS ${{ inputs.args }}"
fi fi
if [ -n '${{ inputs.test-args }}' ]; then
TEST_ARGS="$TEST_ARGS ${{ inputs.test-args }}"
fi
echo "cmake_args=${ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT echo "cmake_args=${ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
echo "cmake_build_args=${BUILD_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT
echo "cmake_test_args=${TEST_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
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
fi
- name: Install Ninja - name: Install Ninja
if: ${{ inputs.generator == 'Ninja' }} if: ${{ inputs.generator == 'Ninja' }}
@ -105,10 +120,11 @@ runs:
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'
shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }} shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }}
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: steps.process_inputs.outputs.cmake_test_args != '' if: inputs.run-test != 'false'
shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }} shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }}
run: ctest ${{ steps.process_inputs.outputs.cmake_test_args }} run: ctest ${{ steps.process_inputs.outputs.cmake_test_args }}

View File

@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.0) cmake_minimum_required(VERSION 3.0)
project(test) project(test)
option(CHECK_USING_CLANG "check if target is compiled using Clang" OFF) option(CHECK_USING_CLANG "Check if the target is compiled using Clang" OFF)
option(CHECK_SURPASS_WARNING "check if target could surpass a compiler warning" OFF) option(CHECK_SURPASS_WARNING "Check if the target could surpass a compiler warning" OFF)
if(CHECK_SURPASS_WARNING) if(CHECK_SURPASS_WARNING)
if(MSVC) if(MSVC)