Skip to content

Commit edde57d

Browse files
committed
chore: Use function to build artifact list
1 parent dffa8fa commit edde57d

File tree

2 files changed

+42
-45
lines changed

2 files changed

+42
-45
lines changed

.kokoro/nightly/downstream-protobuf-binary-compatibility.sh

Lines changed: 41 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515

1616
set -eo pipefail
1717

18-
pwd
19-
2018
# Comma-delimited list of repos to test with the local java-shared-dependencies
2119
if [ -z "${REPOS_UNDER_TEST}" ]; then
2220
echo "REPOS_UNDER_TEST must be set to run downstream-protobuf-binary-compatibility.sh"
@@ -34,14 +32,42 @@ fi
3432
# Create two mappings of possible API names (Key: Maven Artifact ID Prefix, Value: Maven Group ID)
3533
# for the libraries that should be tested.
3634
# 1. These are special handwritten libraries in google-cloud-java that should be tested
37-
declare -A google_cloud_java_handwritten_libraries
38-
google_cloud_java_handwritten_libraries["grafeas"]="io.grafeas"
39-
google_cloud_java_handwritten_libraries["google-cloud-vertexai"]="com.google.cloud"
40-
google_cloud_java_handwritten_libraries["google-cloud-resourcemanager"]="com.google.cloud"
35+
declare -A monorepo_handwritten_libraries
36+
monorepo_handwritten_libraries["grafeas"]="io.grafeas"
37+
monorepo_handwritten_libraries["google-cloud-vertexai"]="com.google.cloud"
38+
monorepo_handwritten_libraries["google-cloud-resourcemanager"]="com.google.cloud"
39+
40+
# 2. These are the mappings of all the downstream handwritten libraries' artifacts
41+
declare -A downstream_handwritten_libraries
42+
downstream_handwritten_libraries["google-cloud"]="com.google.cloud"
43+
44+
# Builds a string output to `artifact_list`. It contains a comma separate list of Maven GAV coordinates. Parses
45+
# the `versions.txt` file by searching for the matching artifact_id_prefix to get the corresponding version.
46+
function build_artifact_list() {
47+
local -n api_maven_mapping=$1
48+
for artifact_id_prefix in "${!api_maven_mapping[@]}"; do
49+
group_id="${api_maven_mapping[${artifact_id_prefix}]}"
4150

42-
# 2. These are the mappings of all the downstream handwritten libraries
43-
declare -A gcp_handwritten_libraries
44-
gcp_handwritten_libraries["google-cloud"]="com.google.cloud"
51+
# Match all artifacts that start with the artifact_id_prefix to exclude any proto and grpc modules.
52+
repo_artifact_list=$(cat "versions.txt" | grep "^${artifact_id_prefix}" || true)
53+
54+
# Only proceed if there are matching elements
55+
if [ -n "${repo_artifact_list}" ]; then
56+
# Exclude any matches to BOM artifacts or emulators. The repo artifact list will look like:
57+
# "com.google.cloud:google-cloud-accessapproval:2.60.0-SNAPSHOT,com.google.cloud:google-cloud-aiplatform:3.60.0-SNAPSHOT,"
58+
repo_artifact_list=$(echo "${repo_artifact_list}" | grep -vE "(bom|emulator|google-cloud-java)" | awk -F: "{\$1=\"${group_id}:\"\$1; \$2=\"\"; print}" OFS=: | sed 's/::/:/' | tr '\n' ',')
59+
# Remove the trailing comma after the last entry
60+
repo_artifact_list=${repo_artifact_list%,}
61+
62+
# The first entry added is not separated with a comma. Avoids generating `,{ARTIFACT_LIST}`
63+
if [ -z "${artifact_list}" ]; then
64+
artifact_list="${repo_artifact_list}"
65+
else
66+
artifact_list="${artifact_list},${repo_artifact_list}"
67+
fi
68+
fi
69+
done
70+
}
4571

4672
# cloud-opensource-java contains the Linkage Checker tool
4773
git clone https://github.com/GoogleCloudPlatform/cloud-opensource-java.git
@@ -50,53 +76,25 @@ mvn -B -ntp clean compile -T 1C
5076
# Linkage Checker tool resides in the /dependencies subfolder
5177
pushd dependencies
5278

