From 51b1c9cb386d35ea333c82c8673367247274bd18 Mon Sep 17 00:00:00 2001 From: Alice Li Date: Fri, 10 May 2024 16:07:50 -0400 Subject: [PATCH 1/4] fix: update generate-library-list.sh for duplicate api_shortnames --- .github/workflows/generateAutoConfigs.yaml | 2 +- .../scripts/generate-library-list.sh | 27 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/.github/workflows/generateAutoConfigs.yaml b/.github/workflows/generateAutoConfigs.yaml index fe409bb944..f801d2d50d 100644 --- a/.github/workflows/generateAutoConfigs.yaml +++ b/.github/workflows/generateAutoConfigs.yaml @@ -5,7 +5,7 @@ on: branch_name: description: PR branch name required: true - default: "renovate/main-gcp-libraries-bom.version" + default: "renovate/gcp-libraries-bom.version" forked_repo: description: Fork name (enter none if repo branch) required: true diff --git a/spring-cloud-generator/scripts/generate-library-list.sh b/spring-cloud-generator/scripts/generate-library-list.sh index 2e9be5243d..d1b2752048 100755 --- a/spring-cloud-generator/scripts/generate-library-list.sh +++ b/spring-cloud-generator/scripts/generate-library-list.sh @@ -23,16 +23,21 @@ cd ${SPRING_GENERATOR_DIR} filename=${SPRING_GENERATOR_DIR}/scripts/resources/library_list.txt echo "# api_shortname, googleapis-folder, distribution_name:version, monorepo_folder" > "$filename" -# loop through folders +# loop through configs for the monorepo (google-cloud-java) count=0 -for d in ./google-cloud-java/*java-*/; do - # parse variables from .repo-metadata.json - language=$(cat $d/.repo-metadata.json | jq -r .language) - api_shortname=$(cat $d/.repo-metadata.json | jq -r .api_shortname) - distribution_name=$(cat $d/.repo-metadata.json | jq -r .distribution_name) - library_type=$(cat $d/.repo-metadata.json | jq -r .library_type) - release_level=$(cat $d/.repo-metadata.json | jq -r .release_level) - monorepo_folder=$(basename $d) +configs=$(yq e '.libraries[]' ./google-cloud-java/generate_config.yaml) +for config_str in $configs; do + # parse variables from generation_config.yaml + config=$(echo "$config_str" | yq e '.') # Parse config_str back to YAML format + unique_module_name=$(echo "$config" | jq -r '.library_name // .api_shortname') + # Determine distribution_name + distribution_name=$(echo "$config" | jq -r '.distribution_name' // "") + if [ -z "$distribution_name" ]; then + distribution_name="com.google.cloud:google-cloud-${unique_module_name}" + fi + library_type=$(echo "$config" | jq -r '.library_type // "GAPIC_AUTO"') # default to GAPIC_AUTO per https://github.com/googleapis/sdk-platform-java/blob/v2.40.0/library_generation/model/library_config.py#L57 + release_level=$(echo "$config" | jq -r '.release_level // "preview"') # default to preview per https://github.com/googleapis/sdk-platform-java/blob/v2.40.0/library_generation/model/library_config.py#L58 + monorepo_folder="java/${unique_module_name}" group_id=$(echo $distribution_name | cut -f1 -d:) artifact_id=$(echo $distribution_name | cut -f2 -d:) @@ -55,9 +60,9 @@ for d in ./google-cloud-java/*java-*/; do continue fi - # parse proto path from generation_config.yaml, find by api_shortname + # parse proto path from generation_config.yaml, find by unique_module_name, which will match library_name if it exists, or api_shortname if library_name does not exist # then sort and keep latest stable version - library=$(yq -r '.libraries[] | select(.api_shortname == "'"$api_shortname"'")' ./google-cloud-java/generation_config.yaml) + library=$(yq -r '.libraries[] | select(.library_name == "'"$unique_module_name"'" or .api_shortname == "'"$unique_module_name"'" )' ./google-cloud-java/generation_config.yaml) proto_paths_stable=$(echo "$library" | yq -r '.GAPICs[] | select(.proto_path | test("/v[0-9]+$")) | .proto_path') proto_paths_latest=$(echo "$proto_paths_stable" | sort -d -r | head -n 1) From 0e80b005c9382e055e3e3559952e6317682e78f6 Mon Sep 17 00:00:00 2001 From: Alice Li Date: Fri, 10 May 2024 21:21:47 -0400 Subject: [PATCH 2/4] add comment about non-cloud apis --- spring-cloud-generator/scripts/generate-library-list.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-cloud-generator/scripts/generate-library-list.sh b/spring-cloud-generator/scripts/generate-library-list.sh index d1b2752048..7b7f0c8684 100755 --- a/spring-cloud-generator/scripts/generate-library-list.sh +++ b/spring-cloud-generator/scripts/generate-library-list.sh @@ -24,6 +24,7 @@ filename=${SPRING_GENERATOR_DIR}/scripts/resources/library_list.txt echo "# api_shortname, googleapis-folder, distribution_name:version, monorepo_folder" > "$filename" # loop through configs for the monorepo (google-cloud-java) +# Note that this logic will not work for non-cloud APIs count=0 configs=$(yq e '.libraries[]' ./google-cloud-java/generate_config.yaml) for config_str in $configs; do From c570c437d96742579b88ae0e29d7c1211031a4ba Mon Sep 17 00:00:00 2001 From: Alice Li Date: Tue, 14 May 2024 10:00:20 -0400 Subject: [PATCH 3/4] use jq instead of yq --- spring-cloud-generator/scripts/generate-library-list.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-cloud-generator/scripts/generate-library-list.sh b/spring-cloud-generator/scripts/generate-library-list.sh index 7b7f0c8684..dd6f5867f4 100755 --- a/spring-cloud-generator/scripts/generate-library-list.sh +++ b/spring-cloud-generator/scripts/generate-library-list.sh @@ -26,7 +26,7 @@ echo "# api_shortname, googleapis-folder, distribution_name:version, monorepo_fo # loop through configs for the monorepo (google-cloud-java) # Note that this logic will not work for non-cloud APIs count=0 -configs=$(yq e '.libraries[]' ./google-cloud-java/generate_config.yaml) +configs=$(jq '.libraries[]' ./google-cloud-java/generate_config.yaml) for config_str in $configs; do # parse variables from generation_config.yaml config=$(echo "$config_str" | yq e '.') # Parse config_str back to YAML format From 4d5e36ade927e79330207438b0635d0d47ff87cd Mon Sep 17 00:00:00 2001 From: Alice Li Date: Tue, 14 May 2024 13:03:20 -0400 Subject: [PATCH 4/4] update script --- .../scripts/generate-library-list.sh | 87 ++++++++++--------- 1 file changed, 47 insertions(+), 40 deletions(-) diff --git a/spring-cloud-generator/scripts/generate-library-list.sh b/spring-cloud-generator/scripts/generate-library-list.sh index dd6f5867f4..76da87599e 100755 --- a/spring-cloud-generator/scripts/generate-library-list.sh +++ b/spring-cloud-generator/scripts/generate-library-list.sh @@ -26,48 +26,55 @@ echo "# api_shortname, googleapis-folder, distribution_name:version, monorepo_fo # loop through configs for the monorepo (google-cloud-java) # Note that this logic will not work for non-cloud APIs count=0 -configs=$(jq '.libraries[]' ./google-cloud-java/generate_config.yaml) -for config_str in $configs; do - # parse variables from generation_config.yaml - config=$(echo "$config_str" | yq e '.') # Parse config_str back to YAML format - unique_module_name=$(echo "$config" | jq -r '.library_name // .api_shortname') - # Determine distribution_name - distribution_name=$(echo "$config" | jq -r '.distribution_name' // "") - if [ -z "$distribution_name" ]; then - distribution_name="com.google.cloud:google-cloud-${unique_module_name}" - fi - library_type=$(echo "$config" | jq -r '.library_type // "GAPIC_AUTO"') # default to GAPIC_AUTO per https://github.com/googleapis/sdk-platform-java/blob/v2.40.0/library_generation/model/library_config.py#L57 - release_level=$(echo "$config" | jq -r '.release_level // "preview"') # default to preview per https://github.com/googleapis/sdk-platform-java/blob/v2.40.0/library_generation/model/library_config.py#L58 - monorepo_folder="java/${unique_module_name}" - group_id=$(echo $distribution_name | cut -f1 -d:) - artifact_id=$(echo $distribution_name | cut -f2 -d:) - # filter to in-scope libraries - if [[ $library_type != *GAPIC_AUTO* ]] ; then - echo "$d: non auto type: $library_type" - continue - fi - if [[ $group_id != "com.google.cloud" ]] ; then - echo "$d: group_id not in scope: $group_id" - continue - fi - if [[ $release_level != "stable" ]] ; then - echo "$d: release_level: $release_level" - continue - fi - # checks if library is in the manual modules exclusion list - if [[ $(cat ${SPRING_GENERATOR_DIR}/scripts/resources/manual_modules_exclusion_list.txt | tail -n+2 | grep $artifact_id | wc -l) -ne 0 ]] ; then - echo "$artifact_id is already present in manual modules." - continue - fi +configs=$(yq eval '.libraries[]' -o=json ./google-cloud-java/generation_config.yaml) +# Properly format the configs as a JSON array +# This includes adding commas between objects and wrapping everything in square brackets +json_array="[ $(echo "$configs" | tr '\n' ' ' | sed 's/} {/}, {/g') ]" - # parse proto path from generation_config.yaml, find by unique_module_name, which will match library_name if it exists, or api_shortname if library_name does not exist - # then sort and keep latest stable version - library=$(yq -r '.libraries[] | select(.library_name == "'"$unique_module_name"'" or .api_shortname == "'"$unique_module_name"'" )' ./google-cloud-java/generation_config.yaml) - proto_paths_stable=$(echo "$library" | yq -r '.GAPICs[] | select(.proto_path | test("/v[0-9]+$")) | .proto_path') - proto_paths_latest=$(echo "$proto_paths_stable" | sort -d -r | head -n 1) +# Parse each object in the JSON array +while IFS= read -r config; do + # Extract library_name if present, otherwise use api_shortname + unique_module_name=$(echo "$config" | jq -r '.library_name // .api_shortname') + # Display the unique module name + echo "Unique Module Name: $unique_module_name" + distribution_name=$(echo "$config" | jq -r '.distribution_name // ""') + if [ -z "$distribution_name" ]; then + distribution_name="com.google.cloud:google-cloud-${unique_module_name}" + fi + echo "Distribution name: $distribution_name" + library_type=$(echo "$config" | jq -r '.library_type // "GAPIC_AUTO"') # default to GAPIC_AUTO per https://github.com/googleapis/sdk-platform-java/blob/v2.40.0/library_generation/model/library_config.py#L57 + echo "library_type: $library_type" + release_level=$(echo "$config" | jq -r '.release_level // "preview"') # default to preview per https://github.com/googleapis/sdk-platform-java/blob/v2.40.0/library_generation/model/library_config.py#L58 + echo "release_level: $release_level" + monorepo_folder="java/${unique_module_name}" + echo "monorepo folder: $monorepo_folder" + group_id=$(echo $distribution_name | cut -f1 -d:) + artifact_id=$(echo $distribution_name | cut -f2 -d:) + # filter to in-scope libraries + if [[ $library_type != *GAPIC_AUTO* ]] ; then + echo "$d: non auto type: $library_type" + continue + fi + if [[ $group_id != "com.google.cloud" ]] ; then + echo "$d: group_id not in scope: $group_id" + continue + fi + if [[ $release_level != "stable" ]] ; then + echo "$d: release_level: $release_level" + continue + fi + # checks if library is in the manual modules exclusion list + if [[ $(cat ${SPRING_GENERATOR_DIR}/scripts/resources/manual_modules_exclusion_list.txt | tail -n+2 | grep $artifact_id | wc -l) -ne 0 ]] ; then + echo "$artifact_id is already present in manual modules." + continue + fi + proto_paths_stable=$(echo "$config" | yq -r '.GAPICs[] | select(.proto_path | test("/v[0-9]+$")) | .proto_path') + echo "proto_paths_stable : $proto_paths_stable" + proto_paths_latest=$(echo "$proto_paths_stable" | sort -d -r | head -n 1) + echo "proto_paths_latest : $proto_paths_latest" - echo "$api_shortname, $proto_paths_latest, $distribution_name, $monorepo_folder" >> $filename + echo "$unique_module_name, $proto_paths_latest, $distribution_name, $monorepo_folder" >> $filename count=$((count+1)) -done +done < <(echo "$json_array" | jq -c '.[]') echo "Total in-scope client libraries: $count"