From 8f8f9744ad48db70d4a0d381de22282735237fe6 Mon Sep 17 00:00:00 2001 From: Yonatan Karp-Rudin Date: Sat, 16 Dec 2023 10:45:54 +0100 Subject: [PATCH 01/11] Extract dockerfile location decision to composite action This commit extracts the logic of finding which dockerfile to use into a composite action as it will be reused in multiple places in this project --- .../actions/get-docker-image-path/action.yml | 31 +++++++++++++++++++ .github/workflows/ci-composite-actions.yml | 10 ++++++ 2 files changed, 41 insertions(+) create mode 100644 .github/actions/get-docker-image-path/action.yml diff --git a/.github/actions/get-docker-image-path/action.yml b/.github/actions/get-docker-image-path/action.yml new file mode 100644 index 0000000..9233730 --- /dev/null +++ b/.github/actions/get-docker-image-path/action.yml @@ -0,0 +1,31 @@ +name: 'Detect Dockerfile location' +description: 'Decides which location the docker file is located at' +inputs: + module-name: + description: 'Module name for Gradle build' + required: false + dockerfile_path: + description: | + An option to override the default dockerfile location, if none supplied the + return value would be ${{ inputs.module_name}}/Dockerfile + required: false +outputs: + location: + value: string + description: the location of the dockerfile that should be used + +runs: + using: 'composite' + steps: + - name: Find Dockerfile Location + id: dockerfile + shell: bash + run: | + if [ -n "${{ inputs.dockerfile_path }}" ]; then + echo "::set-output name=location::${{ inputs.dockerfile_path }}" + elif [ -n "${{ inputs.app_name }}" ]; then + echo "::set-output name=location::(${{ inputs.app_name }}/Dockerfile)" + else + echo "Error: Neither dockerfile_path nor app_name is provided." + exit 1 + fi diff --git a/.github/workflows/ci-composite-actions.yml b/.github/workflows/ci-composite-actions.yml index 5cc5d1f..e67add9 100644 --- a/.github/workflows/ci-composite-actions.yml +++ b/.github/workflows/ci-composite-actions.yml @@ -25,3 +25,13 @@ jobs: uses: yonatankarp/github-actions/.github/actions/build-jar-artifact@main with: tag: "test-tag" + + - name: "[test] - Get Dockrfile for module - use dockerfile override" + uses: yonatankarp/github-actions/.github/actions/get-docker-image@ + with: + dockerfile_path: "dockerfile-location" + + - name: "[test] Get Dockrfile for module - fallback to module" + uses: yonatankarp/github-actions/.github/actions/get-docker-image@ + with: + module-name: "test-tag" From 03c7a1a28eebcd017f4efd72dcad11133bcb6daf Mon Sep 17 00:00:00 2001 From: Yonatan Karp-Rudin Date: Sat, 16 Dec 2023 10:47:09 +0100 Subject: [PATCH 02/11] temp add current branch --- .github/workflows/ci-composite-actions.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-composite-actions.yml b/.github/workflows/ci-composite-actions.yml index e67add9..2078b58 100644 --- a/.github/workflows/ci-composite-actions.yml +++ b/.github/workflows/ci-composite-actions.yml @@ -27,11 +27,11 @@ jobs: tag: "test-tag" - name: "[test] - Get Dockrfile for module - use dockerfile override" - uses: yonatankarp/github-actions/.github/actions/get-docker-image@ + uses: yonatankarp/github-actions/.github/actions/get-docker-image@extract-dockerfile-location with: dockerfile_path: "dockerfile-location" - name: "[test] Get Dockrfile for module - fallback to module" - uses: yonatankarp/github-actions/.github/actions/get-docker-image@ + uses: yonatankarp/github-actions/.github/actions/get-docker-image@extract-dockerfile-location with: module-name: "test-tag" From 9163d9ba6f2b54c90b36b492b44856961d884370 Mon Sep 17 00:00:00 2001 From: Yonatan Karp-Rudin Date: Sat, 16 Dec 2023 10:48:08 +0100 Subject: [PATCH 03/11] fix action name --- .github/workflows/ci-composite-actions.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-composite-actions.yml b/.github/workflows/ci-composite-actions.yml index 2078b58..467df4f 100644 --- a/.github/workflows/ci-composite-actions.yml +++ b/.github/workflows/ci-composite-actions.yml @@ -27,11 +27,11 @@ jobs: tag: "test-tag" - name: "[test] - Get Dockrfile for module - use dockerfile override" - uses: yonatankarp/github-actions/.github/actions/get-docker-image@extract-dockerfile-location + uses: yonatankarp/github-actions/.github/actions/get-docker-image-path@extract-dockerfile-location with: dockerfile_path: "dockerfile-location" - name: "[test] Get Dockrfile for module - fallback to module" - uses: yonatankarp/github-actions/.github/actions/get-docker-image@extract-dockerfile-location + uses: yonatankarp/github-actions/.github/actions/get-docker-image-path@extract-dockerfile-location with: module-name: "test-tag" From a647507a48f8ae1567d641b18b4fcc1c8f07b96c Mon Sep 17 00:00:00 2001 From: Yonatan Karp-Rudin Date: Sat, 16 Dec 2023 10:52:44 +0100 Subject: [PATCH 04/11] fix action --- .github/actions/get-docker-image-path/action.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/actions/get-docker-image-path/action.yml b/.github/actions/get-docker-image-path/action.yml index 9233730..cfcf183 100644 --- a/.github/actions/get-docker-image-path/action.yml +++ b/.github/actions/get-docker-image-path/action.yml @@ -4,7 +4,7 @@ inputs: module-name: description: 'Module name for Gradle build' required: false - dockerfile_path: + dockerfile-path: description: | An option to override the default dockerfile location, if none supplied the return value would be ${{ inputs.module_name}}/Dockerfile @@ -21,11 +21,11 @@ runs: id: dockerfile shell: bash run: | - if [ -n "${{ inputs.dockerfile_path }}" ]; then - echo "::set-output name=location::${{ inputs.dockerfile_path }}" - elif [ -n "${{ inputs.app_name }}" ]; then - echo "::set-output name=location::(${{ inputs.app_name }}/Dockerfile)" + if [ -n "${{ inputs.dockerfile-path }}" ]; then + echo "::set-output name=location::${{ inputs.dockerfile-path }}" + elif [ -n "${{ inputs.module-name }}" ]; then + echo "::set-output name=location::(${{ inputs.module-name }}/Dockerfile)" else - echo "Error: Neither dockerfile_path nor app_name is provided." + echo "Error: Neither dockerfile-path nor module-name is provided." exit 1 fi From b1cd38bb7e97298d7d8e042fd74ff2beb61495d2 Mon Sep 17 00:00:00 2001 From: Yonatan Karp-Rudin Date: Sat, 16 Dec 2023 10:56:06 +0100 Subject: [PATCH 05/11] fixup? --- .../actions/get-docker-image-path/action.yml | 17 +++++++---------- .github/workflows/ci-composite-actions.yml | 2 ++ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/.github/actions/get-docker-image-path/action.yml b/.github/actions/get-docker-image-path/action.yml index cfcf183..03a151d 100644 --- a/.github/actions/get-docker-image-path/action.yml +++ b/.github/actions/get-docker-image-path/action.yml @@ -1,14 +1,14 @@ name: 'Detect Dockerfile location' description: 'Decides which location the docker file is located at' inputs: - module-name: + module_name: description: 'Module name for Gradle build' - required: false - dockerfile-path: + required: true + dockerfile_path: description: | An option to override the default dockerfile location, if none supplied the return value would be ${{ inputs.module_name}}/Dockerfile - required: false + required: true outputs: location: value: string @@ -21,11 +21,8 @@ runs: id: dockerfile shell: bash run: | - if [ -n "${{ inputs.dockerfile-path }}" ]; then - echo "::set-output name=location::${{ inputs.dockerfile-path }}" - elif [ -n "${{ inputs.module-name }}" ]; then - echo "::set-output name=location::(${{ inputs.module-name }}/Dockerfile)" + if [ -n "${{ inputs.dockerfile_path }}" ]; then + echo "::set-output name=location::${{ inputs.dockerfile_path }}" else - echo "Error: Neither dockerfile-path nor module-name is provided." - exit 1 + echo "::set-output name=location::(${{ inputs.module_name }}/Dockerfile)" fi diff --git a/.github/workflows/ci-composite-actions.yml b/.github/workflows/ci-composite-actions.yml index 467df4f..129dd9c 100644 --- a/.github/workflows/ci-composite-actions.yml +++ b/.github/workflows/ci-composite-actions.yml @@ -29,9 +29,11 @@ jobs: - name: "[test] - Get Dockrfile for module - use dockerfile override" uses: yonatankarp/github-actions/.github/actions/get-docker-image-path@extract-dockerfile-location with: + module_name: "" dockerfile_path: "dockerfile-location" - name: "[test] Get Dockrfile for module - fallback to module" uses: yonatankarp/github-actions/.github/actions/get-docker-image-path@extract-dockerfile-location with: module-name: "test-tag" + dockerfile_path: "" From 6e09ff36faafbd9e2c0a3b318cb8ff944c392629 Mon Sep 17 00:00:00 2001 From: Yonatan Karp-Rudin Date: Sat, 16 Dec 2023 10:59:10 +0100 Subject: [PATCH 06/11] ?! --- .github/actions/get-docker-image-path/action.yml | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/.github/actions/get-docker-image-path/action.yml b/.github/actions/get-docker-image-path/action.yml index 03a151d..837bb20 100644 --- a/.github/actions/get-docker-image-path/action.yml +++ b/.github/actions/get-docker-image-path/action.yml @@ -1,13 +1,11 @@ name: 'Detect Dockerfile location' description: 'Decides which location the docker file is located at' inputs: - module_name: + module-name: description: 'Module name for Gradle build' required: true - dockerfile_path: - description: | - An option to override the default dockerfile location, if none supplied the - return value would be ${{ inputs.module_name}}/Dockerfile + dockerfile-path: + description: 'An option to override the default dockerfile location, if none supplied the return value would be ${{ inputs.module-name}}/Dockerfile' required: true outputs: location: @@ -21,8 +19,8 @@ runs: id: dockerfile shell: bash run: | - if [ -n "${{ inputs.dockerfile_path }}" ]; then - echo "::set-output name=location::${{ inputs.dockerfile_path }}" + if [ -n "${{ inputs.dockerfile-path }}" ]; then + echo "::set-output name=location::${{ inputs.dockerfile-path }}" else - echo "::set-output name=location::(${{ inputs.module_name }}/Dockerfile)" + echo "::set-output name=location::(${{ inputs.module-name }}/Dockerfile)" fi From dda62e6c20da411d16039e06c2c8101cf4af98f9 Mon Sep 17 00:00:00 2001 From: Yonatan Karp-Rudin Date: Sat, 16 Dec 2023 10:59:53 +0100 Subject: [PATCH 07/11] fix ci :facepalm: --- .github/workflows/ci-composite-actions.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-composite-actions.yml b/.github/workflows/ci-composite-actions.yml index 129dd9c..352977d 100644 --- a/.github/workflows/ci-composite-actions.yml +++ b/.github/workflows/ci-composite-actions.yml @@ -29,11 +29,11 @@ jobs: - name: "[test] - Get Dockrfile for module - use dockerfile override" uses: yonatankarp/github-actions/.github/actions/get-docker-image-path@extract-dockerfile-location with: - module_name: "" - dockerfile_path: "dockerfile-location" + module-name: "" + dockerfile-path: "dockerfile-location" - name: "[test] Get Dockrfile for module - fallback to module" uses: yonatankarp/github-actions/.github/actions/get-docker-image-path@extract-dockerfile-location with: module-name: "test-tag" - dockerfile_path: "" + dockerfile-path: "" From 4245bf9abd9b5cd25ab98027d29c8ce66552c708 Mon Sep 17 00:00:00 2001 From: Yonatan Karp-Rudin Date: Sat, 16 Dec 2023 11:02:50 +0100 Subject: [PATCH 08/11] try again? --- .../actions/get-docker-image-path/action.yml | 9 ++++++--- .github/workflows/ci-composite-actions.yml | 18 +++++++++--------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.github/actions/get-docker-image-path/action.yml b/.github/actions/get-docker-image-path/action.yml index 837bb20..4a73b56 100644 --- a/.github/actions/get-docker-image-path/action.yml +++ b/.github/actions/get-docker-image-path/action.yml @@ -3,10 +3,10 @@ description: 'Decides which location the docker file is located at' inputs: module-name: description: 'Module name for Gradle build' - required: true + required: false dockerfile-path: description: 'An option to override the default dockerfile location, if none supplied the return value would be ${{ inputs.module-name}}/Dockerfile' - required: true + required: false outputs: location: value: string @@ -21,6 +21,9 @@ runs: run: | if [ -n "${{ inputs.dockerfile-path }}" ]; then echo "::set-output name=location::${{ inputs.dockerfile-path }}" + elif [-n "${{ inputs.module-name }}"]; then + echo "::set-output name=location::(${{ inputs.module-name }}/Dockerfile)" else - echo "::set-output name=location::(${{ inputs.module-name }}/Dockerfile)" + echo "Both dockerfile-path and module-name are empty" + exit 1 fi diff --git a/.github/workflows/ci-composite-actions.yml b/.github/workflows/ci-composite-actions.yml index 352977d..9dd52e6 100644 --- a/.github/workflows/ci-composite-actions.yml +++ b/.github/workflows/ci-composite-actions.yml @@ -28,12 +28,12 @@ jobs: - name: "[test] - Get Dockrfile for module - use dockerfile override" uses: yonatankarp/github-actions/.github/actions/get-docker-image-path@extract-dockerfile-location - with: - module-name: "" - dockerfile-path: "dockerfile-location" - - - name: "[test] Get Dockrfile for module - fallback to module" - uses: yonatankarp/github-actions/.github/actions/get-docker-image-path@extract-dockerfile-location - with: - module-name: "test-tag" - dockerfile-path: "" +# with: +# module-name: "" +# dockerfile-path: "dockerfile-location" +# +# - name: "[test] Get Dockrfile for module - fallback to module" +# uses: yonatankarp/github-actions/.github/actions/get-docker-image-path@extract-dockerfile-location +# with: +# module-name: "test-tag" +# dockerfile-path: "" From 9922bcf30937deca559b25374e875ee1401f0b92 Mon Sep 17 00:00:00 2001 From: Yonatan Karp-Rudin Date: Sat, 16 Dec 2023 11:04:46 +0100 Subject: [PATCH 09/11] try using env variables --- .github/actions/get-docker-image-path/action.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/actions/get-docker-image-path/action.yml b/.github/actions/get-docker-image-path/action.yml index 4a73b56..c98ccbc 100644 --- a/.github/actions/get-docker-image-path/action.yml +++ b/.github/actions/get-docker-image-path/action.yml @@ -18,11 +18,14 @@ runs: - name: Find Dockerfile Location id: dockerfile shell: bash + env: + dockefile_path: ${{ inputs.dockerfile-path }} + module_name: ${{ inputs.module-name }} run: | - if [ -n "${{ inputs.dockerfile-path }}" ]; then - echo "::set-output name=location::${{ inputs.dockerfile-path }}" - elif [-n "${{ inputs.module-name }}"]; then - echo "::set-output name=location::(${{ inputs.module-name }}/Dockerfile)" + if [ -n "${dockefile_path}" ]; then + echo "::set-output name=location::${dockefile_path}" + elif [-n "${module_name}"]; then + echo "::set-output name=location::(${module_name}/Dockerfile)" else echo "Both dockerfile-path and module-name are empty" exit 1 From 406f4d6499b9eb080aac5a898e4c1bc8a9241402 Mon Sep 17 00:00:00 2001 From: Yonatan Karp-Rudin Date: Sat, 16 Dec 2023 11:06:08 +0100 Subject: [PATCH 10/11] ?! --- .github/actions/get-docker-image-path/action.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/actions/get-docker-image-path/action.yml b/.github/actions/get-docker-image-path/action.yml index c98ccbc..b6f5bbd 100644 --- a/.github/actions/get-docker-image-path/action.yml +++ b/.github/actions/get-docker-image-path/action.yml @@ -1,11 +1,11 @@ name: 'Detect Dockerfile location' description: 'Decides which location the docker file is located at' inputs: - module-name: + default-directory: description: 'Module name for Gradle build' required: false dockerfile-path: - description: 'An option to override the default dockerfile location, if none supplied the return value would be ${{ inputs.module-name}}/Dockerfile' + description: 'An option to override the default dockerfile location, if none supplied the return value would be ${{ inputs.default-directory}}/Dockerfile' required: false outputs: location: @@ -20,13 +20,13 @@ runs: shell: bash env: dockefile_path: ${{ inputs.dockerfile-path }} - module_name: ${{ inputs.module-name }} + module_name: ${{ inputs.default-directory }} run: | if [ -n "${dockefile_path}" ]; then echo "::set-output name=location::${dockefile_path}" elif [-n "${module_name}"]; then echo "::set-output name=location::(${module_name}/Dockerfile)" else - echo "Both dockerfile-path and module-name are empty" + echo "Both dockerfile-path and default-directory are empty" exit 1 fi From c096f1f22959c1edb676d0810546cecfc146090b Mon Sep 17 00:00:00 2001 From: Yonatan Karp-Rudin Date: Sat, 16 Dec 2023 11:09:41 +0100 Subject: [PATCH 11/11] maybe now? --- .github/actions/get-docker-image-path/action.yml | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/actions/get-docker-image-path/action.yml b/.github/actions/get-docker-image-path/action.yml index b6f5bbd..f75cde4 100644 --- a/.github/actions/get-docker-image-path/action.yml +++ b/.github/actions/get-docker-image-path/action.yml @@ -9,8 +9,8 @@ inputs: required: false outputs: location: - value: string description: the location of the dockerfile that should be used + value: ${{ steps.dockerfile.outputs.location }} runs: using: 'composite' @@ -18,14 +18,11 @@ runs: - name: Find Dockerfile Location id: dockerfile shell: bash - env: - dockefile_path: ${{ inputs.dockerfile-path }} - module_name: ${{ inputs.default-directory }} run: | - if [ -n "${dockefile_path}" ]; then - echo "::set-output name=location::${dockefile_path}" - elif [-n "${module_name}"]; then - echo "::set-output name=location::(${module_name}/Dockerfile)" + if [ -n "${{ inputs.dockerfile-path }}" ]; then + echo "location=${{ inputs.dockerfile-path }}" >> $GITHUB_OUTPUT + elif [-n "${{ inputs.default-directory }}"]; then + echo "location=${{ inputs.default-directory }}/Dockerfile" >> $GITHUB_OUTPUT else echo "Both dockerfile-path and default-directory are empty" exit 1