53-
function build_artifact_list() {
54-
local artifact_id_prefix=$1
55-
local group_id=$2
56-
# Match all artifacts that start with the artifact_id_prefix to exclude any proto and grpc modules.
57-
repo_artifact_list=$(cat "versions.txt" | grep "^${artifact_id_prefix}" || true)
58-
59-
# Only proceed if there are matching elements
60-
if [ -n "${repo_artifact_list}" ]; then
61-
# Exclude any matches to BOM artifacts or emulators. The repo artifact list will look like:
62-
# "com.google.cloud:google-cloud-accessapproval:2.60.0-SNAPSHOT,com.google.cloud:google-cloud-aiplatform:3.60.0-SNAPSHOT,"
63-
repo_artifact_list=$(echo "${repo_artifact_list}" | grep -vE "(bom|emulator|google-cloud-java)" | awk -F: "{\$1=\"${group_id}:\"\$1; \$2=\"\"; print}" OFS=: | sed 's/::/:/' | tr '\n' ',')
64-
# Remove the trailing comma after the last entry
65-
repo_artifact_list=${repo_artifact_list%,}
66-
67-
# The first entry added is not separated with a comma. Avoids generating `,{ARTIFACT_LIST}`
68-
if [ -z "${artifact_list}" ]; then
69-
artifact_list="${repo_artifact_list}"
70-
else
71-
artifact_list="${artifact_list},${repo_artifact_list}"
72-
fi
73-
fi
74-
}
75-
7679
for repo in ${REPOS_UNDER_TEST//,/ }; do # Split on comma
7780
if [ "${REPOS_INSTALLED_LOCALLY}" != "true" ]; then
7881
# Perform testing on main (with latest changes). Shallow copy as history is not important
7982
git clone "https://github.com/googleapis/${repo}.git" --depth=1
80-
pushd "../../${repo}"
83+
pushd "${repo}"
8184
# Install all repo modules to ~/.m2 (there can be multiple relevant artifacts to test i.e. core, admin, control)
8285
mvn -B -ntp install -T 1C -DskipTests -Dclirr.skip -Denforcer.skip
8386
else
87+
# If installed locally to .m2, then just pull the versions.txt file to parse
88+
mkdir -p "../../${repo}"
8489
pushd "../../${repo}"
85-
# curl -O "https://raw.githubusercontent.com/googleapis/${repo}/refs/heads/main/versions.txt"
90+
curl -Os "https://raw.githubusercontent.com/googleapis/${repo}/refs/heads/main/versions.txt"
8691
fi
8792

88-
# The artifact_list will be a comma separate list of artifacts
8993
artifact_list=""
9094
if [ "${repo}" == "google-cloud-java" ]; then
91-
for artifact_id_prefix in "${!google_cloud_java_handwritten_libraries[@]}"; do
92-
group_id="${google_cloud_java_handwritten_libraries[${artifact_id_prefix}]}"
93-
build_artifact_list "${artifact_id_prefix}" "${group_id}"
94-
done
95+
build_artifact_list monorepo_handwritten_libraries
9596
else
96-
for artifact_id_prefix in "${!gcp_handwritten_libraries[@]}"; do
97-
group_id="${gcp_handwritten_libraries[${artifact_id_prefix}]}"
98-
build_artifact_list "${artifact_id_prefix}" "${group_id}"
99-
done
97+
build_artifact_list downstream_handwritten_libraries
10098
fi
10199

102100
# Linkage Checker /dependencies
@@ -105,7 +103,6 @@ for repo in ${REPOS_UNDER_TEST//,/ }; do # Split on comma
105103
echo "Artifact List: ${artifact_list}"
106104
# Only run Linkage Checker if the repo has any relevant artifacts to test for
107105
if [ -n "${artifact_list}" ]; then
108-
echo "Found artifacts ${artifact_list}"
109106
# The `-s` argument filters the linkage check problems that stem from the artifact
110107
program_args="-r --artifacts ${artifact_list},com.google.protobuf:protobuf-java:${PROTOBUF_RUNTIME_VERSION},com.google.protobuf:protobuf-java-util:${PROTOBUF_RUNTIME_VERSION} -s ${artifact_list}"
111108
echo "Linkage Checker Program Arguments: ${program_args}"

.kokoro/nightly/downstream-protobuf-source-compatibility.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ for repo in ${REPOS_UNDER_TEST//,/ }; do # Split on comma
4141

4242
# Compile the Handwritten Library with the Protobuf-Java version to test source compatibility
4343
# Run unit tests to help check for any behavior differences (dependant on coverage)
44-
mvn test -B -V -ntp \
44+
mvn compile -B -V -ntp \
4545
-Dclirr.skip=true \
4646
-Denforcer.skip=true \
4747
-Dmaven.javadoc.skip=true \

0 commit comments

Comments
 (0)