From 186353f77abb20f640d384fba16e94378b85de05 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 22 Jan 2023 11:13:03 +0700 Subject: [PATCH 1/2] handle the default source dir in the process inputs step --- action.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/action.yml b/action.yml index af61157..5d70903 100644 --- a/action.yml +++ b/action.yml @@ -8,7 +8,6 @@ inputs: source-dir: description: Source directory of the CMake project required: false - default: . build-dir: description: Build directory of the CMake project required: false @@ -41,7 +40,11 @@ runs: id: process_inputs shell: bash run: | - ARGS="'${{ inputs.source-dir }}' -B '${{ inputs.build-dir }}'" + SOURCE_DIR="." + if [ -n '${{ inputs.source-dir }}' ]; then + SOURCE_DIR="${{ inputs.source-dir }}" + fi + ARGS="'$SOURCE_DIR' -B '${{ inputs.build-dir }}'" BUILD_ARGS="--build '${{ inputs.build-dir }}'" if [ -n '${{ inputs.targets }}' ]; then BUILD_ARGS="$BUILD_ARGS --target ${{ inputs.targets }}" From 584ef59aade4444991a4f3cf2e84a7818b73b039 Mon Sep 17 00:00:00 2001 From: Alfi Maulana Date: Sun, 22 Jan 2023 11:23:52 +0700 Subject: [PATCH 2/2] handle the default build dir to be relative to the source dir --- .github/workflows/test.yml | 14 +++++++------- action.yml | 11 ++++++++--- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 442a728..c58c1ae 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,13 +31,13 @@ jobs: uses: ./ with: source-dir: test - build-dir: test/build + build-dir: output - name: Run the build result - run: test/build/hello_world + run: output/hello_world - name: Check if the default build directory does not exist - run: test ! -d build + run: test ! -d build && test ! -d test/build additional-flags-usage: runs-on: ${{ matrix.compiler == 'msvc' && 'windows' || 'ubuntu' }}-latest @@ -59,8 +59,8 @@ jobs: - name: Run the build results run: | - ${{ matrix.compiler == 'msvc' && 'build\Debug\test_c.exe' || 'build/test_c' }} - ${{ matrix.compiler == 'msvc' && 'build\Debug\test_cpp.exe' || 'build/test_cpp' }} + ${{ matrix.compiler == 'msvc' && 'test\build\Debug\test_c.exe' || 'test/build/test_c' }} + ${{ matrix.compiler == 'msvc' && 'test\build\Debug\test_cpp.exe' || 'test/build/test_cpp' }} specified-compiler-usage: runs-on: ${{ matrix.os }}-latest @@ -82,7 +82,7 @@ jobs: args: -D CHECK_USING_CLANG=ON - name: Run the build results - run: build/test_c && build/test_cpp + run: test/build/test_c && test/build/test_cpp specified-generator-usage: runs-on: ${{ matrix.os }}-latest @@ -100,4 +100,4 @@ jobs: generator: Ninja - name: Run the build result - run: build/hello_world + run: test/build/hello_world diff --git a/action.yml b/action.yml index 5d70903..1461fcd 100644 --- a/action.yml +++ b/action.yml @@ -11,7 +11,6 @@ inputs: build-dir: description: Build directory of the CMake project required: false - default: build targets: description: List of build targets required: false @@ -44,8 +43,14 @@ runs: if [ -n '${{ inputs.source-dir }}' ]; then SOURCE_DIR="${{ inputs.source-dir }}" fi - ARGS="'$SOURCE_DIR' -B '${{ inputs.build-dir }}'" - BUILD_ARGS="--build '${{ inputs.build-dir }}'" + 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'" if [ -n '${{ inputs.targets }}' ]; then BUILD_ARGS="$BUILD_ARGS --target ${{ inputs.targets }}" fi