From 9f80f7200af78c9cb994286df9ecfbd8b175b326 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Fri, 30 Jun 2023 13:43:12 +0700 Subject: [PATCH 1/8] docs: replace `@main` with the latest version tag --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a6b3f12..2aaffc0 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ jobs: uses: actions/checkout@v3.5.3 - name: Configure the project - uses: threeal/cmake-action@main + uses: threeal/cmake-action@v1.2.0 - name: Build the project runs: cmake --build build @@ -63,13 +63,13 @@ jobs: runs: ctest --test-dir build ``` -> **Note**: You can replace `@main` with any version you prefer. See [this](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsuses). +> **Note**: You can replace [`v1.2.0`](https://github.com/threeal/cmake-action/releases/tag/v1.2.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 + uses: threeal/cmake-action@v1.2.0 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@main + uses: threeal/cmake-action@v1.2.0 with: options: BUILD_TESTING=ON run-build: true @@ -90,7 +90,7 @@ jobs: ```yaml - name: Configure and build the project - uses: threeal/cmake-action@main + uses: threeal/cmake-action@v1.2.0 with: generator: Ninja c-compiler: clang From 735354b97a38dd7f2077254ccf5274cade581d1e Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Fri, 30 Jun 2023 14:13:01 +0700 Subject: [PATCH 2/8] docs: adjust and fix examples --- README.md | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 2aaffc0..2ee3227 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,16 @@ jobs: > **Note**: You can replace [`v1.2.0`](https://github.com/threeal/cmake-action/releases/tag/v1.2.0) with any version you prefer. See [this](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsuses). +#### Configure, Build, and Test in the Same Step + +```yaml +- name: Configure, build, and test the project + uses: threeal/cmake-action@v1.2.0 + with: + run-build: true + run-test: true +``` + #### Specify the Source and Build Directories ```yaml @@ -75,21 +85,10 @@ jobs: build-dir: submodules/out ``` -#### Configure, Build, and Test in the Same Step - -```yaml -- name: Configure, build, and test the project - uses: threeal/cmake-action@v1.2.0 - with: - options: BUILD_TESTING=ON - run-build: true - run-test: true -``` - #### Using Ninja as the Generator and Clang as the Compiler ```yaml -- name: Configure and build the project +- name: Configure the project uses: threeal/cmake-action@v1.2.0 with: generator: Ninja From 0a60e2eb74723c14787df0edf55f9e4c2eed9e05 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 2 Jul 2023 19:21:30 +0700 Subject: [PATCH 3/8] feat: add `build-dir` action output --- .github/workflows/test.yml | 15 +++++++++------ action.yml | 19 ++++++++++++------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index cff567a..c719d16 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,12 +19,13 @@ jobs: run: mv test/* . - name: Use the action + id: cmake-action uses: ./ - name: Try to test the project id: failed-step continue-on-error: true - run: ctest --test-dir build --output-on-failure --no-tests=error -R hello_world ${{ matrix.os == 'windows' && '-C Debug' || '' }} + run: ctest --test-dir ${{ steps.cmake-action.outputs.build-dir }} --output-on-failure --no-tests=error -R hello_world ${{ matrix.os == 'windows' && '-C Debug' || '' }} - name: Check on success if: steps.failed-step.outcome == 'success' @@ -32,8 +33,8 @@ jobs: - name: Build and test the project run: | - cmake --build build - ctest --test-dir build --output-on-failure --no-tests=error -R hello_world ${{ matrix.os == 'windows' && '-C Debug' || '' }} + cmake --build ${{ steps.cmake-action.outputs.build-dir }} + ctest --test-dir ${{ steps.cmake-action.outputs.build-dir }} --output-on-failure --no-tests=error -R hello_world ${{ matrix.os == 'windows' && '-C Debug' || '' }} specified-dir-usage: runs-on: ubuntu-latest @@ -42,6 +43,7 @@ jobs: uses: actions/checkout@v3.5.3 - name: Use the action with specified directories + id: cmake-action uses: ./ with: source-dir: test @@ -53,8 +55,8 @@ jobs: - name: Build and test the project run: | - cmake --build output - ctest --test-dir output --output-on-failure --no-tests=error -R hello_world + cmake --build ${{ steps.cmake-action.outputs.build-dir }} + ctest --test-dir ${{ steps.cmake-action.outputs.build-dir }} --output-on-failure --no-tests=error -R hello_world run-build-usage: runs-on: ubuntu-latest @@ -63,6 +65,7 @@ jobs: uses: actions/checkout@v3.5.3 - name: Use the action with run build enabled + id: cmake-action uses: ./ with: source-dir: test @@ -70,7 +73,7 @@ jobs: build-args: --target test_c --target test_cpp - name: Test the project - run: ctest --test-dir test/build --output-on-failure --no-tests=error -R test + run: ctest --test-dir ${{ steps.cmake-action.outputs.build-dir }} --output-on-failure --no-tests=error -R test run-test-usage: runs-on: ubuntu-latest diff --git a/action.yml b/action.yml index 51a8bd8..8332bff 100644 --- a/action.yml +++ b/action.yml @@ -46,11 +46,15 @@ inputs: test-args: description: Additional arguments to pass during the CTest run required: false +outputs: + build-dir: + description: The build directory of the CMake project + value: ${{ steps.process-inputs.outputs.build-dir }} runs: using: composite steps: - name: Process the inputs - id: process_inputs + id: process-inputs shell: bash run: | SOURCE_DIR="." @@ -64,6 +68,7 @@ runs: elif [ -n "${{ inputs.source-dir }}" ]; then BUILD_DIR="${{ inputs.source-dir }}/build" fi + echo "build-dir=$BUILD_DIR" >> $GITHUB_OUTPUT ARGS="'$SOURCE_DIR' -B '$BUILD_DIR'" if [ -n '${{ inputs.generator }}' ]; then @@ -87,14 +92,14 @@ runs: if [ -n '${{ inputs.args }}' ]; then ARGS="$ARGS ${{ inputs.args }}" fi - echo "cmake_args=${ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT + echo "cmake-args=${ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT if [ '${{ inputs.run-build }}' == 'true' ] || [ '${{ inputs.run-test }}' == 'true' ]; then BUILD_ARGS="--build '$BUILD_DIR'" if [ -n '${{ inputs.build-args }}' ]; then BUILD_ARGS="$BUILD_ARGS ${{ inputs.build-args }}" fi - echo "cmake_build_args=${BUILD_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT + echo "cmake-build-args=${BUILD_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT fi if [ '${{ inputs.run-test }}' == 'true' ]; then @@ -102,7 +107,7 @@ runs: if [ -n '${{ inputs.test-args }}' ]; then TEST_ARGS="$TEST_ARGS ${{ inputs.test-args }}" fi - echo "cmake_test_args=${TEST_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT + echo "cmake-test-args=${TEST_ARGS//[$'\t\r\n']}" >> $GITHUB_OUTPUT fi - name: Install Ninja @@ -117,14 +122,14 @@ runs: - name: Configure the CMake project shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }} - run: cmake ${{ steps.process_inputs.outputs.cmake_args }} + run: cmake ${{ steps.process-inputs.outputs.cmake-args }} - name: Build targets if: inputs.run-build != 'false' || inputs.run-test != 'false' shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }} - run: cmake ${{ steps.process_inputs.outputs.cmake_build_args }} + run: cmake ${{ steps.process-inputs.outputs.cmake-build-args }} - name: Run tests if: inputs.run-test != 'false' shell: ${{ runner.os == 'Windows' && 'pwsh' || 'bash' }} - run: ctest ${{ steps.process_inputs.outputs.cmake_test_args }} + run: ctest ${{ steps.process-inputs.outputs.cmake-test-args }} From 0a52a2a37369046b6f1ef77d550ec636eb2c37f4 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 2 Jul 2023 19:37:01 +0700 Subject: [PATCH 4/8] docs: add "outputs" section in the `README.md` --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 2ee3227..9ab76aa 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,12 @@ For more information, refer to [action.yml](./action.yml) and the [GitHub Action > **Note**: All inputs are optional. +### Outputs + +| Name | Value Type | Description | +| --- | --- | --- | +| `build-dir` | Path | The build directory of the CMake project. | + ### Examples ```yaml From 9d9c70d25788a80e509c23629109f805f95a6d93 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 2 Jul 2023 22:09:25 +0700 Subject: [PATCH 5/8] docs: improve the description and features section in the readme file --- README.md | 10 +++++----- action.yml | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9ab76aa..667bb32 100644 --- a/README.md +++ b/README.md @@ -4,15 +4,15 @@ [![License](https://img.shields.io/github/license/threeal/cmake-action)](./LICENSE) [![Test Status](https://img.shields.io/github/actions/workflow/status/threeal/cmake-action/test.yml?label=test&branch=main)](https://github.com/threeal/cmake-action/actions/workflows/test.yml) -Configure, build, and test your [CMake](https://cmake.org/) project using [GitHub Actions](https://github.com/features/actions). This action simplifies the workflow for your CMake project. It configures the build environment using the `cmake` command, and optionally builds the project using the `cmake --build` command and tests the project using the `ctest` command. +Configure, build, and test your [CMake](https://cmake.org/) project using [GitHub Actions](https://github.com/features/actions). This action simplifies the workflow for configuring the build environment of a CMake project. It can also be optionally specified to build a CMake project using the `cmake --build` command and test it using the `ctest` command. ## Features -- Configures a project using the [`cmake`](https://cmake.org/cmake/help/latest/manual/cmake.1.html) command. -- Option to build a project using the `cmake --build` command. -- Option to test a project using the [`ctest`](https://cmake.org/cmake/help/latest/manual/ctest.1.html) command. +- Configures a CMake project using the [`cmake`](https://cmake.org/cmake/help/latest/manual/cmake.1.html) command. +- Optionally builds a CMake project using the `cmake --build` command. +- Optionally tests a CMake project using the [`ctest`](https://cmake.org/cmake/help/latest/manual/ctest.1.html) command. - Auto-detects and installs required dependencies. -- Supports specifying multiple CMake options directly from the Action inputs. +- Supports specifying multiple CMake options directly from the action inputs. ## Usage diff --git a/action.yml b/action.yml index 8332bff..e58ec81 100644 --- a/action.yml +++ b/action.yml @@ -1,5 +1,5 @@ name: CMake Action -description: Configure, build, and test a CMake project +description: Configure, build, and test your CMake project author: Alfi Maulana branding: color: gray-dark From 032547798079c96edb40e86369824bf85db4048e Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Tue, 4 Jul 2023 19:23:09 +0700 Subject: [PATCH 6/8] feat: add `shell` action input --- .github/workflows/test.yml | 13 +++++++++++++ action.yml | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c719d16..2809eba 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -132,3 +132,16 @@ jobs: build-args: --target test_c --target test_cpp run-test: true test-args: -R test + + specified-shell: + runs-on: windows-latest + steps: + - name: Checkout the repository + uses: actions/checkout@v3.5.3 + + - name: Use the action with specified shell + uses: ./ + with: + shell: bash + source-dir: test + run-build: true diff --git a/action.yml b/action.yml index e58ec81..0e02db2 100644 --- a/action.yml +++ b/action.yml @@ -5,6 +5,9 @@ branding: color: gray-dark icon: terminal inputs: + shell: + description: The shell to be used to run the commands + required: false source-dir: description: The source directory of the CMake project required: false @@ -57,6 +60,13 @@ runs: id: process-inputs shell: bash run: | + if [ -n '${{ inputs.shell }}' ]; then + SHELL='${{ inputs.shell }}' + else + SHELL='${{ runner.os == 'Windows' && 'pwsh' || 'bash' }}' + fi + echo "shell=$SHELL" >> $GITHUB_OUTPUT + SOURCE_DIR="." if [ -n '${{ inputs.source-dir }}' ]; then SOURCE_DIR="${{ inputs.source-dir }}" @@ -121,15 +131,15 @@ runs: esac - 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 }} - name: Build targets 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 }} - name: Run tests 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 }} From ca8ab2ff60519a280dc00011ec59b75d23b848ae Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Tue, 4 Jul 2023 19:24:49 +0700 Subject: [PATCH 7/8] docs: add documentation of `shell` action input --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 667bb32..0901832 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ For more information, refer to [action.yml](./action.yml) and the [GitHub Action | Name | Value Type | Description | | --- | --- | --- | +| `shell` | String | The shell to be used to run the commands. It defaults to `pwsh` on Windows and `bash` on Linux and macOS. Refer to [this](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsshell) for more information on available shell options. | | `source-dir` | Path | The source directory of the CMake project. It defaults to the current directory. | | `build-dir` | Path | The build directory of the CMake project. It defaults to the `build` directory inside the source directory. | | `generator` | String | The build system generator for the CMake project. It appends the CMake configuration arguments with `-G [val]`. | From 961184a7339cff7627497ce3e58df9c37b8b8ecd Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Wed, 9 Aug 2023 16:06:31 +0700 Subject: [PATCH 8/8] docs: update version to v1.3.0 in the readme file (#61) --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0901832..1484b79 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ jobs: uses: actions/checkout@v3.5.3 - name: Configure the project - uses: threeal/cmake-action@v1.2.0 + uses: threeal/cmake-action@v1.3.0 - name: Build the project runs: cmake --build build @@ -70,13 +70,13 @@ jobs: runs: ctest --test-dir build ``` -> **Note**: You can replace [`v1.2.0`](https://github.com/threeal/cmake-action/releases/tag/v1.2.0) 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). #### Configure, Build, and Test in the Same Step ```yaml - name: Configure, build, and test the project - uses: threeal/cmake-action@v1.2.0 + uses: threeal/cmake-action@v1.3.0 with: run-build: true run-test: true @@ -86,7 +86,7 @@ jobs: ```yaml - name: Configure the project - uses: threeal/cmake-action@v1.2.0 + uses: threeal/cmake-action@v1.3.0 with: source-dir: submodules build-dir: submodules/out @@ -96,7 +96,7 @@ jobs: ```yaml - name: Configure the project - uses: threeal/cmake-action@v1.2.0 + uses: threeal/cmake-action@v1.3.0 with: generator: Ninja c-compiler: clang