From e17390ba57f7fc1df2feacf860715164ced578fd Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Tue, 18 Mar 2025 10:46:53 -0400 Subject: [PATCH 1/6] chore: check return status from maven --- .github/scripts/update_generation_config.sh | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/scripts/update_generation_config.sh b/.github/scripts/update_generation_config.sh index 91434688cc..781de8da52 100644 --- a/.github/scripts/update_generation_config.sh +++ b/.github/scripts/update_generation_config.sh @@ -15,7 +15,21 @@ set -e function get_latest_released_version() { local group_id=$1 local artifact_id=$2 - latest=$(curl -s "https://search.maven.org/solrsearch/select?q=g:${group_id}+AND+a:${artifact_id}&core=gav&rows=500&wt=json" | jq -r '.response.docs[] | select(.v | test("^[0-9]+(\\.[0-9]+)*$")) | .v' | sort -V | tail -n 1) + local latest + json_content=$(curl -s "https://search.maven.org/solrsearch/select?q=g:${group_id}+AND+a:${artifact_id}&core=gav&rows=500&wt=json") + status=$(jq -r '.responseHeader.status' <<< "${json_content}") + num_of_rows=$(jq -r '.response.numFound' <<< "${json_content}") + if [[ "${status}" == "0" ]]; then + if [[ "${num_of_rows}" == "0" ]]; then + echo "The number of artifact found is 0." + exit 1 + fi + latest=$(jq -r '.response.docs[] | select(.v | test("^[0-9]+(\\.[0-9]+)*$")) | .v' <<< "${json_content}" | sort -V | tail -n 1) + else + echo "Error: the response status from maven.org is ${status}." + exit 1 + fi + echo "${latest}" } From 3c481e5022dc5c0dcaaea21c07f18b9bf5f124b0 Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Tue, 18 Mar 2025 10:52:34 -0400 Subject: [PATCH 2/6] update workflow --- .github/workflows/update_generation_config.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/update_generation_config.yaml b/.github/workflows/update_generation_config.yaml index f15c807853..648a97b243 100644 --- a/.github/workflows/update_generation_config.yaml +++ b/.github/workflows/update_generation_config.yaml @@ -28,6 +28,7 @@ jobs: steps: - uses: actions/checkout@v4 with: + fetch-depth: 0 token: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }} - name: Update params in generation config to latest shell: bash From 825b15d2b8b4d664d89940490ef0063181c03fbc Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Tue, 18 Mar 2025 12:51:13 -0400 Subject: [PATCH 3/6] verify json content --- .github/scripts/update_generation_config.sh | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/.github/scripts/update_generation_config.sh b/.github/scripts/update_generation_config.sh index 781de8da52..b526bd28bc 100644 --- a/.github/scripts/update_generation_config.sh +++ b/.github/scripts/update_generation_config.sh @@ -15,21 +15,12 @@ set -e function get_latest_released_version() { local group_id=$1 local artifact_id=$2 - local latest json_content=$(curl -s "https://search.maven.org/solrsearch/select?q=g:${group_id}+AND+a:${artifact_id}&core=gav&rows=500&wt=json") - status=$(jq -r '.responseHeader.status' <<< "${json_content}") - num_of_rows=$(jq -r '.response.numFound' <<< "${json_content}") - if [[ "${status}" == "0" ]]; then - if [[ "${num_of_rows}" == "0" ]]; then - echo "The number of artifact found is 0." - exit 1 - fi - latest=$(jq -r '.response.docs[] | select(.v | test("^[0-9]+(\\.[0-9]+)*$")) | .v' <<< "${json_content}" | sort -V | tail -n 1) - else - echo "Error: the response status from maven.org is ${status}." - exit 1 - fi - + # the jq command will fail if one of the scenario happens: + # .response.docs doesn't exist. + # .response.docs is an empty array. + # .response.docs[].v doesn't exist or no qualified one is found. + latest=$(jq 'if .response.docs then if (.response.docs | length) > 0 then .response.docs[] | if (.v | type == "string" and length > 0 and test("^[0-9]+(\\.[0-9]+)*$")) then .v else error("error: .v is invalid in response.docs") end else error("response.docs is empty") end else error("response.docs not found") end' <<< "$json_content") echo "${latest}" } From cda9450e43acdd6133abaeba9fb77dfa1957debe Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Tue, 18 Mar 2025 12:56:44 -0400 Subject: [PATCH 4/6] sort and tail --- .github/scripts/update_generation_config.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/scripts/update_generation_config.sh b/.github/scripts/update_generation_config.sh index b526bd28bc..2f408967be 100644 --- a/.github/scripts/update_generation_config.sh +++ b/.github/scripts/update_generation_config.sh @@ -20,7 +20,9 @@ function get_latest_released_version() { # .response.docs doesn't exist. # .response.docs is an empty array. # .response.docs[].v doesn't exist or no qualified one is found. - latest=$(jq 'if .response.docs then if (.response.docs | length) > 0 then .response.docs[] | if (.v | type == "string" and length > 0 and test("^[0-9]+(\\.[0-9]+)*$")) then .v else error("error: .v is invalid in response.docs") end else error("response.docs is empty") end else error("response.docs not found") end' <<< "$json_content") + latest=$(jq 'if .response.docs then if (.response.docs | length) > 0 then .response.docs[] | if (.v | type == "string" and length > 0 and test("^[0-9]+(\\.[0-9]+)*$")) then .v else error("error: .v is invalid in response.docs") end else error("response.docs is empty") end else error("response.docs not found") end' <<< "$json_content" \ + | sort -V \ + | tail -n 1) echo "${latest}" } From 86d197ced0ba620ca064306c7b544a60e7631df0 Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Tue, 18 Mar 2025 13:04:39 -0400 Subject: [PATCH 5/6] sed --- .github/scripts/update_generation_config.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/scripts/update_generation_config.sh b/.github/scripts/update_generation_config.sh index 2f408967be..5ba7234a84 100644 --- a/.github/scripts/update_generation_config.sh +++ b/.github/scripts/update_generation_config.sh @@ -20,9 +20,10 @@ function get_latest_released_version() { # .response.docs doesn't exist. # .response.docs is an empty array. # .response.docs[].v doesn't exist or no qualified one is found. - latest=$(jq 'if .response.docs then if (.response.docs | length) > 0 then .response.docs[] | if (.v | type == "string" and length > 0 and test("^[0-9]+(\\.[0-9]+)*$")) then .v else error("error: .v is invalid in response.docs") end else error("response.docs is empty") end else error("response.docs not found") end' <<< "$json_content" \ - | sort -V \ - | tail -n 1) + latest=$(jq 'if .response.docs then if (.response.docs | length) > 0 then .response.docs[] | if (.v | type == "string" and length > 0 and test("^[0-9]+(\\.[0-9]+)*$")) then .v else error("error: .v is invalid in response.docs") end else error("response.docs is empty") end else error("response.docs not found") end' <<< "$json_content" | \ + sort -V | \ + tail -n 1 | \ + sed 's/^"//;s/"$//') # remove leading and tailing double quote. echo "${latest}" } From dd267cd7f7508b3d9d2798ccbd436e30520a913b Mon Sep 17 00:00:00 2001 From: Joe Wang Date: Tue, 18 Mar 2025 14:40:24 -0400 Subject: [PATCH 6/6] verify returned version --- .github/scripts/update_generation_config.sh | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/.github/scripts/update_generation_config.sh b/.github/scripts/update_generation_config.sh index 5ba7234a84..fff56bf5dd 100644 --- a/.github/scripts/update_generation_config.sh +++ b/.github/scripts/update_generation_config.sh @@ -16,15 +16,14 @@ function get_latest_released_version() { local group_id=$1 local artifact_id=$2 json_content=$(curl -s "https://search.maven.org/solrsearch/select?q=g:${group_id}+AND+a:${artifact_id}&core=gav&rows=500&wt=json") - # the jq command will fail if one of the scenario happens: - # .response.docs doesn't exist. - # .response.docs is an empty array. - # .response.docs[].v doesn't exist or no qualified one is found. - latest=$(jq 'if .response.docs then if (.response.docs | length) > 0 then .response.docs[] | if (.v | type == "string" and length > 0 and test("^[0-9]+(\\.[0-9]+)*$")) then .v else error("error: .v is invalid in response.docs") end else error("response.docs is empty") end else error("response.docs not found") end' <<< "$json_content" | \ - sort -V | \ - tail -n 1 | \ - sed 's/^"//;s/"$//') # remove leading and tailing double quote. - echo "${latest}" + latest=$(jq -r '.response.docs[] | select(.v | test("^[0-9]+(\\.[0-9]+)*$")) | .v' <<< "${json_content}" | sort -V | tail -n 1) + if [[ -z "${latest}" ]]; then + echo "The latest version of ${group_id}:${artifact_id} is empty." + echo "The returned json from maven.org is invalid: ${json_content}" + exit 1 + else + echo "${latest}" + fi } # Update a key to a new value in the generation config.