From edaeb9f96cfca9d4e9d16c2beb561d0c14ea6554 Mon Sep 17 00:00:00 2001 From: Norio Nomura Date: Thu, 25 Jul 2024 18:17:43 +0900 Subject: [PATCH 1/2] check-remote-image-existence.yml: check remote image existence in templates Signed-off-by: Norio Nomura check-remote-image-existence.yml: use actions/checkout@v4 Signed-off-by: Norio Nomura --- .../check-remote-image-existence.yml | 20 +++++++++++++++++++ hack/check-remote-image-existence.sh | 19 ++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 .github/workflows/check-remote-image-existence.yml create mode 100755 hack/check-remote-image-existence.sh diff --git a/.github/workflows/check-remote-image-existence.yml b/.github/workflows/check-remote-image-existence.yml new file mode 100644 index 00000000000..1f185bf90d1 --- /dev/null +++ b/.github/workflows/check-remote-image-existence.yml @@ -0,0 +1,20 @@ +name: Check Remote Image Existence + +on: + pull_request: + paths: + - 'examples/**.yaml' + - 'hack/test-templates/**.yaml' + - 'hack/check-remote-image-existence.sh' + +jobs: + check-remote-image-existence: + name: Check Remote Image Existence + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Run check-remote-image-existence.sh + run: ./hack/check-remote-image-existence.sh diff --git a/hack/check-remote-image-existence.sh b/hack/check-remote-image-existence.sh new file mode 100755 index 00000000000..eb66f6bf495 --- /dev/null +++ b/hack/check-remote-image-existence.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -eu -o pipefail + +# Get the directory of the script +script_dir=$(dirname "$0") + +for template in $(realpath "${script_dir}"/../examples/*.yaml "${script_dir}"/./test-templates/*.yaml|sort -u); do + for location in $(yq eval '.images[].location' "${template}"); do + if [[ "${location}" == http* ]]; then + response=$(curl -L -s -I -o /dev/null -w "%{http_code}" "${location}") + if [[ ${response} != "200" ]]; then + line=$(grep -n "${location}" "${template}" | cut -d ':' -f 1) + echo "::error file=${template},line=${line}::response: ${response} for ${location}" + else + echo "response: ${response} for ${location}" + fi + fi + done +done From 4a460d35adba9e6bbd1d57188b88d28b0b8f760d Mon Sep 17 00:00:00 2001 From: Norio Nomura Date: Thu, 25 Jul 2024 18:26:30 +0900 Subject: [PATCH 2/2] check-remote-image-existence.sh: exit 1 if any image does not exist Signed-off-by: Norio Nomura check-remote-image-existence.sh: change to tab Signed-off-by: Norio Nomura check-remote-image-existence.sh: remove double quotation in [[ ]] Signed-off-by: Norio Nomura check-remote-image-existence.sh: add space to `|` Signed-off-by: Norio Nomura --- hack/check-remote-image-existence.sh | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/hack/check-remote-image-existence.sh b/hack/check-remote-image-existence.sh index eb66f6bf495..161eede87e1 100755 --- a/hack/check-remote-image-existence.sh +++ b/hack/check-remote-image-existence.sh @@ -4,16 +4,20 @@ set -eu -o pipefail # Get the directory of the script script_dir=$(dirname "$0") -for template in $(realpath "${script_dir}"/../examples/*.yaml "${script_dir}"/./test-templates/*.yaml|sort -u); do - for location in $(yq eval '.images[].location' "${template}"); do - if [[ "${location}" == http* ]]; then - response=$(curl -L -s -I -o /dev/null -w "%{http_code}" "${location}") - if [[ ${response} != "200" ]]; then - line=$(grep -n "${location}" "${template}" | cut -d ':' -f 1) - echo "::error file=${template},line=${line}::response: ${response} for ${location}" - else - echo "response: ${response} for ${location}" - fi - fi - done +result=0 +for template in $(realpath "${script_dir}"/../examples/*.yaml "${script_dir}"/./test-templates/*.yaml | sort -u); do + for location in $(yq eval '.images[].location' "${template}"); do + if [[ ${location} == http* ]]; then + response=$(curl -L -s -I -o /dev/null -w "%{http_code}" "${location}") + if [[ ${response} != "200" ]]; then + line=$(grep -n "${location}" "${template}" | cut -d ':' -f 1) + echo "::error file=${template},line=${line}::response: ${response} for ${location}" + result=1 + else + echo "response: ${response} for ${location}" + fi + fi + done done + +exit "${result}"