From 4a0c14989854b2ddaf5e5ffbb531bb8e76db5691 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Wed, 11 Jan 2023 15:38:28 +0700 Subject: [PATCH 1/5] add `targets` input option for specifying build targets --- action.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/action.yml b/action.yml index 63a5600..9bb2b43 100644 --- a/action.yml +++ b/action.yml @@ -13,6 +13,9 @@ inputs: description: The build directory of CMake project required: false default: build + targets: + description: List of build targets + required: false generator: description: The build system generator of the CMake project required: false @@ -33,6 +36,9 @@ runs: run: | ARGS="${{ inputs.source-dir }} -B ${{ inputs.build-dir }}" BUILD_ARGS="--build ${{ inputs.build-dir }}" + if [ -n '${{ inputs.targets }}' ]; then + BUILD_ARGS="$BUILD_ARGS --target ${{ inputs.targets }}" + fi if [ -n '${{ inputs.generator }}' ]; then ARGS="$ARGS -G ${{ inputs.generator }}" fi From 2391f1db8fef12546675c403d08132540ccfd628 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Wed, 11 Jan 2023 15:50:37 +0700 Subject: [PATCH 2/5] add `test` target for testing `targets` input --- test/CMakeLists.txt | 2 ++ test/test.cpp | 3 +++ 2 files changed, 5 insertions(+) create mode 100644 test/test.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8e4200e..813ceb9 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -11,3 +11,5 @@ endif() if(BUILD_CXX) add_executable(hello_world hello_world.cpp) endif() + +add_executable(test EXCLUDE_FROM_ALL test.cpp) diff --git a/test/test.cpp b/test/test.cpp new file mode 100644 index 0000000..4cce7f6 --- /dev/null +++ b/test/test.cpp @@ -0,0 +1,3 @@ +int main() { + return 0; +} From 17a40c86ca19f4b985f91a9fca6608a5722c466e Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Wed, 11 Jan 2023 15:52:55 +0700 Subject: [PATCH 3/5] add `use-action-with-specified-targets` to test `targets` input in workflow --- .github/workflows/test.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d4a4e33..e74dd59 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -39,6 +39,21 @@ jobs: - name: Check if the default build directory does not exist run: test ! -d build + use-action-with-specified-targets: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3.3.0 + + - name: Use this action with specified targets + uses: ./ + with: + source-dir: test + targets: test + + - name: Run build result + run: build/test + use-action-with-specified-compiler: runs-on: ubuntu-latest strategy: From 6f70267077ce6815770993cb62cbc4bc3facaad6 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Wed, 11 Jan 2023 16:47:00 +0700 Subject: [PATCH 4/5] separate `test` target into 2 for C and C++ --- .github/workflows/test.yml | 4 ++-- test/CMakeLists.txt | 3 ++- test/test.c | 3 +++ 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 test/test.c diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e74dd59..2796c42 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -49,10 +49,10 @@ jobs: uses: ./ with: source-dir: test - targets: test + targets: test_c test_cpp - name: Run build result - run: build/test + run: build/test_c && build/test_cpp use-action-with-specified-compiler: runs-on: ubuntu-latest diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 813ceb9..617b4f1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -12,4 +12,5 @@ if(BUILD_CXX) add_executable(hello_world hello_world.cpp) endif() -add_executable(test EXCLUDE_FROM_ALL test.cpp) +add_executable(test_c EXCLUDE_FROM_ALL test.c) +add_executable(test_cpp EXCLUDE_FROM_ALL test.cpp) diff --git a/test/test.c b/test/test.c new file mode 100644 index 0000000..4cce7f6 --- /dev/null +++ b/test/test.c @@ -0,0 +1,3 @@ +int main() { + return 0; +} From 99cd2fcb109d6ceb672250138dfc0675df37b59b Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Wed, 11 Jan 2023 16:51:13 +0700 Subject: [PATCH 5/5] show message if `test_c` and `test_cpp` ran successfully --- test/test.c | 3 +++ test/test.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/test/test.c b/test/test.c index 4cce7f6..e9a0a23 100644 --- a/test/test.c +++ b/test/test.c @@ -1,3 +1,6 @@ +#include + int main() { + printf("all ok\n"); return 0; } diff --git a/test/test.cpp b/test/test.cpp index 4cce7f6..c36cbb6 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -1,3 +1,6 @@ +#include + int main() { + std::cout << "all ok" << std::endl; return 0; }