From 835c31b955a2a1df19a37c47b466cd07f9c20d6a Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 8 Jan 2023 11:34:53 +0700 Subject: [PATCH 1/5] add `args` input option --- action.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/action.yml b/action.yml index dfd4d4b..f33733c 100644 --- a/action.yml +++ b/action.yml @@ -13,6 +13,9 @@ inputs: description: The build directory of CMake project required: false default: build + args: + description: Other arguments passed during CMake configuration + required: false runs: using: composite steps: @@ -21,6 +24,9 @@ runs: run: | CONFIGURE_ARGS="${{ inputs.source-dir }} -B ${{ inputs.build-dir }}" BUILD_ARGS="--build ${{ inputs.build-dir }}" + if [ -n '${{ inputs.args }}' ]; then + CMAKE_CONFIGURE_ARGS="$CMAKE_CONFIGURE_ARGS ${{ inputs.args }}" + fi echo "CMAKE_CONFIGURE_ARGS=$CONFIGURE_ARGS" >> $GITHUB_ENV echo "CMAKE_BUILD_ARGS=$BUILD_ARGS" >> $GITHUB_ENV From 1410df2e180fb32193f9d937d8fc77c855409797 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 8 Jan 2023 11:47:14 +0700 Subject: [PATCH 2/5] add option in test configuration to output `hello_world.txt` --- test/CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 71bf957..135aa7f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,3 +1,13 @@ cmake_minimum_required(VERSION 3.0) project(test) + +option(BUILD_TXT "build hello world txt file" OFF) + add_executable(hello_world hello_world.cpp) + +if(BUILD_TXT) + add_custom_target( + hello_world_txt ALL + COMMAND echo "Hello world!" >> ${CMAKE_CURRENT_BINARY_DIR}/hello_world.txt + ) +endif() From f90a3ab334f95eea207256aae972c6f5f09318b5 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 8 Jan 2023 11:55:37 +0700 Subject: [PATCH 3/5] add workflow job to test this action using additional arguments --- .github/workflows/test.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 839cac9..70d3806 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -52,3 +52,21 @@ jobs: - name: Check if default build directory is not exist run: test ! -d build + + use-action-with-other-args: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3.3.0 + + - name: Use this action with build txt enabled + uses: ./ + with: + source-dir: test + args: -D BUILD_TXT=ON + + - name: Run build result + run: build/hello_world + + - name: Check if the txt result exist + run: cat build/hello_world.txt From 81445eb663583786c20be7da34004d54ea0418f5 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 8 Jan 2023 11:56:59 +0700 Subject: [PATCH 4/5] reword other aguments with additional arguments --- .github/workflows/test.yml | 2 +- action.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 70d3806..5575fa6 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -53,7 +53,7 @@ jobs: - name: Check if default build directory is not exist run: test ! -d build - use-action-with-other-args: + use-action-with-additional-args: runs-on: ubuntu-latest steps: - name: Checkout repository diff --git a/action.yml b/action.yml index f33733c..5e2d8b0 100644 --- a/action.yml +++ b/action.yml @@ -14,7 +14,7 @@ inputs: required: false default: build args: - description: Other arguments passed during CMake configuration + description: Additional arguments passed during CMake configuration required: false runs: using: composite From 9daa965e3571feff688fb9c44ea7c14a563b8098 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 8 Jan 2023 12:02:00 +0700 Subject: [PATCH 5/5] fix wrong set to `CONFIGURE_ARGS` variable --- action.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/action.yml b/action.yml index 5e2d8b0..a2963c3 100644 --- a/action.yml +++ b/action.yml @@ -25,7 +25,7 @@ runs: CONFIGURE_ARGS="${{ inputs.source-dir }} -B ${{ inputs.build-dir }}" BUILD_ARGS="--build ${{ inputs.build-dir }}" if [ -n '${{ inputs.args }}' ]; then - CMAKE_CONFIGURE_ARGS="$CMAKE_CONFIGURE_ARGS ${{ inputs.args }}" + CONFIGURE_ARGS="$CONFIGURE_ARGS ${{ inputs.args }}" fi echo "CMAKE_CONFIGURE_ARGS=$CONFIGURE_ARGS" >> $GITHUB_ENV echo "CMAKE_BUILD_ARGS=$BUILD_ARGS" >> $GITHUB_ENV