diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d4a4e33..2796c42 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_c test_cpp + + - name: Run build result + run: build/test_c && build/test_cpp + use-action-with-specified-compiler: runs-on: ubuntu-latest strategy: 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 diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 8e4200e..617b4f1 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -11,3 +11,6 @@ endif() if(BUILD_CXX) add_executable(hello_world hello_world.cpp) endif() + +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..e9a0a23 --- /dev/null +++ b/test/test.c @@ -0,0 +1,6 @@ +#include + +int main() { + printf("all ok\n"); + return 0; +} diff --git a/test/test.cpp b/test/test.cpp new file mode 100644 index 0000000..c36cbb6 --- /dev/null +++ b/test/test.cpp @@ -0,0 +1,6 @@ +#include + +int main() { + std::cout << "all ok" << std::endl; + return 0; +}