Skip to content

Commit cfc7ea2

Browse files
authored
fix: add error handling to script (#7001)
This script lacked error handling, causing it to fail when modules like [java-marketingplatformadminapi](https://github.com/googleapis/google-cloud-java/tree/main/java-marketingplatformadminapi) See context in [doc](https://docs.google.com/document/d/1fh4paz0K_cVmk63nM3PSJj9MkQN8kWCQN2yqfEeF49U/edit?resourcekey=0-uAKnlOeiAnBkQ9Yf-ZCyWw&tab=t.0) This fix is manually tested and can get a peek of data with ``` SELECT * FROM `cloud-java-metrics.client_library_versions.cloud_java_client_library_release_dates` WHERE TIMESTAMP_TRUNC(_PARTITIONTIME, DAY) = TIMESTAMP("2025-03-27") LIMIT 1000 ``` For longer term, consider adding tests and/or refactoring.
1 parent 287b7f3 commit cfc7ea2

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

.kokoro/nightly/get-service-names.sh

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,32 @@ for module in $(find . -mindepth 2 -maxdepth 2 -name pom.xml | sort | xargs dirn
2929
# and locate artifact id of client library
3030
folder=$(find . -mindepth 1 -maxdepth 1 -type d -name "google-*" ! -name "*-bom" )
3131
echo "folder: ${folder}"
32+
if [[ -z "${folder}" ]]; then
33+
echo "Warning: No 'google-*' folder found in ${module}, skipping..."
34+
cd .. # Ensure we go back to the parent directory
35+
continue
36+
fi
3237
cd "${folder}" || continue
3338
artifact_id_string=$(find . -name 'pom.xml' -print -quit | xargs grep -m 1 '<artifactId>' | cut -d '>' -f 2 | cut -d '<' -f 1)
3439
echo "artifact_id_string: ${artifact_id_string}"
40+
if [[ -z "${artifact_id_string}" ]]; then
41+
echo "Warning: Could not find <artifactId> in pom.xml within ${folder}, skipping..."
42+
cd .. # Exit from ${folder}
43+
cd .. # Exit from ${module}
44+
continue
45+
fi
3546
cd .. # exist from folder ${folder}
3647

3748
# Find *StubSettings file, get the first line containing '.googleapis.com:443'
3849
# Extract service name from it
39-
string=$(find . -name '*StubSettings.java' -print -quit | xargs grep -m 1 '.googleapis.com:443')
40-
service_name=$(echo "${string}" | grep -o '".*"' | tr -d '"' | cut -d "." -f 1 | cut -d "-" -f 1)
41-
echo "service name: ${service_name}"
50+
first_line_contain_endpoint=$(find . -name '*StubSettings.java' -print -quit | xargs grep -m 1 '.googleapis.com:443')
51+
service_name="" # Initialize service_name to an empty string
52+
if [[ -n "${first_line_contain_endpoint}" ]]; then
53+
service_name=$(echo "${first_line_contain_endpoint}" | grep -o '".*"' | tr -d '"' | cut -d "." -f 1 | cut -d "-" -f 1)
54+
echo "service name: ${service_name}"
55+
else
56+
echo "Warning: Could not find '*StubSettings.java' containing '.googleapis.com:443' in ${module}"
57+
fi
4258
echo "${artifact_id_string}, ${service_name}" >> "$filename"
4359
cd .. # exit from ${module}
4460
done
@@ -62,4 +78,4 @@ done
6278
cd ..
6379
mv ./google-cloud-java/artifacts_to_services.txt ./libraries-release-data/artifacts_to_services.txt
6480
# clean up
65-
rm -rf google-cloud-java/
81+
rm -rf google-cloud-java/

0 commit comments

Comments
 (0)