-
Notifications
You must be signed in to change notification settings - Fork 319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: restore showcase autogen IT #2895
Changes from 19 commits
7cfc510
457e542
9a8b6c3
57ffaf0
b146141
495b049
6ae8d97
edde192
7bef47a
e337c6e
b444b7c
deb732e
be9f316
662d764
a7e675c
f61d2bb
235478a
b17b1d8
2d0f4bc
c05b3a9
5b9fb60
d8e5a31
23f7e16
7f13152
2bd371c
407d35c
9bf447a
b0b695f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,38 @@ | ||
# Ignore folders | ||
target/ | ||
bin/ | ||
/config | ||
/.idea | ||
/out | ||
|
||
# Do not ignore them | ||
!.idea/copyright | ||
!.idea/inspectionProfiles | ||
!.idea/scopes | ||
!.idea/codeStyleSettings.xml | ||
!.idea/vcs.xml | ||
|
||
# Ignore files | ||
access.properties | ||
mail.properties | ||
*.iml | ||
*.ipr | ||
*.iws | ||
.project | ||
.classpath | ||
.settings/ | ||
.sts4-cache/ | ||
|
||
# Ignore to avoid pushing maven wrapper jar as binary artifact | ||
.mvn/wrapper/maven-wrapper.jar | ||
|
||
# Because re-configuring the directory in the share plugin leads to side effect we ignore the file | ||
dependency-reduced-pom.xml | ||
.factorypath | ||
|
||
# Ignore OSX autogenerated files | ||
.DS_Store | ||
|
||
.flattened-pom.xml | ||
*.versionsBackup | ||
# Ignore folders | ||
target/ | ||
bin/ | ||
/config | ||
/.idea | ||
/out | ||
|
||
# Do not ignore them | ||
!.idea/copyright | ||
!.idea/inspectionProfiles | ||
!.idea/scopes | ||
!.idea/codeStyleSettings.xml | ||
!.idea/vcs.xml | ||
|
||
# Ignore files | ||
access.properties | ||
mail.properties | ||
*.iml | ||
*.ipr | ||
*.iws | ||
*.swp | ||
.project | ||
.classpath | ||
.settings/ | ||
.sts4-cache/ | ||
|
||
# Ignore to avoid pushing maven wrapper jar as binary artifact | ||
.mvn/wrapper/maven-wrapper.jar | ||
|
||
# Because re-configuring the directory in the share plugin leads to side effect we ignore the file | ||
dependency-reduced-pom.xml | ||
.factorypath | ||
|
||
# Ignore OSX autogenerated files | ||
.DS_Store | ||
|
||
.flattened-pom.xml | ||
*.versionsBackup |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,174 @@ | ||
#!/bin/bash | ||
set -e | ||
set -ex | ||
|
||
# To VERIFY: ./scripts/generate-showcase.sh | ||
# To UPDATE: /scripts/generate-showcase.sh -u | ||
UPDATE=0 | ||
# To verify: ./scripts/generate-showcase.sh | ||
# To update: /scripts/generate-showcase.sh -u | ||
update="false" | ||
while getopts u flag | ||
do | ||
case "${flag}" in | ||
u) UPDATE=1;; | ||
u) update="true";; | ||
esac | ||
done | ||
|
||
# For reusing bazel setup modifications and post-processing steps | ||
source ./scripts/generate-steps.sh | ||
|
||
# If not set, assume working directory is spring-cloud-generator | ||
if [[ -z "$SPRING_GENERATOR_DIR" ]]; then | ||
SPRING_GENERATOR_DIR=`pwd` | ||
if [[ -z "${SPRING_GENERATOR_DIR}" ]]; then | ||
SPRING_GENERATOR_DIR=$(pwd) | ||
fi | ||
SPRING_ROOT_DIR=${SPRING_GENERATOR_DIR}/.. | ||
SHOWCASE_STARTER_OLD_DIR=${SPRING_GENERATOR_DIR}/showcase/showcase-spring-starter | ||
SHOWCASE_STARTER_NEW_DIR=${SPRING_GENERATOR_DIR}/showcase/showcase-spring-starter-generated | ||
spring_root_dir=${SPRING_GENERATOR_DIR}/.. | ||
showcase_starter_old_dir=${SPRING_GENERATOR_DIR}/showcase/showcase-spring-starter | ||
showcase_starter_new_dir=${SPRING_GENERATOR_DIR}/showcase/showcase-spring-starter-generated | ||
|
||
# Verifies newly generated showcase-spring-starter against goldens | ||
# | ||
# $1 - directory containing existing showcase-spring-starter (golden) | ||
# $2 - directory containing newly generated showcase-spring-starter | ||
function verify(){ | ||
OLD_DIR=$1 | ||
NEW_DIR=$2 | ||
SHOWCASE_STARTER_DIFF=$(diff -r ${NEW_DIR}/src/main ${OLD_DIR}/src/main) | ||
SHOWCASE_STARTER_POM_DIFF=$(diff -r ${NEW_DIR}/pom.xml ${OLD_DIR}/pom.xml) | ||
if [ "$SHOWCASE_STARTER_DIFF" != "" ] || [ "$SHOWCASE_STARTER_POM_DIFF" != "" ] | ||
old_dir=$1 | ||
new_dir=$2 | ||
showcase_starter_diff=$(diff -r ${new_dir}/src/main ${old_dir}/src/main) | ||
showcase_starter_pom_diff=$(diff -r ${new_dir}/pom.xml ${old_dir}/pom.xml) | ||
if [ "${showcase_starter_diff}" != "" ] || [ "${showcase_starter_pom_diff}" != "" ] | ||
then | ||
echo "Differences detected in generated showcase starter module: " | ||
echo "Diff from src/main: " | ||
echo $SHOWCASE_STARTER_DIFF | ||
echo "${showcase_starter_diff}" | ||
echo "Diff from pom.xml: " | ||
echo $SHOWCASE_STARTER_POM_DIFF | ||
echo "${showcase_starter_pom_diff}" | ||
exit 1; | ||
else | ||
echo "No differences found in showcase-spring-starter" | ||
rm -r ${NEW_DIR} | ||
rm -r "${new_dir}" | ||
fi | ||
} | ||
|
||
# Setup, generation, and post-processing steps for showcase-spring-starter | ||
# | ||
# $1 - target directory for generated starter | ||
function generate_showcase_spring_starter(){ | ||
SHOWCASE_STARTER_DIR=$1 | ||
showcase_starter_dir=$1 | ||
|
||
# Compute the parent project version. | ||
cd ${SPRING_ROOT_DIR} | ||
PROJECT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) | ||
cd ${SPRING_GENERATOR_DIR} | ||
GAPIC_GENERATOR_JAVA_VERSION=$(mvn help:evaluate -Dexpression=gapic-generator-java-bom.version -q -DforceStdout) | ||
pushd "${spring_root_dir}" | ||
export project_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) | ||
cd "${SPRING_GENERATOR_DIR}" | ||
gapic_generator_java_version=$(mvn help:evaluate -Dexpression=gapic-generator-java-bom.version -q -DforceStdout) | ||
|
||
if [[ -z "$GAPIC_GENERATOR_JAVA_VERSION" ]]; then | ||
if [[ -z "${gapic_generator_java_version}" ]]; then | ||
echo "Missing sdk-platform-java commitish to checkout" | ||
exit 1 | ||
fi | ||
|
||
# Clone sdk-platform-java (with showcase library) | ||
git clone https://github.com/googleapis/sdk-platform-java.git | ||
cd sdk-platform-java && git checkout "v${GAPIC_GENERATOR_JAVA_VERSION}" | ||
if [[ ! -d "./sdk-platform-java" ]]; then | ||
git clone https://github.com/googleapis/sdk-platform-java.git | ||
fi | ||
pushd sdk-platform-java | ||
git checkout "v${gapic_generator_java_version}" | ||
|
||
# We will use the generation tools from library_generation | ||
pushd library_generation/utils | ||
source utilities.sh | ||
popd #library_generation/utils | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How many utility methods in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm moving them to |
||
|
||
# Install showcase client libraries locally | ||
cd showcase && mvn clean install | ||
GAPIC_SHOWCASE_CLIENT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) | ||
pushd showcase | ||
# For local development, we cleanup any traces of previous runs | ||
rm -rdf output | ||
mvn clean install | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Everything below uses |
||
gapic_showcase_client_version=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) | ||
|
||
pushd gapic-showcase | ||
gapic_showcase_server_version=$(mvn help:evaluate -Dexpression=gapic-showcase.version -q -DforceStdout) | ||
popd #showcase/gapic-showcase | ||
|
||
output_folder=$(get_output_folder) | ||
mkdir "${output_folder}" | ||
pushd "${output_folder}" | ||
protoc_version=$(get_protoc_version "${gapic_generator_java_version}") | ||
os_architecture=$(detect_os_architecture) | ||
download_protoc "${protoc_version}" "${os_architecture}" | ||
|
||
# We now copy the spring-cloud-generator and gapic-generator-java jar into the output_folder the | ||
# sdk-platform-java generation scripts work with. | ||
spring_generator_jar_name="spring-cloud-generator-${project_version}-jar-with-dependencies.jar" | ||
cp ~/.m2/repository/com/google/cloud/spring-cloud-generator/"${project_version}/${spring_generator_jar_name}" \ | ||
"${output_folder}" | ||
chmod 555 ${output_folder}/*.jar | ||
|
||
# We download gapic-showcase and prepare the protos in output_folder | ||
sparse_clone https://github.com/googleapis/gapic-showcase.git "schema/google/showcase/v1beta1" | ||
pushd gapic-showcase | ||
git checkout "v${gapic_showcase_server_version}" | ||
cp -r schema "${output_folder}" | ||
popd #gapic-showcase | ||
|
||
# We download googleapis and prepare the protos in output_folder | ||
if [[ ! -d "./googleapis" ]]; then | ||
sparse_clone https://github.com/googleapis/googleapis.git "google/iam/v1 google/cloud/location google/api google/longrunning google/rpc google/type" | ||
fi | ||
pushd googleapis | ||
cp -r google "${output_folder}" | ||
popd #gapic-showcase | ||
|
||
burkedavison marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# Now we call protoc with a series of arguments we obtain from | ||
# sdk-platform-java's utilities.sh and others that are hardcoded (and stable). | ||
# Note that --java_gapic_spring_opt uses `get_gapic_opts` which will work | ||
# since the BUILD rules take similar arguments | ||
|
||
proto_path="schema/google/showcase/v1beta1" | ||
proto_files=$(find "${proto_path}" -type f -name "*.proto" | LC_COLLATE=C sort) | ||
gapic_additional_protos="google/iam/v1/iam_policy.proto google/cloud/location/locations.proto" | ||
rest_numeric_enums="false" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need these additional protos, same thing for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @blakeli0 when removing the additional protos, the generated code has missing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Removing
I'll keep checking on the other params There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. SG, we can keep the ones produce changes. |
||
transport="grpc+rest" | ||
gapic_yaml="" | ||
service_config="schema/google/showcase/v1beta1/showcase_grpc_service_config.json" | ||
service_yaml="schema/google/showcase/v1beta1/showcase_v1beta1.yaml" | ||
include_samples="false" | ||
output_srcjar_zip_name="showcase_java_gapic_spring_raw.srcjar.zip" | ||
|
||
"${protoc_path}"/protoc \ | ||
"--experimental_allow_proto3_optional" \ | ||
"--plugin=protoc-gen-java_gapic_spring=${SPRING_GENERATOR_DIR}/spring-cloud-generator-wrapper" \ | ||
"--java_gapic_spring_out=${output_folder}/${output_srcjar_zip_name}" \ | ||
"--java_gapic_spring_opt=$(get_gapic_opts "${transport}" "${rest_numeric_enums}" "${gapic_yaml}" "${service_config}" "${service_yaml}")" \ | ||
${proto_files} ${gapic_additional_protos} # Do not quote because this variable should not be treated as one long string. | ||
|
||
# Alternative: if showcase client library is available on Maven Central, | ||
# Instead of downloading sdk-platform-java/showcase (for client library, and generation setup), | ||
# Can instead download googleapis (for generation setup) and gapic-showcase (for protos) | ||
|
||
# Modify sdk-platform-java/WORKSPACE | ||
modify_workspace_file "../WORKSPACE" ".." "../../scripts/resources/googleapis_modification_string.txt" | ||
# Modify sdk-platform-java/showcase/BUILD.bazel | ||
buildozer 'new_load @spring_cloud_generator//:java_gapic_spring.bzl java_gapic_spring_library' BUILD.bazel:__pkg__ | ||
modify_build_file "BUILD.bazel" | ||
|
||
# Invoke bazel target for generating showcase-spring-starter | ||
bazelisk build --tool_java_language_version=17 --tool_java_runtime_version=remotejdk_17 //showcase:showcase_java_gapic_spring | ||
|
||
# Post-process generated modules | ||
copy_and_unzip "../bazel-bin/showcase/showcase_java_gapic_spring-spring.srcjar" "showcase_java_gapic_spring-spring.srcjar" "${SPRING_GENERATOR_DIR}/showcase" ${SHOWCASE_STARTER_DIR} | ||
modify_starter_pom ${SHOWCASE_STARTER_DIR}/pom.xml "com.google.cloud" "gapic-showcase" $PROJECT_VERSION | ||
unzip "${output_srcjar_zip_name}" | ||
copy_and_unzip "${output_folder}/temp-codegen-spring.srcjar" "temp-codegen-spring.srcjar" "${SPRING_GENERATOR_DIR}/showcase" ${showcase_starter_dir} | ||
modify_starter_pom "${showcase_starter_dir}/pom.xml" "com.google.cloud" "gapic-showcase" "${project_version}" | ||
|
||
popd #output_folder | ||
|
||
# Additional pom.xml modifications for showcase starter | ||
# Add explicit gapic-showcase version | ||
sed -i'' '/^ *<artifactId>gapic-showcase<\/artifactId>*/a \ \ \ \ \ \ <version>'"$GAPIC_SHOWCASE_CLIENT_VERSION"'</version>' ${SHOWCASE_STARTER_DIR}/pom.xml | ||
sed -i'' '/^ *<artifactId>gapic-showcase<\/artifactId>*/a \ \ \ \ \ \ <version>'"${gapic_showcase_client_version}"'</version>' "${showcase_starter_dir}/pom.xml" | ||
# Update relative path to parent pom (different repo structure from starters) | ||
RELATIVE_PATH="\ \ \ \ <relativePath>..\/..\/..\/spring-cloud-gcp-starters\/pom.xml<\/relativePath>" | ||
sed -i'' 's/^ *<relativePath>.*/'"$RELATIVE_PATH"'/g' ${SHOWCASE_STARTER_DIR}/pom.xml | ||
relative_path="\ \ \ \ <relativePath>..\/..\/..\/spring-cloud-gcp-starters\/pom.xml<\/relativePath>" | ||
sed -i'' 's/^ *<relativePath>.*/'"${relative_path}"'/g' ${showcase_starter_dir}/pom.xml | ||
|
||
# Run google-java-format on generated code | ||
run_formatter ${SHOWCASE_STARTER_DIR} | ||
run_formatter "${showcase_starter_dir}" | ||
|
||
# Remove downloaded repos | ||
rm -rf ${SPRING_GENERATOR_DIR}/sdk-platform-java | ||
popd #showcase | ||
popd #sdk-platform-java | ||
rm -rdf ${SPRING_GENERATOR_DIR}/sdk-platform-java | ||
rm -rdf gapic-showcase | ||
popd #spring_root_dir | ||
} | ||
|
||
if [[ UPDATE -ne 0 ]]; then | ||
if [[ "${update}" == "true" ]]; then | ||
echo "Running script to perform showcase-spring-starter update" | ||
generate_showcase_spring_starter ${SHOWCASE_STARTER_OLD_DIR} | ||
generate_showcase_spring_starter ${showcase_starter_old_dir} | ||
else | ||
echo "Running script to perform showcase-spring-starter verification" | ||
generate_showcase_spring_starter ${SHOWCASE_STARTER_NEW_DIR} | ||
verify ${SHOWCASE_STARTER_OLD_DIR} ${SHOWCASE_STARTER_NEW_DIR} | ||
generate_showcase_spring_starter ${showcase_starter_new_dir} | ||
verify ${showcase_starter_old_dir} ${showcase_starter_new_dir} | ||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in order to run the spring generator jar using dependencies such as protobuf classes. This was something bazel took care about with the previous setup.