From b6684cda7bf166ca8769f39501c7ed938ea80ea1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 16 Mar 2023 10:51:25 +0000 Subject: [PATCH 01/24] Bump actions/checkout from 3.3.0 to 3.4.0 Bumps [actions/checkout](https://github.com/actions/checkout) from 3.3.0 to 3.4.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3.3.0...v3.4.0) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/test.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3096ece..292bf45 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -10,7 +10,7 @@ jobs: os: [windows, ubuntu, macos] steps: - name: Check out this repository - uses: actions/checkout@v3.3.0 + uses: actions/checkout@v3.4.0 - name: Move test project to the working directory run: mv test/* . @@ -25,7 +25,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out this repository - uses: actions/checkout@v3.3.0 + uses: actions/checkout@v3.4.0 - name: Use this action with specified directories uses: ./ @@ -45,7 +45,7 @@ jobs: compiler: [gcc, msvc] steps: - name: Check out this repository - uses: actions/checkout@v3.3.0 + uses: actions/checkout@v3.4.0 - name: Use this action with additional compiler flags uses: ./ @@ -65,7 +65,7 @@ jobs: os: [windows, ubuntu, macos] steps: - name: Check out this repository - uses: actions/checkout@v3.3.0 + uses: actions/checkout@v3.4.0 - name: Use this action with specified compilers uses: ./ @@ -86,7 +86,7 @@ jobs: os: [windows, ubuntu, macos] steps: - name: Check out this repository - uses: actions/checkout@v3.3.0 + uses: actions/checkout@v3.4.0 - name: Use this action with a specified generator uses: ./ From 9ac87be07c27553f6b91b406cc83402625549f81 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Mon, 20 Mar 2023 10:08:14 +0700 Subject: [PATCH 02/24] ci: add `chore` prefix in Dependabot commit message --- .github/dependabot.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 253bcb7..245f9ad 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -4,3 +4,5 @@ updates: directory: / schedule: interval: daily + commit-message: + prefix: chore From 65da6607460298685f374b63b266872d22155146 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Mon, 20 Mar 2023 10:17:27 +0700 Subject: [PATCH 03/24] ci: `.gitignore` ignore all dot-prefixed files except for Git files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 378eac2..18d647c 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ +.* +!.git* + build From 6a826ca25fa96866ef999919a7136033af5da3b5 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Tue, 21 Mar 2023 12:29:49 +0700 Subject: [PATCH 04/24] ci: trigger `test.yml` workflow on pull request and push only on latest and main --- .github/workflows/test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 292bf45..e5b2475 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,7 +1,9 @@ name: test on: workflow_dispatch: + pull_request: push: + branches: [latest, main] jobs: default-usage: runs-on: ${{ matrix.os }}-latest From 8e1c81bcbae6b7c4a90adedecc6f703d0a3ad6b3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 24 Mar 2023 11:06:29 +0000 Subject: [PATCH 05/24] chore: bump actions/checkout from 3.4.0 to 3.5.0 Bumps [actions/checkout](https://github.com/actions/checkout) from 3.4.0 to 3.5.0. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3.4.0...v3.5.0) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/test.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e5b2475..19fb71a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: os: [windows, ubuntu, macos] steps: - name: Check out this repository - uses: actions/checkout@v3.4.0 + uses: actions/checkout@v3.5.0 - name: Move test project to the working directory run: mv test/* . @@ -27,7 +27,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out this repository - uses: actions/checkout@v3.4.0 + uses: actions/checkout@v3.5.0 - name: Use this action with specified directories uses: ./ @@ -47,7 +47,7 @@ jobs: compiler: [gcc, msvc] steps: - name: Check out this repository - uses: actions/checkout@v3.4.0 + uses: actions/checkout@v3.5.0 - name: Use this action with additional compiler flags uses: ./ @@ -67,7 +67,7 @@ jobs: os: [windows, ubuntu, macos] steps: - name: Check out this repository - uses: actions/checkout@v3.4.0 + uses: actions/checkout@v3.5.0 - name: Use this action with specified compilers uses: ./ @@ -88,7 +88,7 @@ jobs: os: [windows, ubuntu, macos] steps: - name: Check out this repository - uses: actions/checkout@v3.4.0 + uses: actions/checkout@v3.5.0 - name: Use this action with a specified generator uses: ./ From 76cdde0cc0bce552acaccb6bd84a339517898bb9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 14 Apr 2023 11:03:52 +0000 Subject: [PATCH 06/24] chore: bump actions/checkout from 3.5.0 to 3.5.2 Bumps [actions/checkout](https://github.com/actions/checkout) from 3.5.0 to 3.5.2. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3.5.0...v3.5.2) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/test.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 19fb71a..23f4dc9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: os: [windows, ubuntu, macos] steps: - name: Check out this repository - uses: actions/checkout@v3.5.0 + uses: actions/checkout@v3.5.2 - name: Move test project to the working directory run: mv test/* . @@ -27,7 +27,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out this repository - uses: actions/checkout@v3.5.0 + uses: actions/checkout@v3.5.2 - name: Use this action with specified directories uses: ./ @@ -47,7 +47,7 @@ jobs: compiler: [gcc, msvc] steps: - name: Check out this repository - uses: actions/checkout@v3.5.0 + uses: actions/checkout@v3.5.2 - name: Use this action with additional compiler flags uses: ./ @@ -67,7 +67,7 @@ jobs: os: [windows, ubuntu, macos] steps: - name: Check out this repository - uses: actions/checkout@v3.5.0 + uses: actions/checkout@v3.5.2 - name: Use this action with specified compilers uses: ./ @@ -88,7 +88,7 @@ jobs: os: [windows, ubuntu, macos] steps: - name: Check out this repository - uses: actions/checkout@v3.5.0 + uses: actions/checkout@v3.5.2 - name: Use this action with a specified generator uses: ./ From d9fbdd6b0a207919d8b528d04bd380b55a1c9deb Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Jun 2023 11:08:11 +0000 Subject: [PATCH 07/24] chore: bump actions/checkout from 3.5.2 to 3.5.3 Bumps [actions/checkout](https://github.com/actions/checkout) from 3.5.2 to 3.5.3. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v3.5.2...v3.5.3) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/test.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 23f4dc9..e89d2cb 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,7 +12,7 @@ jobs: os: [windows, ubuntu, macos] steps: - name: Check out this repository - uses: actions/checkout@v3.5.2 + uses: actions/checkout@v3.5.3 - name: Move test project to the working directory run: mv test/* . @@ -27,7 +27,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out this repository - uses: actions/checkout@v3.5.2 + uses: actions/checkout@v3.5.3 - name: Use this action with specified directories uses: ./ @@ -47,7 +47,7 @@ jobs: compiler: [gcc, msvc] steps: - name: Check out this repository - uses: actions/checkout@v3.5.2 + uses: actions/checkout@v3.5.3 - name: Use this action with additional compiler flags uses: ./ @@ -67,7 +67,7 @@ jobs: os: [windows, ubuntu, macos] steps: - name: Check out this repository - uses: actions/checkout@v3.5.2 + uses: actions/checkout@v3.5.3 - name: Use this action with specified compilers uses: ./ @@ -88,7 +88,7 @@ jobs: os: [windows, ubuntu, macos] steps: - name: Check out this repository - uses: actions/checkout@v3.5.2 + uses: actions/checkout@v3.5.3 - name: Use this action with a specified generator uses: ./ From c2edc8900ea5d71a7f10d2829fe17bc28ece4855 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Thu, 29 Jun 2023 14:03:48 +0700 Subject: [PATCH 08/24] docs: improve wordings in the `README.md` --- README.md | 40 ++++++++++++++++++---------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/README.md b/README.md index cc25a92..de7e8f0 100644 --- a/README.md +++ b/README.md @@ -1,50 +1,46 @@ # 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, builds the project using the `cmake --build` command, and optionally 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 and builds a project using the [cmake](https://cmake.org/cmake/help/latest/manual/cmake.1.html) 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. | +| `source-dir` | Path | Source directory of the CMake project. Defaults to the current directory. | +| `build-dir` | Path | Build directory of the CMake project. Defaults to the `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. | +| `run-test` | `true` or `false` | If enabled, runs testing using [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html). Defaults to `false`. | +| `generator` | String | Build system generator for 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. | +| `args` | Multiple strings | Additional arguments passed during 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: 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: @@ -58,9 +54,9 @@ jobs: uses: threeal/cmake-action@latest ``` -> 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 `@latest` 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 From 1d02cad3ab100e3e9efd3ebe6b138c58bc4f61b1 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Thu, 29 Jun 2023 14:24:25 +0700 Subject: [PATCH 09/24] docs: improve wordings in the `CMakeLists.txt` --- test/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 9c512eb..3e64c27 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,8 +1,8 @@ cmake_minimum_required(VERSION 3.0) project(test) -option(CHECK_USING_CLANG "check if target is compiled using Clang" OFF) -option(CHECK_SURPASS_WARNING "check if target could surpass a compiler warning" OFF) +option(CHECK_USING_CLANG "Check if the target is compiled using Clang" OFF) +option(CHECK_SURPASS_WARNING "Check if the target could surpass a compiler warning" OFF) if(CHECK_SURPASS_WARNING) if(MSVC) From be11a3a3dde4b9b5fc2c18c4d2977dffd50c34cd Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Thu, 29 Jun 2023 14:37:38 +0700 Subject: [PATCH 10/24] style: modify the order of `run-test` input --- README.md | 2 +- action.yml | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index de7e8f0..7ca4d9b 100644 --- a/README.md +++ b/README.md @@ -24,13 +24,13 @@ For more information, refer to [action.yml](./action.yml) and the [GitHub Action | `source-dir` | Path | Source directory of the CMake project. Defaults to the current directory. | | `build-dir` | Path | Build directory of the CMake project. Defaults to the `build` directory inside the source directory. | | `targets` | Multiple strings | List of build targets. | -| `run-test` | `true` or `false` | If enabled, runs testing using [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html). Defaults to `false`. | | `generator` | String | Build system generator for 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 CMake configuration. | +| `run-test` | `true` or `false` | If enabled, runs testing using [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html). Defaults to `false`. | | `test-args` | Multiple strings | Additional arguments passed 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. diff --git a/action.yml b/action.yml index ec6c6aa..9539e40 100644 --- a/action.yml +++ b/action.yml @@ -14,10 +14,6 @@ inputs: targets: description: List of build targets required: false - run-test: - description: If enabled, run testing using CTest (true/false) - required: false - default: false generator: description: Build system generator of the CMake project required: false @@ -36,6 +32,10 @@ inputs: args: description: Additional arguments passed during the CMake configuration required: false + run-test: + description: If enabled, run testing using CTest (true/false) + required: false + default: false test-args: description: Additional arguments passed during the CTest run required: false @@ -62,9 +62,6 @@ runs: 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 ARGS="$ARGS -G '${{ inputs.generator }}'" fi @@ -83,6 +80,9 @@ runs: if [ -n '${{ inputs.args }}' ]; then ARGS="$ARGS ${{ inputs.args }}" fi + if [ '${{ inputs.run-test }}' == 'true' ]; then + TEST_ARGS="--test-dir '$BUILD_DIR' --output-on-failure --no-tests=error" + fi if [ -n '${{ inputs.test-args }}' ]; then TEST_ARGS="$TEST_ARGS ${{ inputs.test-args }}" fi From 3430da8dad3655ab53209cba8e94d758ae83c137 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Thu, 29 Jun 2023 19:17:47 +0700 Subject: [PATCH 11/24] feat: add the `run-build` input --- .github/workflows/test.yml | 12 ++++++++--- README.md | 44 +++++++++++++++++++++----------------- action.yml | 37 +++++++++++++++++++++----------- 3 files changed, 58 insertions(+), 35 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e89d2cb..5d5c92f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,6 +19,8 @@ jobs: - name: Use this action uses: ./ + with: + run-build: true - name: Run the build result run: ${{ matrix.os == 'windows' && 'build\Debug\hello_world.exe' || 'build/hello_world' }} @@ -34,6 +36,7 @@ jobs: with: source-dir: test build-dir: output + run-build: true run-test: true test-args: -R hello_world @@ -54,10 +57,11 @@ jobs: 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 + run-build: true + run-test: true test-args: -R test ${{ matrix.compiler == 'msvc' && '-C Debug' || '' }} specified-compiler-usage: @@ -74,11 +78,12 @@ jobs: 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 + run-build: true + run-test: true test-args: -R test specified-generator-usage: @@ -94,6 +99,7 @@ jobs: uses: ./ with: source-dir: test - run-test: true generator: Ninja + run-build: true + run-test: true test-args: -R hello_world diff --git a/README.md b/README.md index 7ca4d9b..850345f 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,12 @@ [![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, builds the project using the `cmake --build` command, and optionally 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 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 -- Configures and builds 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. +- 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. @@ -21,16 +22,17 @@ For more information, refer to [action.yml](./action.yml) and the [GitHub Action | Name | Value Type | Description | | --- | --- | --- | -| `source-dir` | Path | Source directory of the CMake project. Defaults to the current directory. | -| `build-dir` | Path | Build directory of the CMake project. Defaults to the `build` directory inside the source directory. | -| `targets` | Multiple strings | List of build targets. | -| `generator` | String | Build system generator for the CMake project. | -| `c-compiler` | String | Preferred executable for compiling C language files. | -| `cxx-compiler` | String | Preferred executable for compiling C++ language files. | +| `source-dir` | Path | The source directory of the CMake project. Defaults to the current directory. | +| `build-dir` | Path | The source directory of the CMake project.. Defaults to the `build` directory inside the source directory. | +| `targets` | Multiple strings | A list of build targets. | +| `generator` | String | The build system generator for the CMake project. | +| `c-compiler` | String | The preferred executable for compiling C language files. | +| `cxx-compiler` | String | The 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 CMake configuration. | -| `run-test` | `true` or `false` | If enabled, runs testing using [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html). Defaults to `false`. | +| `args` | Multiple strings | Additional arguments passed during the CMake configuration. | +| `run-build` | `true` or `false` | If enabled, it builds the project using [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html). Defaults to `false`. | +| `run-test` | `true` or `false` | If enabled, it runs testing using [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html). Defaults to `false`. | | `test-args` | Multiple strings | Additional arguments passed 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. @@ -47,10 +49,10 @@ jobs: build-project: runs-on: ubuntu-latest steps: - - name: Check out this repository + - name: Check out the repository uses: actions/checkout@v3.3.0 - - name: Configure and build this project + - name: Configure the project uses: threeal/cmake-action@latest ``` @@ -59,30 +61,32 @@ jobs: #### Specify the Source and Build Directories ```yaml -- name: Configure and build this project +- name: Configure the project uses: threeal/cmake-action@latest with: source-dir: submodules build-dir: submodules/out ``` -#### Specify the Build Targets +#### Configure, Build, and Test in the Same Step ```yaml -- name: Configure and build this project +- name: Configure, build, and test the project uses: threeal/cmake-action@latest with: - targets: hello_mars hello_sun + args: -DBUILD_TESTING=ON + run-build: true + run-test: true ``` -#### Run Unit Tests After Build +#### Specify the Build Targets ```yaml -- name: Configure, build, and test this project +- name: Configure and build this project uses: threeal/cmake-action@latest with: - args: -DBUILD_TESTING=ON - run-test: true + run-build: true + targets: hello_mars hello_sun ``` #### Using Ninja as the Generator and Clang as the Compiler diff --git a/action.yml b/action.yml index 9539e40..37e1172 100644 --- a/action.yml +++ b/action.yml @@ -6,22 +6,22 @@ branding: icon: terminal inputs: source-dir: - description: Source directory of the CMake project + description: The source directory of the CMake project required: false build-dir: - description: Build directory of the CMake project + description: The source directory of the CMake project. required: false targets: - description: List of build targets + description: A list of build targets required: false generator: - description: Build system generator of the CMake project + description: The build system generator for the CMake project required: false c-compiler: - description: Preferred executable for compiling C language files + description: The preferred executable for compiling C language files required: false cxx-compiler: - description: Preferred executable for compiling C++ language files + description: The preferred executable for compiling C++ language files required: false c-flags: description: Additional flags passed when compiling C language files @@ -32,8 +32,12 @@ inputs: args: description: Additional arguments passed during the CMake configuration required: false + run-build: + description: If enabled, it builds the project using CMake (true/false) + required: false + default: false run-test: - description: If enabled, run testing using CTest (true/false) + description: If enabled, it runs testing using CTest (true/false) required: false default: false test-args: @@ -50,18 +54,15 @@ runs: if [ -n '${{ inputs.source-dir }}' ]; then SOURCE_DIR="${{ inputs.source-dir }}" fi + BUILD_DIR="build" if [ -n '${{ inputs.build-dir }}' ]; then BUILD_DIR="${{ inputs.build-dir }}" elif [ -n "${{ inputs.source-dir }}" ]; then BUILD_DIR="${{ inputs.source-dir }}/build" fi + 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 [ -n '${{ inputs.generator }}' ]; then ARGS="$ARGS -G '${{ inputs.generator }}'" fi @@ -80,12 +81,23 @@ runs: if [ -n '${{ inputs.args }}' ]; then ARGS="$ARGS ${{ inputs.args }}" fi + + BUILD_ARGS="" + if [ '${{ inputs.run-build }}' == 'true' ]; then + BUILD_ARGS="--build '$BUILD_DIR'" + fi + if [ -n '${{ inputs.targets }}' ]; then + BUILD_ARGS="$BUILD_ARGS --target ${{ inputs.targets }}" + fi + + TEST_ARGS="" if [ '${{ inputs.run-test }}' == 'true' ]; then TEST_ARGS="--test-dir '$BUILD_DIR' --output-on-failure --no-tests=error" 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_build_args=${BUILD_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT echo "cmake_test_args=${TEST_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT @@ -105,6 +117,7 @@ runs: run: cmake ${{ steps.process_inputs.outputs.cmake_args }} - name: Build targets + if: steps.process_inputs.outputs.cmake_build_args != '' shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }} run: cmake ${{ steps.process_inputs.outputs.cmake_build_args }} From f1910e1a56433ce114398e4facd6e1a96fd72efe Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Thu, 29 Jun 2023 19:32:21 +0700 Subject: [PATCH 12/24] feat: replace `targets` input with the more general `build-args` input --- .github/workflows/test.yml | 4 ++-- README.md | 32 +++++++++++--------------------- action.yml | 20 ++++++++++---------- 3 files changed, 23 insertions(+), 33 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5d5c92f..15c4445 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -56,11 +56,11 @@ jobs: uses: ./ with: source-dir: test - targets: test_c test_cpp 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 run-build: true + build-args: --target test_c --target test_cpp run-test: true test-args: -R test ${{ matrix.compiler == 'msvc' && '-C Debug' || '' }} @@ -77,12 +77,12 @@ jobs: uses: ./ with: source-dir: test - targets: test_c test_cpp generator: Ninja c-compiler: clang cxx-compiler: clang++ args: -D CHECK_USING_CLANG=ON run-build: true + build-args: --target test_c --target test_cpp run-test: true test-args: -R test diff --git a/README.md b/README.md index 850345f..c35fdd5 100644 --- a/README.md +++ b/README.md @@ -8,9 +8,9 @@ Configure, build, and test your [CMake](https://cmake.org/) project using [GitHu ## Features -- Configures 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. - 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. +- 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. @@ -22,18 +22,18 @@ For more information, refer to [action.yml](./action.yml) and the [GitHub Action | Name | Value Type | Description | | --- | --- | --- | -| `source-dir` | Path | The source directory of the CMake project. Defaults to the current directory. | -| `build-dir` | Path | The source directory of the CMake project.. Defaults to the `build` directory inside the source directory. | -| `targets` | Multiple strings | A list of build targets. | +| `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. | | `c-compiler` | String | The preferred executable for compiling C language files. | | `cxx-compiler` | String | The 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. | -| `run-build` | `true` or `false` | If enabled, it builds the project using [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html). Defaults to `false`. | -| `run-test` | `true` or `false` | If enabled, it runs testing using [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html). Defaults to `false`. | -| `test-args` | Multiple strings | Additional arguments passed during the CTest run. | +| `c-flags` | Multiple strings | Additional flags to pass when compiling C language files. | +| `cxx-flags` | Multiple strings | Additional flags to pass when compiling C++ language files. | +| `args` | Multiple strings | Additional arguments to pass during the CMake configuration. | +| `run-build` | `true` or `false` | If enabled, it builds the project using [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html). 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. @@ -79,16 +79,6 @@ jobs: run-test: true ``` -#### Specify the Build Targets - -```yaml -- name: Configure and build this project - uses: threeal/cmake-action@latest - with: - run-build: true - targets: hello_mars hello_sun -``` - #### Using Ninja as the Generator and Clang as the Compiler ```yaml diff --git a/action.yml b/action.yml index 37e1172..032d161 100644 --- a/action.yml +++ b/action.yml @@ -9,10 +9,7 @@ inputs: description: The source directory of the CMake project required: false build-dir: - description: The source directory of the CMake project. - required: false - targets: - description: A list of build targets + description: The build directory of the CMake project required: false generator: description: The build system generator for the CMake project @@ -24,24 +21,27 @@ inputs: description: The preferred executable for compiling C++ language files required: false c-flags: - description: Additional flags passed when compiling C language files + description: Additional flags to pass when compiling C language files required: false cxx-flags: - description: Additional flags passed when compiling C++ language files + description: Additional flags to pass when compiling C++ language files required: false args: - description: Additional arguments passed during the CMake configuration + description: Additional arguments to pass during the CMake configuration 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: - description: Additional arguments passed during the CTest run + description: Additional arguments to pass during the CTest run required: false runs: using: composite @@ -86,8 +86,8 @@ runs: if [ '${{ inputs.run-build }}' == 'true' ]; then BUILD_ARGS="--build '$BUILD_DIR'" fi - if [ -n '${{ inputs.targets }}' ]; then - BUILD_ARGS="$BUILD_ARGS --target ${{ inputs.targets }}" + if [ -n '${{ inputs.build-args }}' ]; then + BUILD_ARGS="$BUILD_ARGS ${{ inputs.build-args }}" fi TEST_ARGS="" From 62ad24196f690a7fd87f31b6993f66c1e33ce61e Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Thu, 29 Jun 2023 20:13:23 +0700 Subject: [PATCH 13/24] ci: expand jobs to test for `run-build` and `run-test` inputs --- .github/workflows/test.yml | 66 ++++++++++++++++++++++++++++++-------- 1 file changed, 53 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 15c4445..820c215 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,37 +11,77 @@ jobs: matrix: os: [windows, ubuntu, macos] steps: - - name: Check out this repository + - 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: ./ - with: - run-build: true - - 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 + + - 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 specified-dir-usage: runs-on: ubuntu-latest steps: - - name: Check out this repository + - 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-build: true - 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 + + 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 + + - name: Test the project + run: ctest --test-dir build --output-on-failure --no-tests=error + + 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-build: true + run-test: true additional-flags-usage: runs-on: ${{ matrix.compiler == 'msvc' && 'windows' || 'ubuntu' }}-latest From b5b08aba16e015242c39dc3ea58ef91a66e83c5d Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Thu, 29 Jun 2023 20:20:04 +0700 Subject: [PATCH 14/24] ci: disable fail fast in job with matrix strategy --- .github/workflows/test.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 820c215..e3ace27 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -8,6 +8,7 @@ jobs: default-usage: runs-on: ${{ matrix.os }}-latest strategy: + fail-fast: false matrix: os: [windows, ubuntu, macos] steps: @@ -86,6 +87,7 @@ jobs: additional-flags-usage: runs-on: ${{ matrix.compiler == 'msvc' && 'windows' || 'ubuntu' }}-latest strategy: + fail-fast: false matrix: compiler: [gcc, msvc] steps: @@ -107,6 +109,7 @@ jobs: specified-compiler-usage: runs-on: ${{ matrix.os }}-latest strategy: + fail-fast: false matrix: os: [windows, ubuntu, macos] steps: @@ -129,6 +132,7 @@ jobs: specified-generator-usage: runs-on: ${{ matrix.os }}-latest strategy: + fail-fast: false matrix: os: [windows, ubuntu, macos] steps: From 09bf642a9f101b3ecac36cb3741bc6adfb1637dd Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Thu, 29 Jun 2023 20:23:07 +0700 Subject: [PATCH 15/24] ci: fix by specified test to run --- .github/workflows/test.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e3ace27..c9cc996 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,7 +24,7 @@ jobs: - name: Try to test the project id: failed-step continue-on-error: true - run: ctest --test-dir build --output-on-failure --no-tests=error + run: ctest --test-dir build --output-on-failure --no-tests=error -R hello_world - name: Check on success if: steps.failed-step.outcome == 'success' @@ -33,7 +33,7 @@ jobs: - name: Build and test the project run: | cmake --build build - ctest --test-dir build --output-on-failure --no-tests=error + ctest --test-dir build --output-on-failure --no-tests=error -R hello_world specified-dir-usage: runs-on: ubuntu-latest @@ -54,7 +54,7 @@ jobs: - name: Build and test the project run: | cmake --build output - ctest --test-dir output --output-on-failure --no-tests=error + ctest --test-dir output --output-on-failure --no-tests=error -R hello_world run-build-usage: runs-on: ubuntu-latest @@ -67,9 +67,10 @@ jobs: with: source-dir: test run-build: true + build-args: --target test_c --target test_cpp - name: Test the project - run: ctest --test-dir build --output-on-failure --no-tests=error + run: ctest --test-dir test/build --output-on-failure --no-tests=error -R test run-test-usage: runs-on: ubuntu-latest @@ -83,6 +84,7 @@ jobs: source-dir: test run-build: true run-test: true + test-args: -R hello_world additional-flags-usage: runs-on: ${{ matrix.compiler == 'msvc' && 'windows' || 'ubuntu' }}-latest From 4e05d6cf4fab4b45dabe890cd3b92a12a9e2ad14 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Thu, 29 Jun 2023 20:26:57 +0700 Subject: [PATCH 16/24] ci: fix by specified test configuration on Windows --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c9cc996..2c180ff 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -24,7 +24,7 @@ jobs: - 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 + 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' @@ -33,7 +33,7 @@ jobs: - name: Build and test the project run: | cmake --build build - ctest --test-dir build --output-on-failure --no-tests=error -R hello_world + 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 From cc3b1b7f505a6b213844fcd23e76000e43c1e650 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Thu, 29 Jun 2023 22:59:16 +0700 Subject: [PATCH 17/24] feat: modify how build targets and run tests steps got enabled --- action.yml | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/action.yml b/action.yml index 032d161..a2ec7f3 100644 --- a/action.yml +++ b/action.yml @@ -81,26 +81,23 @@ runs: if [ -n '${{ inputs.args }}' ]; then ARGS="$ARGS ${{ inputs.args }}" fi + echo "cmake_args=${ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT - BUILD_ARGS="" if [ '${{ inputs.run-build }}' == 'true' ]; then BUILD_ARGS="--build '$BUILD_DIR'" - fi - if [ -n '${{ inputs.build-args }}' ]; then - BUILD_ARGS="$BUILD_ARGS ${{ inputs.build-args }}" + 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 - TEST_ARGS="" 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 - 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_build_args=${BUILD_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT - echo "cmake_test_args=${TEST_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT - name: Install Ninja if: ${{ inputs.generator == 'Ninja' }} @@ -117,11 +114,11 @@ runs: run: cmake ${{ steps.process_inputs.outputs.cmake_args }} - name: Build targets - if: steps.process_inputs.outputs.cmake_build_args != '' + if: inputs.run-build != 'false' shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }} run: cmake ${{ steps.process_inputs.outputs.cmake_build_args }} - name: Run tests - if: steps.process_inputs.outputs.cmake_test_args != '' + if: inputs.run-test != 'false' shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }} run: ctest ${{ steps.process_inputs.outputs.cmake_test_args }} From baf303f12124efc7fcf86226f5d74837032853c8 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Thu, 29 Jun 2023 23:11:10 +0700 Subject: [PATCH 18/24] ci: merge jobs for testing action with specified generator and compilers --- .github/workflows/test.yml | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2c180ff..764613b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -108,7 +108,7 @@ jobs: 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 @@ -118,7 +118,7 @@ jobs: - name: Check out this repository uses: actions/checkout@v3.5.3 - - name: Use this action with specified compilers + - name: Use this action with specified generator and compilers uses: ./ with: source-dir: test @@ -130,22 +130,3 @@ jobs: build-args: --target test_c --target test_cpp run-test: true test-args: -R test - - specified-generator-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.5.3 - - - name: Use this action with a specified generator - uses: ./ - with: - source-dir: test - generator: Ninja - run-build: true - run-test: true - test-args: -R hello_world From d0fef383d5e28857357a98d8d4b32d2ef2b1da0d Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Thu, 29 Jun 2023 23:17:28 +0700 Subject: [PATCH 19/24] feat: auto enable `run-build` if `run-test` is enabled --- .github/workflows/test.yml | 1 - action.yml | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 764613b..e55645b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -82,7 +82,6 @@ jobs: uses: ./ with: source-dir: test - run-build: true run-test: true test-args: -R hello_world diff --git a/action.yml b/action.yml index a2ec7f3..c12b88b 100644 --- a/action.yml +++ b/action.yml @@ -83,7 +83,7 @@ runs: fi echo "cmake_args=${ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT - if [ '${{ inputs.run-build }}' == 'true' ]; then + 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 }}" @@ -114,7 +114,7 @@ runs: run: cmake ${{ steps.process_inputs.outputs.cmake_args }} - name: Build targets - if: inputs.run-build != 'false' + if: inputs.run-build != 'false' || inputs.run-test != 'false' shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }} run: cmake ${{ steps.process_inputs.outputs.cmake_build_args }} From a320b8e14bb0b06ef1bd9d9568861973a3dca498 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Thu, 29 Jun 2023 23:18:54 +0700 Subject: [PATCH 20/24] style: use a better step names in `test.yml` workflow --- .github/workflows/test.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e55645b..3d33ca6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -92,10 +92,10 @@ jobs: matrix: compiler: [gcc, msvc] steps: - - name: Check out this repository + - 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 @@ -114,10 +114,10 @@ jobs: matrix: os: [windows, ubuntu, macos] steps: - - name: Check out this repository + - name: Checkout the repository uses: actions/checkout@v3.5.3 - - name: Use this action with specified generator and compilers + - name: Use the action with specified generator and compilers uses: ./ with: source-dir: test From 75d5a7178bffca59a4aed69e17bc2667168752d7 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Thu, 29 Jun 2023 23:31:04 +0700 Subject: [PATCH 21/24] docs: add cmake build and ctest steps example --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c35fdd5..0158cf3 100644 --- a/README.md +++ b/README.md @@ -49,11 +49,17 @@ jobs: build-project: runs-on: ubuntu-latest steps: - - name: Check out the repository + - name: Checkout the repository uses: actions/checkout@v3.3.0 - name: Configure the project uses: threeal/cmake-action@latest + + - 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 prefer. See [this](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsuses). @@ -82,7 +88,7 @@ jobs: #### Using Ninja as the Generator and Clang as the Compiler ```yaml -- name: Configure and build this project +- name: Configure and build the project uses: threeal/cmake-action@latest with: generator: Ninja From f599e74b36c25c7480469f19abb061cd5f3d641b Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Fri, 30 Jun 2023 12:29:27 +0700 Subject: [PATCH 22/24] feat: add `options` input --- .github/workflows/test.yml | 4 ++-- README.md | 3 ++- action.yml | 6 ++++++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3d33ca6..cff567a 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -101,7 +101,7 @@ jobs: source-dir: test 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 @@ -124,7 +124,7 @@ jobs: generator: Ninja c-compiler: clang cxx-compiler: clang++ - args: -D CHECK_USING_CLANG=ON + options: CHECK_USING_CLANG=ON run-build: true build-args: --target test_c --target test_cpp run-test: true diff --git a/README.md b/README.md index 0158cf3..143dbd4 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ For more information, refer to [action.yml](./action.yml) and the [GitHub Action | `cxx-compiler` | String | The preferred executable for compiling C++ language files. | | `c-flags` | Multiple strings | Additional flags to pass when compiling C language files. | | `cxx-flags` | Multiple strings | Additional flags to pass when compiling C++ language files. | +| `options` | Multiple strings | Additional options to pass during the CMake configuration. | | `args` | Multiple strings | Additional arguments to pass during the CMake configuration. | | `run-build` | `true` or `false` | If enabled, it builds the project using [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html). It defaults to `false`. | | `build-args` | Multiple strings | Additional arguments to pass during the CMake build. | @@ -80,7 +81,7 @@ jobs: - name: Configure, build, and test the project uses: threeal/cmake-action@latest with: - args: -DBUILD_TESTING=ON + options: BUILD_TESTING=ON run-build: true run-test: true ``` diff --git a/action.yml b/action.yml index c12b88b..51a8bd8 100644 --- a/action.yml +++ b/action.yml @@ -26,6 +26,9 @@ inputs: cxx-flags: description: Additional flags to pass when compiling C++ language files required: false + options: + description: Additional options to pass during the CMake configuration + required: false args: description: Additional arguments to pass during the CMake configuration required: false @@ -78,6 +81,9 @@ runs: if [ -n '${{ inputs.cxx-flags }}' ]; then ARGS="$ARGS -D CMAKE_CXX_FLAGS='${{ inputs.cxx-flags }}'" fi + for OPT in ${{ inputs.options }}; do + ARGS="$ARGS -D $OPT" + done if [ -n '${{ inputs.args }}' ]; then ARGS="$ARGS ${{ inputs.args }}" fi From fc5e82e9e08d1869287cc25821f14fe92d8eef13 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Fri, 30 Jun 2023 12:44:02 +0700 Subject: [PATCH 23/24] docs: describe how each inputs append the CMake arguments --- README.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 143dbd4..5781e0e 100644 --- a/README.md +++ b/README.md @@ -24,21 +24,21 @@ For more information, refer to [action.yml](./action.yml) and the [GitHub Action | --- | --- | --- | | `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. | -| `c-compiler` | String | The preferred executable for compiling C language files. | -| `cxx-compiler` | String | The preferred executable for compiling C++ language files. | -| `c-flags` | Multiple strings | Additional flags to pass when compiling C language files. | -| `cxx-flags` | Multiple strings | Additional flags to pass when compiling C++ language files. | -| `options` | Multiple strings | Additional options to pass during the CMake configuration. | +| `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 [CTest](https://cmake.org/cmake/help/latest/manual/ctest.1.html). It defaults to `false`. | +| `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**: 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 @@ -63,7 +63,7 @@ jobs: runs: ctest --test-dir build ``` -> Note: You can replace `@latest` 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 `@latest` 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 From ce8b638deaf27e562cd11a3cba7f113612179283 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Fri, 30 Jun 2023 12:50:35 +0700 Subject: [PATCH 24/24] docs: replace `@latest` with `@main` --- README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 5781e0e..a6b3f12 100644 --- a/README.md +++ b/README.md @@ -51,10 +51,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout the repository - uses: actions/checkout@v3.3.0 + uses: actions/checkout@v3.5.3 - name: Configure the project - uses: threeal/cmake-action@latest + uses: threeal/cmake-action@main - name: Build the project runs: cmake --build build @@ -63,13 +63,13 @@ jobs: runs: ctest --test-dir build ``` -> **Note**: You can replace `@latest` 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 `@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 Build Directories ```yaml - name: Configure the project - uses: threeal/cmake-action@latest + uses: threeal/cmake-action@main with: source-dir: submodules build-dir: submodules/out @@ -79,7 +79,7 @@ jobs: ```yaml - name: Configure, build, and test the project - uses: threeal/cmake-action@latest + uses: threeal/cmake-action@main with: options: BUILD_TESTING=ON run-build: true @@ -90,7 +90,7 @@ jobs: ```yaml - name: Configure and build the project - uses: threeal/cmake-action@latest + uses: threeal/cmake-action@main with: generator: Ninja c-compiler: clang