From badca9377145b0dc4f3fabb300f3b61f238b8b39 Mon Sep 17 00:00:00 2001 From: Diego Marquez Date: Tue, 10 Sep 2024 14:10:44 -0400 Subject: [PATCH] chore: make the showcase scripts to automatically prepare the generator jar (#3171) The recent changes in the hermetic library generation workflow make it necessary for the environment to have a well-known folder where the generator jar is assumed to be located. This PR sets up the generator jar in such location when running showcase golden tests or using the `-Pupdate` profile. More details in the [development guide](https://togithub.com/googleapis/sdk-platform-java/blob/main/library_generation/DEVELOPMENT.md#the-hermetic-builds-well-known-folder) --- .github/workflows/ci.yaml | 11 -------- showcase/README.md | 5 ++++ showcase/scripts/generate_showcase.sh | 38 ++++++++++++++++++++++++--- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5dcedf37df..6e3a6b85d5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -232,17 +232,6 @@ jobs: - name: Showcase golden tests working-directory: showcase run: | - # The golden test directly calls - # library_generation/generate_library.sh, which expects the jar to be - # located in its well-known location. More info in - # library_generation/DEVELOPMENT.md - # Here we prepare the jar in such location - generator_version=$(grep "gapic-generator-java:" "../versions.txt" \ - | cut -d: -f3) # the 3rd field is the snapshot version - mkdir -p "${HOME}/.library_generation" - cp \ - "${HOME}/.m2/repository/com/google/api/gapic-generator-java/${generator_version}/gapic-generator-java-${generator_version}.jar" \ - "${HOME}/.library_generation/gapic-generator-java.jar" mvn test \ -P enable-golden-tests \ --batch-mode \ diff --git a/showcase/README.md b/showcase/README.md index 4bd35c4252..536568e76b 100644 --- a/showcase/README.md +++ b/showcase/README.md @@ -77,6 +77,11 @@ Note: ## Update the Golden Showcase Files Open a new terminal window in the root project directory. +Note that the underlying scripts will modify your `$HOME` folder by creating a +`.library_generation` folder. +This is the well-known location of the artifacts the generation scripts use. +For more details see the +[development guide](https://github.com/googleapis/sdk-platform-java/blob/main/library_generation/DEVELOPMENT.md#the-hermetic-builds-well-known-folder) ```shell # In repository's root directory diff --git a/showcase/scripts/generate_showcase.sh b/showcase/scripts/generate_showcase.sh index f5558e7b04..c1089fd522 100755 --- a/showcase/scripts/generate_showcase.sh +++ b/showcase/scripts/generate_showcase.sh @@ -6,9 +6,9 @@ set -ex readonly SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) -lib_gen_scripts_dir="${SCRIPT_DIR}/../../library_generation/" -source "${lib_gen_scripts_dir}/test/test_utilities.sh" -source "${lib_gen_scripts_dir}/utils/utilities.sh" +readonly LIB_GEN_SCRIPTS_DIR="${SCRIPT_DIR}/../../library_generation/" +source "${LIB_GEN_SCRIPTS_DIR}/test/test_utilities.sh" +source "${LIB_GEN_SCRIPTS_DIR}/utils/utilities.sh" readonly perform_cleanup=$1 cd "${SCRIPT_DIR}" @@ -21,6 +21,14 @@ get_version_from_pom() { grep -e "<${key}>" "${target_pom}" | cut -d'>' -f2 | cut -d'<' -f1 } +# gets the latest version of the specified artifact from versions.txt +get_version_from_versions_txt() { + readonly VERSIONS_TXT_PATH="${SCRIPT_DIR}/../../versions.txt" + target_artifact="$1" + # prints the result to stdout + grep -e "${target_artifact}" "${VERSIONS_TXT_PATH}" | cut -d: -f3 +} + # clone gapic-showcase if [ ! -d schema ]; then if [ -d gapic-showcase ]; then @@ -47,6 +55,30 @@ if [ ! -d google ];then rm -rdf googleapis fi +# copy the generator into its well-known location. For more details, +# refer to library_generation/DEVELOPMENT.md +well_known_folder="${HOME}/.library_generation" +well_known_generator_jar_location="${well_known_folder}/gapic-generator-java.jar" +if [[ ! -d "${well_known_folder}" ]]; then + mkdir "${well_known_folder}" +fi +if [[ -f "${well_known_generator_jar_location}" ]]; then + echo "replacing well-known generator jar with the latest one" + rm "${well_known_generator_jar_location}" +fi +maven_repository="$(mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout)" +generator_version=$(get_version_from_versions_txt "gapic-generator-java") +source_jar_path="${maven_repository}/com/google/api/gapic-generator-java/${generator_version}/gapic-generator-java-${generator_version}.jar" + +if [[ ! -f "${source_jar_path}" ]]; then + echo "generator jar not found in its assumed location" + echo "in the local repository: ${source_jar_path}" + echo "(did you run mvn install in this repository's root?)" + exit 1 +fi +# transfer the snapshot jar into its well-known location +cp "${source_jar_path}" "${well_known_generator_jar_location}" + gapic_additional_protos="google/iam/v1/iam_policy.proto google/cloud/location/locations.proto" path_to_generator_parent_pom="${SCRIPT_DIR}/../../gapic-generator-java-pom-parent/pom.xml"