From 0b65f156c1e9fde402b21bd726c3584ec1d67aa0 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 2 Apr 2024 17:07:18 +0000 Subject: [PATCH 01/57] chore: bake synthtool into library_generation docker image --- library_generation/configuration/synthtool-committish | 1 + 1 file changed, 1 insertion(+) create mode 100644 library_generation/configuration/synthtool-committish diff --git a/library_generation/configuration/synthtool-committish b/library_generation/configuration/synthtool-committish new file mode 100644 index 0000000000..9a47302405 --- /dev/null +++ b/library_generation/configuration/synthtool-committish @@ -0,0 +1 @@ +6612ab8f3afcd5e292aecd647f0fa68812c9f5b5 From a6bb064e5b8b43491ef68b3f1e3d09f3d56845cf Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 2 Apr 2024 18:31:13 +0000 Subject: [PATCH 02/57] remove synthtool usage --- library_generation/README.md | 2 -- .../generate_composed_library.py | 1 - library_generation/model/generation_config.py | 3 -- library_generation/postprocess_library.sh | 31 +++---------------- .../google-cloud-java/generation_config.yaml | 3 +- .../java-bigtable/generation_config.yaml | 1 - .../config_without_temp_excludes.yaml | 1 - .../test-config/generation_config.yaml | 1 - .../test/utilities_unit_tests.py | 5 --- ...generation_config_comparator_unit_tests.py | 14 --------- 10 files changed, 6 insertions(+), 56 deletions(-) diff --git a/library_generation/README.md b/library_generation/README.md index 75fc32695d..c34514cb74 100644 --- a/library_generation/README.md +++ b/library_generation/README.md @@ -92,7 +92,6 @@ They are shared by library level parameters. | grpc_version | No | inferred from the generator if not specified | | googleapis-commitish | Yes | | | owlbot-cli-image | Yes | | -| synthtool-commitish | Yes | | | template_excludes | Yes | | ### Library level parameters @@ -142,7 +141,6 @@ gapic_generator_version: 2.34.0 protobuf_version: 25.2 googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026 owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 -synthtool_commitish: 6612ab8f3afcd5e292aecd647f0fa68812c9f5b5 destination_path: google-cloud-java template_excludes: - ".github/*" diff --git a/library_generation/generate_composed_library.py b/library_generation/generate_composed_library.py index 4caf0c45ff..005a6f11d2 100755 --- a/library_generation/generate_composed_library.py +++ b/library_generation/generate_composed_library.py @@ -110,7 +110,6 @@ def generate_composed_library( versions_file, owlbot_cli_source_folder, config.owlbot_cli_image, - config.synthtool_commitish, str(config.is_monorepo).lower(), config.path_to_yaml, ], diff --git a/library_generation/model/generation_config.py b/library_generation/model/generation_config.py index 22823b903d..989af140a7 100644 --- a/library_generation/model/generation_config.py +++ b/library_generation/model/generation_config.py @@ -30,7 +30,6 @@ def __init__( gapic_generator_version: str, googleapis_commitish: str, owlbot_cli_image: str, - synthtool_commitish: str, template_excludes: List[str], path_to_yaml: str, libraries: List[LibraryConfig], @@ -40,7 +39,6 @@ def __init__( self.gapic_generator_version = gapic_generator_version self.googleapis_commitish = googleapis_commitish self.owlbot_cli_image = owlbot_cli_image - self.synthtool_commitish = synthtool_commitish self.template_excludes = template_excludes self.path_to_yaml = path_to_yaml self.libraries = libraries @@ -106,7 +104,6 @@ def from_yaml(path_to_yaml: str) -> GenerationConfig: protobuf_version=__optional(config, "protobuf_version", None), googleapis_commitish=__required(config, "googleapis_commitish"), owlbot_cli_image=__required(config, "owlbot_cli_image"), - synthtool_commitish=__required(config, "synthtool_commitish"), template_excludes=__required(config, "template_excludes"), path_to_yaml=path_to_yaml, libraries=parsed_libraries, diff --git a/library_generation/postprocess_library.sh b/library_generation/postprocess_library.sh index c6a5b4020d..3b42617eb2 100755 --- a/library_generation/postprocess_library.sh +++ b/library_generation/postprocess_library.sh @@ -16,11 +16,9 @@ # 4 - owlbot_cli_source_folder: alternative folder with a structure exactly like # googleapis-gen. It will be used instead of preprocessed_sources_path if # 5 - owlbot_cli_image_sha: SHA of the image containing the OwlBot CLI -# 6 - synthtool_commitish: Commit SHA of the synthtool repo -# provided -# 7 - is_monorepo: whether this library is a monorepo, which implies slightly +# 6 - is_monorepo: whether this library is a monorepo, which implies slightly # different logic -# 8 - configuration_yaml_path: path to the configuration yaml containing library +# 7 - configuration_yaml_path: path to the configuration yaml containing library # generation information for this library set -exo pipefail scripts_root=$(dirname "$(readlink -f "$0")") @@ -30,13 +28,12 @@ preprocessed_sources_path=$2 versions_file=$3 owlbot_cli_source_folder=$4 owlbot_cli_image_sha=$5 -synthtool_commitish=$6 -is_monorepo=$7 -configuration_yaml_path=$8 +is_monorepo=$6 +configuration_yaml_path=$7 source "${scripts_root}"/utilities.sh -declare -a required_inputs=("postprocessing_target" "versions_file" "owlbot_cli_image_sha" "synthtool_commitish" "is_monorepo") +declare -a required_inputs=("postprocessing_target" "versions_file" "owlbot_cli_image_sha" "is_monorepo") for required_input in "${required_inputs[@]}"; do if [[ -z "${!required_input}" ]]; then echo "missing required ${required_input} argument, please specify one" @@ -129,24 +126,6 @@ if [[ "${is_monorepo}" == "true" ]]; then rm "${postprocessing_target}/.OwlBot.hermetic.yaml" fi -# we clone the synthtool library and manually build it -mkdir -p /tmp/synthtool -pushd /tmp/synthtool - -if [ ! -d "synthtool" ]; then - git clone https://github.com/googleapis/synthtool.git -fi -git config --global --add safe.directory /tmp/synthtool/synthtool -pushd "synthtool" - -git fetch --all -git reset --hard "${synthtool_commitish}" - -python3 -m pip install -e . -python3 -m pip install -r requirements.in -popd # synthtool -popd # temp dir - # run the postprocessor echo 'running owl-bot post-processor' pushd "${postprocessing_target}" diff --git a/library_generation/test/resources/integration/google-cloud-java/generation_config.yaml b/library_generation/test/resources/integration/google-cloud-java/generation_config.yaml index 839f80996e..1e3be07725 100644 --- a/library_generation/test/resources/integration/google-cloud-java/generation_config.yaml +++ b/library_generation/test/resources/integration/google-cloud-java/generation_config.yaml @@ -2,7 +2,6 @@ gapic_generator_version: 2.37.0 protobuf_version: 25.2 googleapis_commitish: 4ce0ff67a3d4509be641cbe47a35844ddc1268fc owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 -synthtool_commitish: 5e1fb2032fa44bc170677b38713023b4fec51a4e template_excludes: - ".github/*" - ".kokoro/*" @@ -55,4 +54,4 @@ libraries: api_description: Provides insights about your customers and their Assured Workloads based on your Sovereign Controls by Partners offering. GAPICs: - proto_path: google/cloud/cloudcontrolspartner/v1 - - proto_path: google/cloud/cloudcontrolspartner/v1beta \ No newline at end of file + - proto_path: google/cloud/cloudcontrolspartner/v1beta diff --git a/library_generation/test/resources/integration/java-bigtable/generation_config.yaml b/library_generation/test/resources/integration/java-bigtable/generation_config.yaml index 48afd9eef7..944ee954b7 100644 --- a/library_generation/test/resources/integration/java-bigtable/generation_config.yaml +++ b/library_generation/test/resources/integration/java-bigtable/generation_config.yaml @@ -2,7 +2,6 @@ gapic_generator_version: 2.37.0 protobuf_version: 25.2 googleapis_commitish: 9868a57470a969ffa1d21194a5c05d7a6e4e98cc owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 -synthtool_commitish: a6fb7d5f072b75698af1cbf06c5b001565753cfb template_excludes: - ".gitignore" - ".kokoro/presubmit/integration.cfg" diff --git a/library_generation/test/resources/test-config/config_without_temp_excludes.yaml b/library_generation/test/resources/test-config/config_without_temp_excludes.yaml index 9def2f3be6..8907f96bf7 100644 --- a/library_generation/test/resources/test-config/config_without_temp_excludes.yaml +++ b/library_generation/test/resources/test-config/config_without_temp_excludes.yaml @@ -1,7 +1,6 @@ gapic_generator_version: 2.34.0 googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026 owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 -synthtool_commitish: 6612ab8f3afcd5e292aecd647f0fa68812c9f5b5 libraries: - api_shortname: apigeeconnect name_pretty: Apigee Connect diff --git a/library_generation/test/resources/test-config/generation_config.yaml b/library_generation/test/resources/test-config/generation_config.yaml index d84ed3afd2..c2744c14b6 100644 --- a/library_generation/test/resources/test-config/generation_config.yaml +++ b/library_generation/test/resources/test-config/generation_config.yaml @@ -2,7 +2,6 @@ gapic_generator_version: 2.34.0 protobuf_version: 25.2 googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026 owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 -synthtool_commitish: 6612ab8f3afcd5e292aecd647f0fa68812c9f5b5 template_excludes: - ".github/*" - ".kokoro/*" diff --git a/library_generation/test/utilities_unit_tests.py b/library_generation/test/utilities_unit_tests.py index 3d114f977f..cfecf61911 100644 --- a/library_generation/test/utilities_unit_tests.py +++ b/library_generation/test/utilities_unit_tests.py @@ -146,7 +146,6 @@ def test_eprint_valid_input_succeeds(self): f"{test_config_dir}/config_without_googleapis.yaml", ), ("owlbot_cli_image", f"{test_config_dir}/config_without_owlbot.yaml"), - ("synthtool_commitish", f"{test_config_dir}/config_without_synthtool.yaml"), ( "template_excludes", f"{test_config_dir}/config_without_temp_excludes.yaml", @@ -172,9 +171,6 @@ def test_from_yaml_succeeds(self): "sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409", config.owlbot_cli_image, ) - self.assertEqual( - "6612ab8f3afcd5e292aecd647f0fa68812c9f5b5", config.synthtool_commitish - ) self.assertEqual( [ ".github/*", @@ -526,7 +522,6 @@ def __get_a_gen_config( gapic_generator_version="", googleapis_commitish="", owlbot_cli_image="", - synthtool_commitish="", template_excludes=[ ".github/*", ".kokoro/*", diff --git a/library_generation/test/utils/generation_config_comparator_unit_tests.py b/library_generation/test/utils/generation_config_comparator_unit_tests.py index c2c025c579..cd7d925310 100644 --- a/library_generation/test/utils/generation_config_comparator_unit_tests.py +++ b/library_generation/test/utils/generation_config_comparator_unit_tests.py @@ -40,7 +40,6 @@ def setUp(self) -> None: gapic_generator_version="", googleapis_commitish="", owlbot_cli_image="", - synthtool_commitish="", template_excludes=[], path_to_yaml="", grpc_version="", @@ -51,7 +50,6 @@ def setUp(self) -> None: gapic_generator_version="", googleapis_commitish="", owlbot_cli_image="", - synthtool_commitish="", template_excludes=[], path_to_yaml="", grpc_version="", @@ -103,18 +101,6 @@ def test_compare_config_owlbot_cli_update(self): self.assertEqual("owlbot_cli_image", config_change.changed_param) self.assertEqual("image_version_456", config_change.latest_value) - def test_compare_config_synthtool_update(self): - self.baseline_config.synthtool_commitish = "commit123" - self.latest_config.synthtool_commitish = "commit456" - result = compare_config( - baseline_config=self.baseline_config, - latest_config=self.latest_config, - ) - self.assertTrue(len(result[ChangeType.REPO_LEVEL_CHANGE]) == 1) - config_change = result[ChangeType.REPO_LEVEL_CHANGE][0] - self.assertEqual("synthtool_commitish", config_change.changed_param) - self.assertEqual("commit456", config_change.latest_value) - def test_compare_protobuf_update(self): self.baseline_config.protobuf_version = "3.25.2" self.latest_config.protobuf_version = "3.27.0" From d4f27e27fb57bfd26ca71f4245e416389aa24d5f Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 2 Apr 2024 18:18:05 +0000 Subject: [PATCH 03/57] do not use config file --- library_generation/configuration/synthtool-committish | 1 - 1 file changed, 1 deletion(-) delete mode 100644 library_generation/configuration/synthtool-committish diff --git a/library_generation/configuration/synthtool-committish b/library_generation/configuration/synthtool-committish deleted file mode 100644 index 9a47302405..0000000000 --- a/library_generation/configuration/synthtool-committish +++ /dev/null @@ -1 +0,0 @@ -6612ab8f3afcd5e292aecd647f0fa68812c9f5b5 From 19a0b0405a3c54a07fcf6b6deb1f58e7c8ce5ce3 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 2 Apr 2024 18:24:18 +0000 Subject: [PATCH 04/57] bake synthtool in dockerfile --- .../library_generation.Dockerfile | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index 4b3b1f4b1c..d26a7f360e 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -14,22 +14,35 @@ # build from the root of this repo: FROM gcr.io/cloud-devrel-public-resources/python +ARG SYNTHTOOL_COMMITTISH=6612ab8f3afcd5e292aecd647f0fa68812c9f5b5 -# install tools +# install OS tools RUN apt-get update && apt-get install -y \ unzip openjdk-17-jdk rsync maven jq \ && apt-get clean +# copy source code COPY library_generation /src +# install synthtool +WORKDIR /synthtool +RUN git clone https://github.com/googleapis/synthtool +WORKDIR /synthtool/synthtool +RUN git checkout "${SYNTHTOOL_COMMITTISH}" +RUN python3 -m pip install --no-deps -e . +RUN python3 -m pip install -r requirements.in + + +# use python 3.11 (the base image has several python versions; here we define the default one) RUN rm $(which python3) RUN ln -s $(which python3.11) /usr/local/bin/python RUN ln -s $(which python3.11) /usr/local/bin/python3 RUN python -m pip install --upgrade pip -RUN cd /src && python -m pip install -r requirements.in -RUN cd /src && python -m pip install . +WORKDIR /src +RUN python -m pip install -r requirements.in +RUN python -m pip install . -# set dummy git credentials for empty commit used in postprocessing +# set dummy git credentials for the empty commit used in postprocessing RUN git config --global user.email "cloud-java-bot@google.com" RUN git config --global user.name "Cloud Java Bot" @@ -37,4 +50,6 @@ WORKDIR /workspace RUN chmod 750 /workspace RUN chmod 750 /src/generate_repo.py +# define runtime env vars +ENV RUNNING_IN_DOCKER=true CMD [ "/src/generate_repo.py" ] From bc693b5090051c324a6b22c9379cd1c145bb07fc Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 2 Apr 2024 20:18:10 +0000 Subject: [PATCH 05/57] bake copy-code into the image --- .../library_generation.Dockerfile | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index d26a7f360e..554525ff05 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -14,7 +14,13 @@ # build from the root of this repo: FROM gcr.io/cloud-devrel-public-resources/python + ARG SYNTHTOOL_COMMITTISH=6612ab8f3afcd5e292aecd647f0fa68812c9f5b5 +ARG OWLBOT_CLI_COMMITTISH=ac84fa5c423a0069bbce3d2d869c9730c8fdf550 + +# build the image using bash +RUN echo ~ +SHELL ["/bin/bash", "--login", "-c"] # install OS tools RUN apt-get update && apt-get install -y \ @@ -25,13 +31,29 @@ RUN apt-get update && apt-get install -y \ COPY library_generation /src # install synthtool -WORKDIR /synthtool +WORKDIR /tools RUN git clone https://github.com/googleapis/synthtool -WORKDIR /synthtool/synthtool +WORKDIR /tools/synthtool RUN git checkout "${SYNTHTOOL_COMMITTISH}" RUN python3 -m pip install --no-deps -e . RUN python3 -m pip install -r requirements.in +# install node +ENV NODE_VERSION 20.12.0 +# Install nvm with node and npm +RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash +RUN ls /root/.nvm +ENV PATH=${PATH}:/root/.nvm/versions/node/v${NODE_VERSION}/bin +RUN node --version +RUN npm --version + +# install the owl-bot CLI +WORKDIR /tools +RUN git clone https://github.com/googleapis/repo-automation-bots +WORKDIR /tools/repo-automation-bots/packages/owl-bot +RUN npm i && npm run compile && npm link +RUN owl-bot copy-code --version + # use python 3.11 (the base image has several python versions; here we define the default one) RUN rm $(which python3) From f335cbbb5aae7df7a055967c90f3be7c5fe9a5fe Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 2 Apr 2024 20:23:06 +0000 Subject: [PATCH 06/57] remove unnecessary SHELL statement --- .cloudbuild/library_generation/library_generation.Dockerfile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index 554525ff05..73c3db850f 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -18,10 +18,6 @@ FROM gcr.io/cloud-devrel-public-resources/python ARG SYNTHTOOL_COMMITTISH=6612ab8f3afcd5e292aecd647f0fa68812c9f5b5 ARG OWLBOT_CLI_COMMITTISH=ac84fa5c423a0069bbce3d2d869c9730c8fdf550 -# build the image using bash -RUN echo ~ -SHELL ["/bin/bash", "--login", "-c"] - # install OS tools RUN apt-get update && apt-get install -y \ unzip openjdk-17-jdk rsync maven jq \ From aab50efab3a47487c5ac48ded29a24bc0525aa9c Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 2 Apr 2024 20:25:29 +0000 Subject: [PATCH 07/57] add info for installing synthtool --- library_generation/DEVELOPMENT.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 library_generation/DEVELOPMENT.md diff --git a/library_generation/DEVELOPMENT.md b/library_generation/DEVELOPMENT.md new file mode 100644 index 0000000000..ce04ff5d63 --- /dev/null +++ b/library_generation/DEVELOPMENT.md @@ -0,0 +1,17 @@ +# Local Development +## Installing prerequisites +### Install synthtool +```bash +git clone https://github.com/googleapis/synthtool +cd synthtool +python3 -m pip install --require-hashes -r requirements.txt +python3 -m pip install --no-deps -e . +python -m synthtool --version +``` +### Install the owl-bot CLI +```bash +git clone https://github.com/googleapis/repo-automation-bots +cd repo-automation-bots/packages/owl-bot +npm i && npm run compile && npm link +owl-bot copy-code --version +``` From f97cdca1f47c7ca0305483ef492eb9fa71ae2e5a Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 2 Apr 2024 20:36:31 +0000 Subject: [PATCH 08/57] modify owl-bot usage in postprocess_library --- library_generation/postprocess_library.sh | 39 +++-------------------- 1 file changed, 4 insertions(+), 35 deletions(-) diff --git a/library_generation/postprocess_library.sh b/library_generation/postprocess_library.sh index 3b42617eb2..6329910854 100755 --- a/library_generation/postprocess_library.sh +++ b/library_generation/postprocess_library.sh @@ -80,47 +80,17 @@ else fi # Default values for running copy-code directly from host -repo_bindings="-v ${postprocessing_target}:/workspace" repo_workspace="/workspace" preprocessed_libraries_binding="${owlbot_cli_source_folder}" -# When running docker inside docker, we run into the issue of volume bindings -# being mapped from the host machine to the child container (instead of the -# parent container to child container) because we bind the `docker.sock` socket -# to the parent container (i.e. docker calls use the host's filesystem context) -# see https://serverfault.com/a/819371 -# We solve this by referencing environment variables that will be -# set to produce the correct volume mapping. -# -# The workflow is: to check if we are in a docker container (via passed env var) -# and use managed volumes (docker volume create) instead of bindings -# (-v /path:/other-path). The volume names are also received as env vars. - -if [[ -n "${RUNNING_IN_DOCKER}" ]]; then - set -u # temporarily fail on unset variables - repo_bindings="${REPO_BINDING_VOLUMES}" - set +u - library_name=$(echo "${postprocessing_target}" | rev | cut -d'/' -f1 | rev) - repo_workspace="/workspace/" - if [[ "${is_monorepo}" == "true" ]]; then - monorepo_name=$(echo "${postprocessing_target}" | rev | cut -d'/' -f2 | rev) - repo_workspace+="${monorepo_name}/" - fi - repo_workspace+="${library_name}" -fi +pushd "${postprocessing_target}" -docker run --rm \ - --user "$(id -u)":"$(id -g)" \ - ${repo_bindings} \ - -v "/tmp:/tmp" \ - -w "${repo_workspace}" \ - --env HOME=/tmp \ - gcr.io/cloud-devrel-public-resources/owlbot-cli@"${owlbot_cli_image_sha}" \ - copy-code \ +owl-bot copy-code \ --source-repo-commit-hash=none \ - --source-repo="${preprocessed_libraries_binding}" \ + --source-repo="${owlbot_cli_source_folder}" \ --config-file="${owlbot_yaml_relative_path}" + # clean the custom owlbot yaml if [[ "${is_monorepo}" == "true" ]]; then rm "${postprocessing_target}/.OwlBot.hermetic.yaml" @@ -128,6 +98,5 @@ fi # run the postprocessor echo 'running owl-bot post-processor' -pushd "${postprocessing_target}" bash "${scripts_root}/owlbot/bin/entrypoint.sh" "${scripts_root}" "${versions_file}" "${configuration_yaml_path}" popd # postprocessing_target From eca0d9208497fb832bffc9b603fef41a3cf8ea3e Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 10 Apr 2024 15:39:23 +0000 Subject: [PATCH 09/57] fix synthtool installation --- .../library_generation.Dockerfile | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index 84aa8fee33..5f705c9c05 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -23,9 +23,20 @@ RUN apt-get update && apt-get install -y \ unzip openjdk-17-jdk rsync maven jq \ && apt-get clean +# use python 3.11 (the base image has several python versions; here we define the default one) +RUN rm $(which python3) +RUN ln -s $(which python3.11) /usr/local/bin/python +RUN ln -s $(which python3.11) /usr/local/bin/python3 +RUN python -m pip install --upgrade pip + # copy source code COPY library_generation /src +# install scripts as a python package +WORKDIR /src +RUN python -m pip install -r requirements.txt +RUN python -m pip install . + # install synthtool WORKDIR /tools RUN git clone https://github.com/googleapis/synthtool @@ -51,14 +62,6 @@ RUN npm i && npm run compile && npm link RUN owl-bot copy-code --version -# use python 3.11 (the base image has several python versions; here we define the default one) -RUN rm $(which python3) -RUN ln -s $(which python3.11) /usr/local/bin/python -RUN ln -s $(which python3.11) /usr/local/bin/python3 -RUN python -m pip install --upgrade pip -WORKDIR /src -RUN python -m pip install -r requirements.txt -RUN python -m pip install . # set dummy git credentials for the empty commit used in postprocessing RUN git config --global user.email "cloud-java-bot@google.com" From 6aa85331aa56256fcea5b36b753288af94fed64b Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 10 Apr 2024 15:55:47 +0000 Subject: [PATCH 10/57] change permissions to script folder --- .../library_generation/library_generation.Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index 5f705c9c05..3ca29b45e8 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -61,15 +61,15 @@ WORKDIR /tools/repo-automation-bots/packages/owl-bot RUN npm i && npm run compile && npm link RUN owl-bot copy-code --version - +# allow users to access the script folders +RUN chmod -R 755 /src # set dummy git credentials for the empty commit used in postprocessing RUN git config --global user.email "cloud-java-bot@google.com" RUN git config --global user.name "Cloud Java Bot" WORKDIR /workspace -RUN chmod 750 /workspace -RUN chmod 750 /src/generate_repo.py +RUN chmod 755 /workspace # define runtime env vars ENV RUNNING_IN_DOCKER=true From 53c5deaa9485ad342d3eee9184b5fbba327b7e75 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 10 Apr 2024 17:41:46 +0000 Subject: [PATCH 11/57] assume location of generation_config.yaml --- library_generation/generate_repo.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/library_generation/generate_repo.py b/library_generation/generate_repo.py index a15cfb5f2a..2c78bc31b2 100755 --- a/library_generation/generate_repo.py +++ b/library_generation/generate_repo.py @@ -12,6 +12,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import os import click as click import library_generation.utils.utilities as util from library_generation.generate_composed_library import generate_composed_library @@ -30,11 +31,12 @@ def main(ctx): @main.command() @click.option( "--generation-config-yaml", - required=True, + required=False, type=str, help=""" Path to generation_config.yaml that contains the metadata about - library generation + library generation. If not specified, it will be assumed to be found + at the root of --repository-path """, ) @click.option( @@ -72,6 +74,8 @@ def generate( target_library_names: str, repository_path: str, ): + if generation_config_yaml is None: + generation_config_yaml = os.path.join(repository_path, 'generation_config.yaml') config = from_yaml(generation_config_yaml) generate_from_yaml( config=config, From cc4309ba58e00b7c98554a1d4e9b39d66d2c2e6f Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 10 Apr 2024 21:05:50 +0000 Subject: [PATCH 12/57] fix permissions --- .../library_generation.Dockerfile | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index 3ca29b45e8..bb305e7786 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -17,10 +17,11 @@ FROM gcr.io/cloud-devrel-public-resources/python ARG SYNTHTOOL_COMMITTISH=6612ab8f3afcd5e292aecd647f0fa68812c9f5b5 ARG OWLBOT_CLI_COMMITTISH=ac84fa5c423a0069bbce3d2d869c9730c8fdf550 +ENV HOME=/home # install OS tools RUN apt-get update && apt-get install -y \ - unzip openjdk-17-jdk rsync maven jq \ + unzip openjdk-17-jdk rsync maven jq less vim \ && apt-get clean # use python 3.11 (the base image has several python versions; here we define the default one) @@ -45,12 +46,13 @@ RUN git checkout "${SYNTHTOOL_COMMITTISH}" RUN python3 -m pip install --no-deps -e . RUN python3 -m pip install -r requirements.in -# install node -ENV NODE_VERSION 20.12.0 # Install nvm with node and npm +ENV NODE_VERSION 20.12.0 +WORKDIR /home RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash -RUN ls /root/.nvm -ENV PATH=${PATH}:/root/.nvm/versions/node/v${NODE_VERSION}/bin +RUN chmod 755 /home/.nvm +ENV NODE_PATH=/home/.nvm/versions/node/v${NODE_VERSION}/bin +ENV PATH=${PATH}:${NODE_PATH} RUN node --version RUN npm --version @@ -60,17 +62,23 @@ RUN git clone https://github.com/googleapis/repo-automation-bots WORKDIR /tools/repo-automation-bots/packages/owl-bot RUN npm i && npm run compile && npm link RUN owl-bot copy-code --version +RUN chmod -R 755 ${NODE_PATH} +RUN ln -sf ${NODE_PATH}/* /usr/local/bin # allow users to access the script folders RUN chmod -R 755 /src # set dummy git credentials for the empty commit used in postprocessing -RUN git config --global user.email "cloud-java-bot@google.com" -RUN git config --global user.name "Cloud Java Bot" +# we use system so all users using the container will use this configuration +RUN git config --system user.email "cloud-java-bot@google.com" +RUN git config --system user.name "Cloud Java Bot" +RUN touch /home/.gitconfig -WORKDIR /workspace -RUN chmod 755 /workspace +# allow read-write for /home/.gitconfig and execution for binaries in /home/.nvm +RUN chmod -R 757 /home # define runtime env vars ENV RUNNING_IN_DOCKER=true -CMD [ "/src/generate_repo.py" ] + +WORKDIR /workspace +ENTRYPOINT [ "python", "/src/generate_repo.py", "generate" ] From 7a4b6b82038c5f9a11702f5ef91f4da1126456c5 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 10 Apr 2024 21:17:34 +0000 Subject: [PATCH 13/57] fix path to config yaml --- library_generation/generate_repo.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library_generation/generate_repo.py b/library_generation/generate_repo.py index 2c78bc31b2..cf1c19772b 100755 --- a/library_generation/generate_repo.py +++ b/library_generation/generate_repo.py @@ -19,6 +19,7 @@ from library_generation.model.generation_config import GenerationConfig, from_yaml from library_generation.model.library_config import LibraryConfig from library_generation.utils.monorepo_postprocessor import monorepo_postprocessing +from pathlib import Path @click.group(invoke_without_command=False) @@ -75,7 +76,7 @@ def generate( repository_path: str, ): if generation_config_yaml is None: - generation_config_yaml = os.path.join(repository_path, 'generation_config.yaml') + generation_config_yaml = str(Path(os.path.join(repository_path, 'generation_config.yaml')).resolve()) config = from_yaml(generation_config_yaml) generate_from_yaml( config=config, From 4838d5b3b09b04c40ed31e93172f86f4ff29cf50 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 11 Apr 2024 14:30:34 +0000 Subject: [PATCH 14/57] use entrypoint for docker image --- .../library_generation.Dockerfile | 2 +- library_generation/test/integration_tests.py | 46 ++++++------------- 2 files changed, 15 insertions(+), 33 deletions(-) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index bb305e7786..881cee4f0a 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -81,4 +81,4 @@ RUN chmod -R 757 /home ENV RUNNING_IN_DOCKER=true WORKDIR /workspace -ENTRYPOINT [ "python", "/src/generate_repo.py", "generate" ] +ENTRYPOINT [ "python", "/src/cli/entry_point.py", "generate" ] diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index 2c356d24a1..95c66ff84b 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -57,31 +57,25 @@ def test_entry_point_running_in_container(self): config_files = self.__get_config_files(config_dir) for repo, config_file in config_files: config = from_yaml(config_file) + repo_location=f"{output_dir}/{repo}" + config_location=f"{golden_dir}/../{repo}" # 1. pull repository repo_dest = self.__pull_repo_to( - Path(f"{output_dir}/{repo}"), repo, committish_map[repo] + Path(repo_location), repo, committish_map[repo] ) # 2. prepare golden files library_names = self.__get_library_names_from_config(config) self.__prepare_golden_files( config=config, library_names=library_names, repo_dest=repo_dest ) - # 3. bind repository and configuration to docker volumes - self.__bind_device_to_volumes( - volume_name=f"repo-{repo}", device_dir=f"{output_dir}/{repo}" - ) - self.__bind_device_to_volumes( - volume_name=f"config-{repo}", device_dir=f"{golden_dir}/../{repo}" - ) - repo_volumes = f"-v repo-{repo}:/workspace/{repo} -v config-{repo}:/workspace/config-{repo}" - # 4. run entry_point.py in docker container + # 3. run entry_point.py in docker container self.__run_entry_point_in_docker_container( - repo=repo, - repo_volumes=repo_volumes, + repo_location=repo_location, + config_location=config_location, baseline_config=baseline_config_name, current_config=current_config_name, ) - # 5. compare generation result with golden files + # 4. compare generation result with golden files print( "Generation finished successfully. " "Will now compare differences between generated and existing " @@ -241,8 +235,8 @@ def __bind_device_to_volumes(cls, volume_name: str, device_dir: str): @classmethod def __run_entry_point_in_docker_container( cls, - repo: str, - repo_volumes: str, + repo_location: str, + config_location: str, baseline_config: str, current_config: str, ): @@ -252,26 +246,14 @@ def __run_entry_point_in_docker_container( "run", "--rm", "-v", - f"repo-{repo}:/workspace/{repo}", - "-v", - f"config-{repo}:/workspace/config-{repo}", - "-v", - "/tmp:/tmp", + f"{repo_location}:/workspace/repo", "-v", - "/var/run/docker.sock:/var/run/docker.sock", - "-e", - "RUNNING_IN_DOCKER=true", - "-e", - f"REPO_BINDING_VOLUMES={repo_volumes}", + f"{config_location}:/workspace/config", "-w", - "/src", + "/workspace/repo", image_tag, - "python", - "/src/cli/entry_point.py", - "generate", - f"--baseline-generation-config=/workspace/config-{repo}/{baseline_config}", - f"--current-generation-config=/workspace/config-{repo}/{current_config}", - f"--repository-path=/workspace/{repo}", + f"--baseline-generation-config=/workspace/config/{baseline_config}", + f"--current-generation-config=/workspace/config/{current_config}", ] ) From 1b01713d3aea95d009366a8b0d518251496e1d06 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 11 Apr 2024 14:31:03 +0000 Subject: [PATCH 15/57] format --- library_generation/generate_repo.py | 4 +++- library_generation/test/integration_tests.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/library_generation/generate_repo.py b/library_generation/generate_repo.py index cf1c19772b..7a3689364f 100755 --- a/library_generation/generate_repo.py +++ b/library_generation/generate_repo.py @@ -76,7 +76,9 @@ def generate( repository_path: str, ): if generation_config_yaml is None: - generation_config_yaml = str(Path(os.path.join(repository_path, 'generation_config.yaml')).resolve()) + generation_config_yaml = str( + Path(os.path.join(repository_path, "generation_config.yaml")).resolve() + ) config = from_yaml(generation_config_yaml) generate_from_yaml( config=config, diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index 95c66ff84b..4c0a0d37cb 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -57,8 +57,8 @@ def test_entry_point_running_in_container(self): config_files = self.__get_config_files(config_dir) for repo, config_file in config_files: config = from_yaml(config_file) - repo_location=f"{output_dir}/{repo}" - config_location=f"{golden_dir}/../{repo}" + repo_location = f"{output_dir}/{repo}" + config_location = f"{golden_dir}/../{repo}" # 1. pull repository repo_dest = self.__pull_repo_to( Path(repo_location), repo, committish_map[repo] From c1494613531591acec2fbb7a8862f32967c0254b Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 11 Apr 2024 15:07:59 +0000 Subject: [PATCH 16/57] finish development guide --- library_generation/DEVELOPMENT.md | 90 +++++++++++++++++++++++++++++-- 1 file changed, 87 insertions(+), 3 deletions(-) diff --git a/library_generation/DEVELOPMENT.md b/library_generation/DEVELOPMENT.md index ce04ff5d63..4e161debc6 100644 --- a/library_generation/DEVELOPMENT.md +++ b/library_generation/DEVELOPMENT.md @@ -1,17 +1,101 @@ -# Local Development +# Linting + +When contributing, ensure your changes to python code have a valid +format. + +``` +python -m pip install black +black library_generation +``` + +# Running the integration tests + +The integration tests build the docker image declared in +`.cloudbuild/library_generation/library_generation.Dockerfile`, pull GAPIC +repositories, generate the libraries and compares the results with the source +code declared in a "golden branch" of the repo. + +It requires docker and python 3.x to be installed. + +``` +cd library_generation +python -m pip install . +python -m pip install -r requirements.txt +python -m unittest test/integration_tests.py +``` + +# Running the scripts in your local environment + +Although the scripts are designed to be run in a Docker container, you can also +run them directly. This section explains how to run the entrypoint script +(`library_generation/cli/entry_point.py`). + ## Installing prerequisites + +In order to run the generation scripts directly, there are a few tools we +need to install beforehand. + ### Install synthtool + +It requires python 3.x to be installed. +You will need to specify a committish of the synthtool repo in order to have +your generation results matching exactly what the docker image would produce. +You can achieve this by inspecting `SYNTHTOOL_COMMITISH` in +`.cloudbuild/library_generation/library_generation.Dockerfile`. + +```bash +# obtained from .cloudbuild/library_generation/library_generation.Dockerfile +export SYNTHTOOL_COMMITTISH=6612ab8f3afcd5e292aecd647f0fa68812c9f5b5 +``` + ```bash git clone https://github.com/googleapis/synthtool cd synthtool -python3 -m pip install --require-hashes -r requirements.txt -python3 -m pip install --no-deps -e . +git checkout "${SYNTHTOOL_COMMITTISH}" +python -m pip install --require-hashes -r requirements.txt +python -m pip install --no-deps -e . python -m synthtool --version ``` + ### Install the owl-bot CLI + +Requires node.js to be installed. +Check this [installation guide](https://github.com/nvm-sh/nvm?tab=readme-ov-file#install--update-script) +for NVM, Node.js's version manager. + +After you install it, you can install the owl-bot CLI with the following +commands: ```bash git clone https://github.com/googleapis/repo-automation-bots cd repo-automation-bots/packages/owl-bot npm i && npm run compile && npm link owl-bot copy-code --version ``` + +The key step is `npm link`, which will make the command available in you current +shell session. + +## Running the script +The entrypoint script (`library_generation/cli/entry_point.py`) allows you to +update the target repository with the latest changes starting from the +googleapis committish declared in `generation_config.yaml`. + +### Download the repo +For example, google-cloud-java +``` +git clone https://github.com/googleapis/google-cloud-java +export path_to_repo="$(pwd)/google-cloud-java" +``` + +### Install the scripts +``` +cd library_generation +python -m pip install . +``` + +### Run the script +``` +cd library_generation +python cli/entry_point.py --repository-path "${path_to_repo}" +``` + From 4ee16928b1290701a4b81b2f923ddb23842a1bfd Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 11 Apr 2024 15:29:34 +0000 Subject: [PATCH 17/57] remove olwbot_cli usage --- library_generation/README.md | 1 - library_generation/generate_composed_library.py | 1 - library_generation/model/generation_config.py | 3 --- library_generation/postprocess_library.sh | 10 ++++------ .../test/generate_repo_unit_tests.py | 2 -- .../test/model/config_change_unit_tests.py | 2 -- .../baseline_generation_config.yaml | 4 +--- .../current_generation_config.yaml | 1 - .../java-bigtable/generation_config.yaml | 1 - .../test-config/config_without_owlbot.yaml | 9 --------- .../test-config/config_without_synthtool.yaml | 10 ---------- .../config_without_temp_excludes.yaml | 1 - .../resources/test-config/generation_config.yaml | 1 - library_generation/test/utilities_unit_tests.py | 6 ------ .../generation_config_comparator_unit_tests.py | 16 ---------------- 15 files changed, 5 insertions(+), 63 deletions(-) delete mode 100644 library_generation/test/resources/test-config/config_without_owlbot.yaml delete mode 100644 library_generation/test/resources/test-config/config_without_synthtool.yaml diff --git a/library_generation/README.md b/library_generation/README.md index 02775a4dee..52ebefcdd4 100644 --- a/library_generation/README.md +++ b/library_generation/README.md @@ -146,7 +146,6 @@ The GAPIC level parameters define how to generate a GAPIC library. gapic_generator_version: 2.34.0 protobuf_version: 25.2 googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026 -owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 destination_path: google-cloud-java template_excludes: - ".github/*" diff --git a/library_generation/generate_composed_library.py b/library_generation/generate_composed_library.py index fdf708cd4b..757fa044e3 100755 --- a/library_generation/generate_composed_library.py +++ b/library_generation/generate_composed_library.py @@ -109,7 +109,6 @@ def generate_composed_library( "", versions_file, owlbot_cli_source_folder, - config.owlbot_cli_image, str(config.is_monorepo).lower(), config.path_to_yaml, ], diff --git a/library_generation/model/generation_config.py b/library_generation/model/generation_config.py index 03c2c2b7ec..d05925878d 100644 --- a/library_generation/model/generation_config.py +++ b/library_generation/model/generation_config.py @@ -29,7 +29,6 @@ def __init__( self, gapic_generator_version: str, googleapis_commitish: str, - owlbot_cli_image: str, template_excludes: List[str], path_to_yaml: str, libraries: List[LibraryConfig], @@ -38,7 +37,6 @@ def __init__( ): self.gapic_generator_version = gapic_generator_version self.googleapis_commitish = googleapis_commitish - self.owlbot_cli_image = owlbot_cli_image self.template_excludes = template_excludes self.path_to_yaml = path_to_yaml self.libraries = libraries @@ -115,7 +113,6 @@ def from_yaml(path_to_yaml: str) -> GenerationConfig: grpc_version=__optional(config, "grpc_version", None), protobuf_version=__optional(config, "protobuf_version", None), googleapis_commitish=__required(config, "googleapis_commitish"), - owlbot_cli_image=__required(config, "owlbot_cli_image"), template_excludes=__required(config, "template_excludes"), path_to_yaml=path_to_yaml, libraries=parsed_libraries, diff --git a/library_generation/postprocess_library.sh b/library_generation/postprocess_library.sh index 725afccd1e..f701c6ab4b 100755 --- a/library_generation/postprocess_library.sh +++ b/library_generation/postprocess_library.sh @@ -15,10 +15,9 @@ # 3 - versions_file: path to file containing versions to be applied to the poms # 4 - owlbot_cli_source_folder: alternative folder with a structure exactly like # googleapis-gen. It will be used instead of preprocessed_sources_path if -# 5 - owlbot_cli_image_sha: SHA of the image containing the OwlBot CLI -# 6 - is_monorepo: whether this library is a monorepo, which implies slightly +# 5 - is_monorepo: whether this library is a monorepo, which implies slightly # different logic -# 7 - configuration_yaml_path: path to the configuration yaml containing library +# 6 - configuration_yaml_path: path to the configuration yaml containing library # generation information for this library set -exo pipefail scripts_root=$(dirname "$(readlink -f "$0")") @@ -27,9 +26,8 @@ postprocessing_target=$1 preprocessed_sources_path=$2 versions_file=$3 owlbot_cli_source_folder=$4 -owlbot_cli_image_sha=$5 -is_monorepo=$6 -configuration_yaml_path=$7 +is_monorepo=$5 +configuration_yaml_path=$6 source "${scripts_root}"/utils/utilities.sh diff --git a/library_generation/test/generate_repo_unit_tests.py b/library_generation/test/generate_repo_unit_tests.py index db8cb4eb63..10deefa101 100644 --- a/library_generation/test/generate_repo_unit_tests.py +++ b/library_generation/test/generate_repo_unit_tests.py @@ -45,8 +45,6 @@ def __get_an_empty_generation_config() -> GenerationConfig: return GenerationConfig( gapic_generator_version="", googleapis_commitish="", - synthtool_commitish="", - owlbot_cli_image="", template_excludes=[], path_to_yaml="", libraries=[], diff --git a/library_generation/test/model/config_change_unit_tests.py b/library_generation/test/model/config_change_unit_tests.py index 5df6e8b021..6fe111db35 100644 --- a/library_generation/test/model/config_change_unit_tests.py +++ b/library_generation/test/model/config_change_unit_tests.py @@ -239,8 +239,6 @@ def __get_a_gen_config( return GenerationConfig( gapic_generator_version="", googleapis_commitish=googleapis_commitish, - owlbot_cli_image="", - synthtool_commitish="", template_excludes=[], path_to_yaml="", grpc_version="", diff --git a/library_generation/test/resources/integration/google-cloud-java/baseline_generation_config.yaml b/library_generation/test/resources/integration/google-cloud-java/baseline_generation_config.yaml index ad9eafb31e..ab2b9c3100 100644 --- a/library_generation/test/resources/integration/google-cloud-java/baseline_generation_config.yaml +++ b/library_generation/test/resources/integration/google-cloud-java/baseline_generation_config.yaml @@ -1,8 +1,6 @@ gapic_generator_version: 2.37.0 protobuf_version: 25.2 googleapis_commitish: a17d4caf184b050d50cacf2b0d579ce72c31ce74 -owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 -synthtool_commitish: 5e1fb2032fa44bc170677b38713023b4fec51a4e template_excludes: - ".github/*" - ".kokoro/*" @@ -55,4 +53,4 @@ libraries: api_description: Provides insights about your customers and their Assured Workloads based on your Sovereign Controls by Partners offering. GAPICs: - proto_path: google/cloud/cloudcontrolspartner/v1 - - proto_path: google/cloud/cloudcontrolspartner/v1beta \ No newline at end of file + - proto_path: google/cloud/cloudcontrolspartner/v1beta diff --git a/library_generation/test/resources/integration/google-cloud-java/current_generation_config.yaml b/library_generation/test/resources/integration/google-cloud-java/current_generation_config.yaml index 1e3be07725..d1d601b0a3 100644 --- a/library_generation/test/resources/integration/google-cloud-java/current_generation_config.yaml +++ b/library_generation/test/resources/integration/google-cloud-java/current_generation_config.yaml @@ -1,7 +1,6 @@ gapic_generator_version: 2.37.0 protobuf_version: 25.2 googleapis_commitish: 4ce0ff67a3d4509be641cbe47a35844ddc1268fc -owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 template_excludes: - ".github/*" - ".kokoro/*" diff --git a/library_generation/test/resources/integration/java-bigtable/generation_config.yaml b/library_generation/test/resources/integration/java-bigtable/generation_config.yaml index 944ee954b7..3d9545ad6a 100644 --- a/library_generation/test/resources/integration/java-bigtable/generation_config.yaml +++ b/library_generation/test/resources/integration/java-bigtable/generation_config.yaml @@ -1,7 +1,6 @@ gapic_generator_version: 2.37.0 protobuf_version: 25.2 googleapis_commitish: 9868a57470a969ffa1d21194a5c05d7a6e4e98cc -owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 template_excludes: - ".gitignore" - ".kokoro/presubmit/integration.cfg" diff --git a/library_generation/test/resources/test-config/config_without_owlbot.yaml b/library_generation/test/resources/test-config/config_without_owlbot.yaml deleted file mode 100644 index 7921f68bd2..0000000000 --- a/library_generation/test/resources/test-config/config_without_owlbot.yaml +++ /dev/null @@ -1,9 +0,0 @@ -gapic_generator_version: 2.34.0 -googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026 -libraries: - - api_shortname: apigeeconnect - name_pretty: Apigee Connect - api_description: "allows the Apigee hybrid management" - product_documentation: "https://cloud.google.com/apigee/docs/hybrid/v1.3/apigee-connect/" - GAPICs: - - proto_path: google/cloud/apigeeconnect/v1 diff --git a/library_generation/test/resources/test-config/config_without_synthtool.yaml b/library_generation/test/resources/test-config/config_without_synthtool.yaml deleted file mode 100644 index 8907f96bf7..0000000000 --- a/library_generation/test/resources/test-config/config_without_synthtool.yaml +++ /dev/null @@ -1,10 +0,0 @@ -gapic_generator_version: 2.34.0 -googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026 -owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 -libraries: - - api_shortname: apigeeconnect - name_pretty: Apigee Connect - api_description: "allows the Apigee hybrid management" - product_documentation: "https://cloud.google.com/apigee/docs/hybrid/v1.3/apigee-connect/" - GAPICs: - - proto_path: google/cloud/apigeeconnect/v1 diff --git a/library_generation/test/resources/test-config/config_without_temp_excludes.yaml b/library_generation/test/resources/test-config/config_without_temp_excludes.yaml index 8907f96bf7..7921f68bd2 100644 --- a/library_generation/test/resources/test-config/config_without_temp_excludes.yaml +++ b/library_generation/test/resources/test-config/config_without_temp_excludes.yaml @@ -1,6 +1,5 @@ gapic_generator_version: 2.34.0 googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026 -owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 libraries: - api_shortname: apigeeconnect name_pretty: Apigee Connect diff --git a/library_generation/test/resources/test-config/generation_config.yaml b/library_generation/test/resources/test-config/generation_config.yaml index c2744c14b6..22dad91ca3 100644 --- a/library_generation/test/resources/test-config/generation_config.yaml +++ b/library_generation/test/resources/test-config/generation_config.yaml @@ -1,7 +1,6 @@ gapic_generator_version: 2.34.0 protobuf_version: 25.2 googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026 -owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409 template_excludes: - ".github/*" - ".kokoro/*" diff --git a/library_generation/test/utilities_unit_tests.py b/library_generation/test/utilities_unit_tests.py index 4076137265..487dec8b87 100644 --- a/library_generation/test/utilities_unit_tests.py +++ b/library_generation/test/utilities_unit_tests.py @@ -143,7 +143,6 @@ def test_eprint_valid_input_succeeds(self): "googleapis_commitish", f"{test_config_dir}/config_without_googleapis.yaml", ), - ("owlbot_cli_image", f"{test_config_dir}/config_without_owlbot.yaml"), ( "template_excludes", f"{test_config_dir}/config_without_temp_excludes.yaml", @@ -165,10 +164,6 @@ def test_from_yaml_succeeds(self): self.assertEqual( "1a45bf7393b52407188c82e63101db7dc9c72026", config.googleapis_commitish ) - self.assertEqual( - "sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409", - config.owlbot_cli_image, - ) self.assertEqual( [ ".github/*", @@ -477,7 +472,6 @@ def __get_a_gen_config( return GenerationConfig( gapic_generator_version="", googleapis_commitish="", - owlbot_cli_image="", template_excludes=[ ".github/*", ".kokoro/*", diff --git a/library_generation/test/utils/generation_config_comparator_unit_tests.py b/library_generation/test/utils/generation_config_comparator_unit_tests.py index 1c25854c1f..53d4092e60 100644 --- a/library_generation/test/utils/generation_config_comparator_unit_tests.py +++ b/library_generation/test/utils/generation_config_comparator_unit_tests.py @@ -39,7 +39,6 @@ def setUp(self) -> None: self.baseline_config = GenerationConfig( gapic_generator_version="", googleapis_commitish="", - owlbot_cli_image="", template_excludes=[], path_to_yaml="", grpc_version="", @@ -49,7 +48,6 @@ def setUp(self) -> None: self.latest_config = GenerationConfig( gapic_generator_version="", googleapis_commitish="", - owlbot_cli_image="", template_excludes=[], path_to_yaml="", grpc_version="", @@ -91,20 +89,6 @@ def test_compare_config_generator_update(self): self.assertEqual("gapic_generator_version", config_change.changed_param) self.assertEqual("1.2.4", config_change.current_value) - def test_compare_config_owlbot_cli_update(self): - self.baseline_config.owlbot_cli_image = "image_version_123" - self.latest_config.owlbot_cli_image = "image_version_456" - result = compare_config( - baseline_config=self.baseline_config, - current_config=self.latest_config, - ) - self.assertTrue( - len(result.change_to_libraries[ChangeType.REPO_LEVEL_CHANGE]) == 1 - ) - config_change = result.change_to_libraries[ChangeType.REPO_LEVEL_CHANGE][0] - self.assertEqual("owlbot_cli_image", config_change.changed_param) - self.assertEqual("image_version_456", config_change.current_value) - def test_compare_protobuf_update(self): self.baseline_config.protobuf_version = "3.25.2" self.latest_config.protobuf_version = "3.27.0" From e77bacc667a47e837c8847deee8db97a643469aa Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 17 Apr 2024 15:22:44 +0000 Subject: [PATCH 18/57] add entrypoint for docker image --- .cloudbuild/library_generation/entrypoint.sh | 8 ++++++++ .../library_generation.Dockerfile | 18 +++++++++--------- library_generation/generate_library.sh | 2 +- library_generation/postprocess_library.sh | 2 +- library_generation/test/integration_tests.py | 8 +++++++- 5 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 .cloudbuild/library_generation/entrypoint.sh diff --git a/.cloudbuild/library_generation/entrypoint.sh b/.cloudbuild/library_generation/entrypoint.sh new file mode 100644 index 0000000000..5350becc24 --- /dev/null +++ b/.cloudbuild/library_generation/entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/bash +# wrapper script for the hermetic build cli entrypoint that sets environment +# variables that can be read by any user calling the container +set -ex +export HOME=/home +export MAVEN_HOME=/home/.m2 +python /src/cli/entry_point.py generate $@ + diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index 881cee4f0a..f26ee13133 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -50,7 +50,7 @@ RUN python3 -m pip install -r requirements.in ENV NODE_VERSION 20.12.0 WORKDIR /home RUN curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash -RUN chmod 755 /home/.nvm +RUN chmod o+rx /home/.nvm ENV NODE_PATH=/home/.nvm/versions/node/v${NODE_VERSION}/bin ENV PATH=${PATH}:${NODE_PATH} RUN node --version @@ -62,23 +62,23 @@ RUN git clone https://github.com/googleapis/repo-automation-bots WORKDIR /tools/repo-automation-bots/packages/owl-bot RUN npm i && npm run compile && npm link RUN owl-bot copy-code --version -RUN chmod -R 755 ${NODE_PATH} +RUN chmod -R o+rx ${NODE_PATH} RUN ln -sf ${NODE_PATH}/* /usr/local/bin # allow users to access the script folders -RUN chmod -R 755 /src +RUN chmod -R o+rx /src # set dummy git credentials for the empty commit used in postprocessing # we use system so all users using the container will use this configuration RUN git config --system user.email "cloud-java-bot@google.com" RUN git config --system user.name "Cloud Java Bot" -RUN touch /home/.gitconfig -# allow read-write for /home/.gitconfig and execution for binaries in /home/.nvm -RUN chmod -R 757 /home +# allow read-write for /home and execution for binaries in /home/.nvm +RUN chmod -R a+rw /home +RUN chmod -R a+rx /home/.nvm -# define runtime env vars -ENV RUNNING_IN_DOCKER=true +COPY .cloudbuild/library_generation/entrypoint.sh /entrypoint.sh +RUN chmod o+rx /entrypoint.sh WORKDIR /workspace -ENTRYPOINT [ "python", "/src/cli/entry_point.py", "generate" ] +ENTRYPOINT [ "bash", "/entrypoint.sh" ] diff --git a/library_generation/generate_library.sh b/library_generation/generate_library.sh index a5d73ebec4..a7131e33e5 100755 --- a/library_generation/generate_library.sh +++ b/library_generation/generate_library.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail +set -eox pipefail # parse input parameters while [[ $# -gt 0 ]]; do diff --git a/library_generation/postprocess_library.sh b/library_generation/postprocess_library.sh index f701c6ab4b..106be3dd88 100755 --- a/library_generation/postprocess_library.sh +++ b/library_generation/postprocess_library.sh @@ -31,7 +31,7 @@ configuration_yaml_path=$6 source "${scripts_root}"/utils/utilities.sh -declare -a required_inputs=("postprocessing_target" "versions_file" "owlbot_cli_image_sha" "is_monorepo") +declare -a required_inputs=("postprocessing_target" "versions_file" "is_monorepo") for required_input in "${required_inputs[@]}"; do if [[ -z "${!required_input}" ]]; then echo "missing required ${required_input} argument, please specify one" diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index 4c0a0d37cb..b6a036be2f 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -240,10 +240,16 @@ def __run_entry_point_in_docker_container( baseline_config: str, current_config: str, ): + # we use the calling user to prevent the mapped volumes from changing + # owners + user_id = shell_call("id -u") + group_id = shell_call("id -g") subprocess.check_call( [ "docker", "run", + "-u", + f'{user_id}:{group_id}', "--rm", "-v", f"{repo_location}:/workspace/repo", @@ -254,7 +260,7 @@ def __run_entry_point_in_docker_container( image_tag, f"--baseline-generation-config=/workspace/config/{baseline_config}", f"--current-generation-config=/workspace/config/{current_config}", - ] + ], ) @classmethod From 9120c94c17e44403397e4e915e776958cf5390c3 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 18 Apr 2024 04:15:47 +0000 Subject: [PATCH 19/57] manually set HOME var in owlbot --- library_generation/owlbot/bin/entrypoint.sh | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/library_generation/owlbot/bin/entrypoint.sh b/library_generation/owlbot/bin/entrypoint.sh index e7eb91c179..1ecd13e5d0 100755 --- a/library_generation/owlbot/bin/entrypoint.sh +++ b/library_generation/owlbot/bin/entrypoint.sh @@ -79,7 +79,12 @@ echo "Fixing missing license headers..." python3 "${scripts_root}/owlbot/src/fix-license-headers.py" echo "...done" -# ensure formatting on all .java files in the repository +# Ensure formatting on all .java files in the repository. +# Here we manually set the user.home system variable. Unfortunately, Maven +# infers user.home involves the /etc/passwd file (confirmed empirically), +# instead of the presumable $HOME env var, which may not work properly +# when `docker run`ning with the -u flag because we may incur in users +# not registered in the container's passwd file echo "Reformatting source..." -mvn fmt:format -V --batch-mode --no-transfer-progress +mvn fmt:format -Duser.home="${HOME}" -V --batch-mode --no-transfer-progress echo "...done" From 427c564984bcdb463a2d9569ec6a0b718360448a Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 18 Apr 2024 19:09:20 +0000 Subject: [PATCH 20/57] post-merge cleanup --- .../test/generate_pr_description_unit_tests.py | 2 -- .../test/model/generation_config_unit_test.py | 11 ----------- 2 files changed, 13 deletions(-) diff --git a/library_generation/test/generate_pr_description_unit_tests.py b/library_generation/test/generate_pr_description_unit_tests.py index c633268aa4..3e3508155c 100644 --- a/library_generation/test/generate_pr_description_unit_tests.py +++ b/library_generation/test/generate_pr_description_unit_tests.py @@ -61,8 +61,6 @@ def test_generate_pr_description_with_same_googleapis_commits(self): gapic_generator_version="", googleapis_commitish=commit_sha, libraries_bom_version="", - owlbot_cli_image="", - synthtool_commitish="", template_excludes=[], grpc_version="", protobuf_version="", diff --git a/library_generation/test/model/generation_config_unit_test.py b/library_generation/test/model/generation_config_unit_test.py index 08fea21523..40cd27f3f6 100644 --- a/library_generation/test/model/generation_config_unit_test.py +++ b/library_generation/test/model/generation_config_unit_test.py @@ -46,13 +46,6 @@ def test_from_yaml_succeeds(self): "1a45bf7393b52407188c82e63101db7dc9c72026", config.googleapis_commitish ) self.assertEqual("26.37.0", config.libraris_bom_version) - self.assertEqual( - "sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409", - config.owlbot_cli_image, - ) - self.assertEqual( - "6612ab8f3afcd5e292aecd647f0fa68812c9f5b5", config.synthtool_commitish - ) self.assertEqual( [ ".github/*", @@ -115,8 +108,6 @@ def test_is_monorepo_with_one_library_returns_false(self): gapic_generator_version="", googleapis_commitish="", libraries_bom_version="", - owlbot_cli_image="", - synthtool_commitish="", template_excludes=[], libraries=[library_1], ) @@ -127,8 +118,6 @@ def test_is_monorepo_with_two_libraries_returns_true(self): gapic_generator_version="", googleapis_commitish="", libraries_bom_version="", - owlbot_cli_image="", - synthtool_commitish="", template_excludes=[], libraries=[library_1, library_2], ) From 7b79763230404ca544fdff348290fedd8a03903b Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 18 Apr 2024 21:30:58 +0000 Subject: [PATCH 21/57] fix parameters --- library_generation/test/integration_tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index 1195a0a373..40883c5192 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -258,8 +258,8 @@ def __run_entry_point_in_docker_container( "-w", "/workspace/repo", image_tag, - f"--baseline-generation-config=/workspace/config/{baseline_config}", - f"--current-generation-config=/workspace/config/{current_config}", + f"--baseline-generation-config-path=/workspace/config/{baseline_config}", + f"--current-generation-config-path=/workspace/config/{current_config}", ], ) From 240742a42ec51fe8c3aefb6d373f84c67c5a443a Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 18 Apr 2024 21:31:36 +0000 Subject: [PATCH 22/57] fix synthtool sha --- .cloudbuild/library_generation/library_generation.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index f26ee13133..512ba59a5a 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -15,7 +15,7 @@ # build from the root of this repo: FROM gcr.io/cloud-devrel-public-resources/python -ARG SYNTHTOOL_COMMITTISH=6612ab8f3afcd5e292aecd647f0fa68812c9f5b5 +ARG SYNTHTOOL_COMMITTISH=63cc541da2c45fcfca2136c43e638da1fbae174d ARG OWLBOT_CLI_COMMITTISH=ac84fa5c423a0069bbce3d2d869c9730c8fdf550 ENV HOME=/home From 8498f2c27714c233dd4235bd5429e6814d7a930d Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Fri, 19 Apr 2024 15:54:32 +0000 Subject: [PATCH 23/57] fix entrypoint --- .cloudbuild/library_generation/library_generation.Dockerfile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index 512ba59a5a..73861c316f 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -77,8 +77,5 @@ RUN git config --system user.name "Cloud Java Bot" RUN chmod -R a+rw /home RUN chmod -R a+rx /home/.nvm -COPY .cloudbuild/library_generation/entrypoint.sh /entrypoint.sh -RUN chmod o+rx /entrypoint.sh - WORKDIR /workspace -ENTRYPOINT [ "bash", "/entrypoint.sh" ] +ENTRYPOINT [ "python", "/src/cli/entry_point.py", "generate" ] From 2faf45dc0e11bf877fcfffb72764a946e4e5ccd1 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Fri, 19 Apr 2024 17:35:36 +0000 Subject: [PATCH 24/57] lint --- library_generation/test/integration_tests.py | 2 +- .../test/resources/goldens/owlbot-golden.py | 29 ++++++++++--------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index b74d42b907..030a73571d 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -264,7 +264,7 @@ def __run_entry_point_in_docker_container( "docker", "run", "-u", - f'{user_id}:{group_id}', + f"{user_id}:{group_id}", "--rm", "-v", f"{repo_location}:/workspace/repo", diff --git a/library_generation/test/resources/goldens/owlbot-golden.py b/library_generation/test/resources/goldens/owlbot-golden.py index 2ba11e6bba..7559eaf034 100644 --- a/library_generation/test/resources/goldens/owlbot-golden.py +++ b/library_generation/test/resources/goldens/owlbot-golden.py @@ -21,16 +21,19 @@ s.move(library) s.remove_staging_dirs() -java.common_templates(monorepo=True, excludes=[ - ".github/*", - ".kokoro/*", - "samples/*", - "CODE_OF_CONDUCT.md", - "CONTRIBUTING.md", - "LICENSE", - "SECURITY.md", - "java.header", - "license-checks.xml", - "renovate.json", - ".gitignore" -]) \ No newline at end of file +java.common_templates( + monorepo=True, + excludes=[ + ".github/*", + ".kokoro/*", + "samples/*", + "CODE_OF_CONDUCT.md", + "CONTRIBUTING.md", + "LICENSE", + "SECURITY.md", + "java.header", + "license-checks.xml", + "renovate.json", + ".gitignore", + ], +) From 7ce954879d07faaab980591cc58cece009d8b993 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Fri, 19 Apr 2024 17:36:21 +0000 Subject: [PATCH 25/57] remove unused entrypoint file --- .cloudbuild/library_generation/entrypoint.sh | 8 -------- 1 file changed, 8 deletions(-) delete mode 100644 .cloudbuild/library_generation/entrypoint.sh diff --git a/.cloudbuild/library_generation/entrypoint.sh b/.cloudbuild/library_generation/entrypoint.sh deleted file mode 100644 index 5350becc24..0000000000 --- a/.cloudbuild/library_generation/entrypoint.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -# wrapper script for the hermetic build cli entrypoint that sets environment -# variables that can be read by any user calling the container -set -ex -export HOME=/home -export MAVEN_HOME=/home/.m2 -python /src/cli/entry_point.py generate $@ - From 8474452e4a66127faadf207a4db8be805e937646 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Fri, 19 Apr 2024 17:37:02 +0000 Subject: [PATCH 26/57] remove owlbot CLI from readmne --- library_generation/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/library_generation/README.md b/library_generation/README.md index b4978812f8..cded4bf54a 100644 --- a/library_generation/README.md +++ b/library_generation/README.md @@ -98,7 +98,6 @@ They are shared by library level parameters. | grpc_version | No | inferred from the generator if not specified | | googleapis-commitish | Yes | | | libraries_bom_version | Yes | | -| owlbot-cli-image | Yes | | | template_excludes | Yes | | ### Library level parameters From b58e990d9f570a2bd416965ae64d6e2c7a137ae7 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Fri, 19 Apr 2024 17:37:46 +0000 Subject: [PATCH 27/57] restore xtrace --- library_generation/generate_library.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library_generation/generate_library.sh b/library_generation/generate_library.sh index a7131e33e5..a5d73ebec4 100755 --- a/library_generation/generate_library.sh +++ b/library_generation/generate_library.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -eox pipefail +set -eo pipefail # parse input parameters while [[ $# -gt 0 ]]; do From 00cb2a7e6296f49ea2d7c45f1bf56279a71c54aa Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Fri, 19 Apr 2024 17:38:54 +0000 Subject: [PATCH 28/57] correct comment --- library_generation/owlbot/bin/entrypoint.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library_generation/owlbot/bin/entrypoint.sh b/library_generation/owlbot/bin/entrypoint.sh index 056a1d14ab..789737b2a5 100755 --- a/library_generation/owlbot/bin/entrypoint.sh +++ b/library_generation/owlbot/bin/entrypoint.sh @@ -72,10 +72,10 @@ echo "...done" # Ensure formatting on all .java files in the repository. # Here we manually set the user.home system variable. Unfortunately, Maven -# infers user.home involves the /etc/passwd file (confirmed empirically), +# user.home inference involves the /etc/passwd file (confirmed empirically), # instead of the presumable $HOME env var, which may not work properly # when `docker run`ning with the -u flag because we may incur in users -# not registered in the container's passwd file +# not registered in the container's /etc/passwd file echo "Reformatting source..." mvn fmt:format -Duser.home="${HOME}" -V --batch-mode --no-transfer-progress echo "...done" From b27a57ee036638037884bd124a1a20d33442a313 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Fri, 19 Apr 2024 17:41:19 +0000 Subject: [PATCH 29/57] remove test helper --- library_generation/test/integration_tests.py | 30 -------------------- 1 file changed, 30 deletions(-) diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index 030a73571d..6c4704905b 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -217,36 +217,6 @@ def __prepare_golden_files( else: copy_tree(f"{repo_dest}", f"{golden_dir}/{library_name}") - @classmethod - def __bind_device_to_volumes(cls, volume_name: str, device_dir: str): - # We use a volume to hold the repositories used in the integration - # tests. This is because the test container creates a child container - # using the host machine's docker socket, meaning that we can only - # reference volumes created from within the host machine (i.e. the - # machine running this script). - # - # To summarize, we create a special volume that can be referenced both - # in the main container and in any child containers created by this one. - - # use subprocess.run because we don't care about the return value (we - # want to remove the volume in any case). - subprocess.run(["docker", "volume", "rm", volume_name]) - subprocess.check_call( - [ - "docker", - "volume", - "create", - "--name", - volume_name, - "--opt", - "type=none", - "--opt", - f"device={device_dir}", - "--opt", - "o=bind", - ] - ) - @classmethod def __run_entry_point_in_docker_container( cls, From 6c6432a7b3eac9b3c22acc2e409e82b7add671e4 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Fri, 19 Apr 2024 17:42:55 +0000 Subject: [PATCH 30/57] checkout owlbot cli committish --- .cloudbuild/library_generation/library_generation.Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index 73861c316f..bfdfeba1d8 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -60,6 +60,7 @@ RUN npm --version WORKDIR /tools RUN git clone https://github.com/googleapis/repo-automation-bots WORKDIR /tools/repo-automation-bots/packages/owl-bot +RUN git checkout "${OWLBOT_CLI_COMMITTISH}" RUN npm i && npm run compile && npm link RUN owl-bot copy-code --version RUN chmod -R o+rx ${NODE_PATH} From eca8c62b1cc01d34932edaf8bd6190703bb99648 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Fri, 19 Apr 2024 17:46:11 +0000 Subject: [PATCH 31/57] remove owlbot config --- .../resources/test-config/config_without_owlbot.yaml | 10 ---------- 1 file changed, 10 deletions(-) delete mode 100644 library_generation/test/resources/test-config/config_without_owlbot.yaml diff --git a/library_generation/test/resources/test-config/config_without_owlbot.yaml b/library_generation/test/resources/test-config/config_without_owlbot.yaml deleted file mode 100644 index 0d1bb7deea..0000000000 --- a/library_generation/test/resources/test-config/config_without_owlbot.yaml +++ /dev/null @@ -1,10 +0,0 @@ -gapic_generator_version: 2.34.0 -googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026 -libraries_bom_version: 26.37.0 -libraries: - - api_shortname: apigeeconnect - name_pretty: Apigee Connect - api_description: "allows the Apigee hybrid management" - product_documentation: "https://cloud.google.com/apigee/docs/hybrid/v1.3/apigee-connect/" - GAPICs: - - proto_path: google/cloud/apigeeconnect/v1 From 0041c6b08a4e4a2fad75f010e52c92f0b8cb7778 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Fri, 19 Apr 2024 17:51:57 +0000 Subject: [PATCH 32/57] fix golden file --- .../test/resources/goldens/owlbot-golden.py | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/library_generation/test/resources/goldens/owlbot-golden.py b/library_generation/test/resources/goldens/owlbot-golden.py index 7559eaf034..2ba11e6bba 100644 --- a/library_generation/test/resources/goldens/owlbot-golden.py +++ b/library_generation/test/resources/goldens/owlbot-golden.py @@ -21,19 +21,16 @@ s.move(library) s.remove_staging_dirs() -java.common_templates( - monorepo=True, - excludes=[ - ".github/*", - ".kokoro/*", - "samples/*", - "CODE_OF_CONDUCT.md", - "CONTRIBUTING.md", - "LICENSE", - "SECURITY.md", - "java.header", - "license-checks.xml", - "renovate.json", - ".gitignore", - ], -) +java.common_templates(monorepo=True, excludes=[ + ".github/*", + ".kokoro/*", + "samples/*", + "CODE_OF_CONDUCT.md", + "CONTRIBUTING.md", + "LICENSE", + "SECURITY.md", + "java.header", + "license-checks.xml", + "renovate.json", + ".gitignore" +]) \ No newline at end of file From 7ec0f4cdb318278abe017bb416ad2abba6f868a8 Mon Sep 17 00:00:00 2001 From: Diego Marquez Date: Mon, 29 Apr 2024 18:16:08 -0400 Subject: [PATCH 33/57] Update library_generation/DEVELOPMENT.md Co-authored-by: Joe Wang <106995533+JoeWang1127@users.noreply.github.com> --- library_generation/DEVELOPMENT.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library_generation/DEVELOPMENT.md b/library_generation/DEVELOPMENT.md index 4e161debc6..25382ccad6 100644 --- a/library_generation/DEVELOPMENT.md +++ b/library_generation/DEVELOPMENT.md @@ -96,6 +96,6 @@ python -m pip install . ### Run the script ``` cd library_generation -python cli/entry_point.py --repository-path "${path_to_repo}" +python cli/entry_point.py generate --repository-path="${path_to_repo}" ``` From 4399bfe4661c6aec900fe484b07fb018c4b7b641 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Mon, 29 Apr 2024 23:28:54 +0000 Subject: [PATCH 34/57] docker instructions, pwd blurb, unit tests instructions --- library_generation/DEVELOPMENT.md | 57 ++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/library_generation/DEVELOPMENT.md b/library_generation/DEVELOPMENT.md index 4e161debc6..ee108cf330 100644 --- a/library_generation/DEVELOPMENT.md +++ b/library_generation/DEVELOPMENT.md @@ -1,3 +1,7 @@ +> [!IMPORTANT] +> All examples assume you are inside the `library_generation` folder + + # Linting When contributing, ensure your changes to python code have a valid @@ -5,7 +9,7 @@ format. ``` python -m pip install black -black library_generation +black . ``` # Running the integration tests @@ -18,12 +22,26 @@ code declared in a "golden branch" of the repo. It requires docker and python 3.x to be installed. ``` -cd library_generation python -m pip install . python -m pip install -r requirements.txt python -m unittest test/integration_tests.py ``` +# Running the unit tests + +The unit tests of the hermetic build scripts are contained in several scripts, +corresponding to a specific component. Every unit test script ends with +`unit_tests.py`. To avoid them specifying them +individually, we can use the following command: + +```bash +python -m unittest discover -s test/ -p "*unit_tests.py" +``` + +> [!NOTE] +> The output of this command may look erratic during the first 30 seconds. +> This is normal. After the tests are done, an "OK" message should be shown. + # Running the scripts in your local environment Although the scripts are designed to be run in a Docker container, you can also @@ -89,13 +107,44 @@ export path_to_repo="$(pwd)/google-cloud-java" ### Install the scripts ``` -cd library_generation python -m pip install . ``` ### Run the script ``` -cd library_generation python cli/entry_point.py --repository-path "${path_to_repo}" ``` + +# Running the scripts using the docker container image +This is convenient in order to avoid installing the dependencies manually. + +> [!IMPORTANT] +> From now, the examples assume you are in the root of your sdk-platform-java +> folder + +## Build the docker image +```bash +docker build --file .cloudbuild/library_generation/library_generation.Dockerfile --iidfile image-id . +``` + +This will create an `image-id` file at the root of the repo with the hash ID of +the image. + +## Run the docker image +The docker image will perform changes on its internal `/workspace` folder, to which you +need to map a folder on your host machine (i.e. map your downloaded repo to this +folder). + +To run the docker container on the google-cloud-java repo, you must run: +```bash +docker run -u "$(id -u)":"$(id -g)" -v/path/to/google-cloud-java:/workspace $(cat image-id) +``` + + * `-u "$(id -u)":"$(id -g)"` makes docker run the container impersonating + yourself. This avoids folder ownership changes since it runs as root by + default. + * `-v/path/to/google-cloud-java:/workspace` maps the host machine's + google-cloud-java folder to the /workspace folder. The image is configured to + perform changes in this directory + * `$(cat image-id)` obtains the image ID created in the build step From 1df1aa158ace81ab1b79ccfce28c622366c846e0 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 30 Apr 2024 15:19:17 +0000 Subject: [PATCH 35/57] restore generate repo --- library_generation/generate_repo.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/library_generation/generate_repo.py b/library_generation/generate_repo.py index 42a4e24bf7..9a97e3555b 100755 --- a/library_generation/generate_repo.py +++ b/library_generation/generate_repo.py @@ -12,14 +12,12 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import os import click as click import library_generation.utils.utilities as util from library_generation.generate_composed_library import generate_composed_library from library_generation.model.generation_config import GenerationConfig, from_yaml from library_generation.model.library_config import LibraryConfig from library_generation.utils.monorepo_postprocessor import monorepo_postprocessing -from pathlib import Path @click.group(invoke_without_command=False) @@ -32,12 +30,11 @@ def main(ctx): @main.command() @click.option( "--generation-config-yaml", - required=False, + required=True, type=str, help=""" Path to generation_config.yaml that contains the metadata about - library generation. If not specified, it will be assumed to be found - at the root of --repository-path + library generation """, ) @click.option( @@ -75,10 +72,6 @@ def generate( target_library_names: str, repository_path: str, ): - if generation_config_yaml is None: - generation_config_yaml = str( - Path(os.path.join(repository_path, "generation_config.yaml")).resolve() - ) config = from_yaml(generation_config_yaml) generate_from_yaml( config_path=generation_config_yaml, From 054458d345a535286d3700d3984a32f445d6bf8f Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 30 Apr 2024 18:46:19 +0000 Subject: [PATCH 36/57] chore: bake protoc into the library_generation docker image --- .../library_generation.Dockerfile | 18 +++++++++++++++--- library_generation/utils/utilities.sh | 16 ++++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index bfdfeba1d8..0e54b2cc47 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -15,8 +15,11 @@ # build from the root of this repo: FROM gcr.io/cloud-devrel-public-resources/python +SHELL [ "/bin/bash", "-c" ] + ARG SYNTHTOOL_COMMITTISH=63cc541da2c45fcfca2136c43e638da1fbae174d ARG OWLBOT_CLI_COMMITTISH=ac84fa5c423a0069bbce3d2d869c9730c8fdf550 +ARG PROTOC_VERSION=25.3 ENV HOME=/home # install OS tools @@ -24,15 +27,24 @@ RUN apt-get update && apt-get install -y \ unzip openjdk-17-jdk rsync maven jq less vim \ && apt-get clean +# copy source code +COPY library_generation /src + +# install protobuf +WORKDIR /protoc +RUN ls /src +RUN source /src/utils/utilities.sh \ + && download_protoc "${PROTOC_VERSION}" "linux-x86_64" +# we indicate protoc is available in the container via env vars +ENV DOCKER_PROTOC_LOCATION=/protoc +ENV DOCKER_PROTOC_VERSION="${PROTOC_VERSION}" + # use python 3.11 (the base image has several python versions; here we define the default one) RUN rm $(which python3) RUN ln -s $(which python3.11) /usr/local/bin/python RUN ln -s $(which python3.11) /usr/local/bin/python3 RUN python -m pip install --upgrade pip -# copy source code -COPY library_generation /src - # install scripts as a python package WORKDIR /src RUN python -m pip install -r requirements.txt diff --git a/library_generation/utils/utilities.sh b/library_generation/utils/utilities.sh index 16ad766ce5..83091d41b8 100755 --- a/library_generation/utils/utilities.sh +++ b/library_generation/utils/utilities.sh @@ -157,7 +157,20 @@ download_generator_artifact() { download_protoc() { local protoc_version=$1 local os_architecture=$2 - if [ ! -d "protoc-${protoc_version}" ]; then + + protoc_path="${output_folder}/protoc-${protoc_version}/bin" + if [[ -f "${protoc_path}/protoc" ]]; then + return + fi + + if [[ -n "${DOCKER_PROTOC_VERSION}" ]] \ + && [[ "${DOCKER_PROTOC_VERSION}" == "${protoc_version}" ]]; then + # if the specified protoc_version matches the one baked in the docker + # container, we just copy it into the output folder + cp -r "${DOCKER_PROTOC_LOCATION}" "${outut_folder}" + fi + + if [ ! -d "${protoc_path}" ]; then # pull proto files and protoc from protobuf repository as maven central # doesn't have proto files download_from \ @@ -169,7 +182,6 @@ download_protoc() { rm "protoc-${protoc_version}.zip" fi - protoc_path="${output_folder}/protoc-${protoc_version}/bin" } download_grpc_plugin() { From 00d9ecc63fc7727678c10ca9fc4c60a659143c20 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 30 Apr 2024 19:30:21 +0000 Subject: [PATCH 37/57] fix baked protoc transfer --- library_generation/utils/utilities.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library_generation/utils/utilities.sh b/library_generation/utils/utilities.sh index 83091d41b8..458279387a 100755 --- a/library_generation/utils/utilities.sh +++ b/library_generation/utils/utilities.sh @@ -167,7 +167,7 @@ download_protoc() { && [[ "${DOCKER_PROTOC_VERSION}" == "${protoc_version}" ]]; then # if the specified protoc_version matches the one baked in the docker # container, we just copy it into the output folder - cp -r "${DOCKER_PROTOC_LOCATION}" "${outut_folder}" + cp -r "${DOCKER_PROTOC_LOCATION}"/* "${output_folder}" fi if [ ! -d "${protoc_path}" ]; then From 1a5faec2af79a5527b2cd798935b28113fac8d5a Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 30 Apr 2024 19:41:48 +0000 Subject: [PATCH 38/57] add unit test for baked protoc --- .../test/generate_library_unit_tests.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/library_generation/test/generate_library_unit_tests.sh b/library_generation/test/generate_library_unit_tests.sh index 9b5f8bc456..60ae9e8bff 100755 --- a/library_generation/test/generate_library_unit_tests.sh +++ b/library_generation/test/generate_library_unit_tests.sh @@ -134,6 +134,18 @@ download_protoc_failed_with_invalid_arch_test() { assertEquals 1 $((res)) } +download_protoc_succeed_with_baked_protoc() { + # this mimics a docker container scenario. + # if the specified version matches the docker env var, then it will be just + # copied from the docker protoc location (also specified in an env var). + export DOCKER_PROTOC_LOCATION=$(mktmp -d) + mkdir "${DOCKER_PROTOC_LOCATION}/protoc-99.99" + export DOCKER_PROTOC_VERSION="99.99" + download_protoc "99.99" "linux-x86_64" + assertFileOrDirectoryExists "protoc-99.99" + rm -rf "protoc-99.99" +} + download_grpc_plugin_succeed_with_valid_version_linux_test() { download_grpc_plugin "1.55.1" "linux-x86_64" assertFileOrDirectoryExists "protoc-gen-grpc-java-1.55.1-linux-x86_64.exe" From 5a7d52554d77399d12f52b29631eab8b48b6d907 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 1 May 2024 18:26:23 +0000 Subject: [PATCH 39/57] restore change from main --- .cloudbuild/library_generation/library_generation.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index 0e54b2cc47..fe3a71fed5 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -24,7 +24,7 @@ ENV HOME=/home # install OS tools RUN apt-get update && apt-get install -y \ - unzip openjdk-17-jdk rsync maven jq less vim \ + unzip openjdk-17-jdk rsync maven jq \ && apt-get clean # copy source code From 3cde6f5770025264042a21125c5f81ac6329ee6e Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 1 May 2024 18:56:30 +0000 Subject: [PATCH 40/57] add renovate config for protoc version --- renovate.json | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/renovate.json b/renovate.json index a6303eaf38..b356cf06ca 100644 --- a/renovate.json +++ b/renovate.json @@ -28,6 +28,17 @@ "depNameTemplate": "com.google.protobuf:protobuf-java", "datasourceTemplate": "maven" }, + { + "customType": "regex", + "fileMatch": [ + "^\\.cloudbuild/library_generation/library_generation\\.Dockerfile$" + ], + "matchStrings": [ + "ARG PROTOC_VERSION==(?.+?)\\n" + ], + "depNameTemplate": "com.google.protobuf:protobuf-java", + "datasourceTemplate": "maven" + }, { "customType": "regex", "fileMatch": [ From acf26faa935cbc0d120a3c546b3e452515b25043 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 1 May 2024 22:19:14 +0000 Subject: [PATCH 41/57] add to unit tests list --- library_generation/test/generate_library_unit_tests.sh | 10 ++++++---- library_generation/utils/utilities.sh | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/library_generation/test/generate_library_unit_tests.sh b/library_generation/test/generate_library_unit_tests.sh index 60ae9e8bff..042cbc8db6 100755 --- a/library_generation/test/generate_library_unit_tests.sh +++ b/library_generation/test/generate_library_unit_tests.sh @@ -138,12 +138,13 @@ download_protoc_succeed_with_baked_protoc() { # this mimics a docker container scenario. # if the specified version matches the docker env var, then it will be just # copied from the docker protoc location (also specified in an env var). - export DOCKER_PROTOC_LOCATION=$(mktmp -d) - mkdir "${DOCKER_PROTOC_LOCATION}/protoc-99.99" + export DOCKER_PROTOC_LOCATION=$(mktemp -d) export DOCKER_PROTOC_VERSION="99.99" + export output_folder=$(get_output_folder) + mkdir -p "${DOCKER_PROTOC_LOCATION}/protoc-99.99/bin" download_protoc "99.99" "linux-x86_64" - assertFileOrDirectoryExists "protoc-99.99" - rm -rf "protoc-99.99" + assertFileOrDirectoryExists "${output_folder}/protoc-99.99" + rm -rf "${output_folder}/protoc-99.99" } download_grpc_plugin_succeed_with_valid_version_linux_test() { @@ -280,6 +281,7 @@ test_list=( download_protoc_succeed_with_valid_version_macos_test download_protoc_failed_with_invalid_version_linux_test download_protoc_failed_with_invalid_arch_test + download_protoc_succeed_with_baked_protoc download_grpc_plugin_succeed_with_valid_version_linux_test download_grpc_plugin_succeed_with_valid_version_macos_test download_grpc_plugin_failed_with_invalid_version_linux_test diff --git a/library_generation/utils/utilities.sh b/library_generation/utils/utilities.sh index 458279387a..b0edbeb25f 100755 --- a/library_generation/utils/utilities.sh +++ b/library_generation/utils/utilities.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -eo pipefail +set -exo pipefail utilities_script_dir=$(dirname "$(realpath "${BASH_SOURCE[0]}")") # Utility functions used in `generate_library.sh` and showcase generation. @@ -167,7 +167,7 @@ download_protoc() { && [[ "${DOCKER_PROTOC_VERSION}" == "${protoc_version}" ]]; then # if the specified protoc_version matches the one baked in the docker # container, we just copy it into the output folder - cp -r "${DOCKER_PROTOC_LOCATION}"/* "${output_folder}" + cp -r "${DOCKER_PROTOC_LOCATION}/protoc-${protoc_version}" "${output_folder}" fi if [ ! -d "${protoc_path}" ]; then From 1ef4006057b7848ee56423f31839281e7b911ad3 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 1 May 2024 22:28:24 +0000 Subject: [PATCH 42/57] expand explanation of the test --- .../test/generate_library_unit_tests.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/library_generation/test/generate_library_unit_tests.sh b/library_generation/test/generate_library_unit_tests.sh index 042cbc8db6..e3833c478e 100755 --- a/library_generation/test/generate_library_unit_tests.sh +++ b/library_generation/test/generate_library_unit_tests.sh @@ -135,9 +135,14 @@ download_protoc_failed_with_invalid_arch_test() { } download_protoc_succeed_with_baked_protoc() { - # this mimics a docker container scenario. - # if the specified version matches the docker env var, then it will be just - # copied from the docker protoc location (also specified in an env var). + # This mimics a docker container scenario. + # This test consists of creating an empty /tmp/.../protoc-99.99/bin folder and map + # it to the DOCKER_PROTOC_LOCATION env var (which is treated specially in the + # `download_protoc` function). If `DOCKER_PROTOC_VERSION` matches exactly as + # the version passed to `download_protoc`, then we will not download protoc + # but simply copy it from DOCKER_PROTOC_LOCATION into ${output_folder} (which + # we manually created in this test), so we should expect ${output_folder} to + # contain a folder called protoc-99.99. export DOCKER_PROTOC_LOCATION=$(mktemp -d) export DOCKER_PROTOC_VERSION="99.99" export output_folder=$(get_output_folder) From 358be3261328a85f8e5eb91efd49aae1e6bee6f5 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Sun, 12 May 2024 22:25:49 +0000 Subject: [PATCH 43/57] fix renovate config --- renovate.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/renovate.json b/renovate.json index b356cf06ca..92e644c1ed 100644 --- a/renovate.json +++ b/renovate.json @@ -34,10 +34,11 @@ "^\\.cloudbuild/library_generation/library_generation\\.Dockerfile$" ], "matchStrings": [ - "ARG PROTOC_VERSION==(?.+?)\\n" + "ARG PROTOC_VERSION=[\"']?(?.+?)[\"']?\\s+" ], - "depNameTemplate": "com.google.protobuf:protobuf-java", - "datasourceTemplate": "maven" + "datasourceTemplate": "github-releases", + "depNameTemplate": "protocolbuffers/protobuf", + "extractVersionTemplate": "^v(?.*)$" }, { "customType": "regex", From 17de6db2c1a76be6e18a8ab6b99fbfde39de7b80 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Sun, 12 May 2024 22:42:21 +0000 Subject: [PATCH 44/57] fix unit tests --- library_generation/test/generate_library_unit_tests.sh | 3 +++ library_generation/utils/utilities.sh | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/library_generation/test/generate_library_unit_tests.sh b/library_generation/test/generate_library_unit_tests.sh index e3833c478e..68d70b7d91 100755 --- a/library_generation/test/generate_library_unit_tests.sh +++ b/library_generation/test/generate_library_unit_tests.sh @@ -150,6 +150,9 @@ download_protoc_succeed_with_baked_protoc() { download_protoc "99.99" "linux-x86_64" assertFileOrDirectoryExists "${output_folder}/protoc-99.99" rm -rf "${output_folder}/protoc-99.99" + unset DOCKER_PROTOC_LOCATION + unset DOCKER_PROTOC_VERSION + rm -rdf $(get_output_folder) } download_grpc_plugin_succeed_with_valid_version_linux_test() { diff --git a/library_generation/utils/utilities.sh b/library_generation/utils/utilities.sh index b0edbeb25f..37e7ddc621 100755 --- a/library_generation/utils/utilities.sh +++ b/library_generation/utils/utilities.sh @@ -158,16 +158,18 @@ download_protoc() { local protoc_version=$1 local os_architecture=$2 - protoc_path="${output_folder}/protoc-${protoc_version}/bin" + protoc_dirname="protoc-${protoc_version}" + protoc_path="${output_folder}/${protoc_dirname}/bin" if [[ -f "${protoc_path}/protoc" ]]; then return fi - if [[ -n "${DOCKER_PROTOC_VERSION}" ]] \ - && [[ "${DOCKER_PROTOC_VERSION}" == "${protoc_version}" ]]; then + if [[ "${DOCKER_PROTOC_VERSION}" == "${protoc_version}" ]]; then # if the specified protoc_version matches the one baked in the docker # container, we just copy it into the output folder - cp -r "${DOCKER_PROTOC_LOCATION}/protoc-${protoc_version}" "${output_folder}" + mkdir -p "${output_folder}/${protoc_dirname}" + cp -r "${DOCKER_PROTOC_LOCATION}/${protoc_dirname}" \ + "${output_folder}" fi if [ ! -d "${protoc_path}" ]; then From e3d6e50b48480ec7fd9f513ff639d5fde77762e9 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Mon, 13 May 2024 15:28:19 +0000 Subject: [PATCH 45/57] remove debug tracing --- library_generation/utils/utilities.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library_generation/utils/utilities.sh b/library_generation/utils/utilities.sh index 37e7ddc621..79af9691a1 100755 --- a/library_generation/utils/utilities.sh +++ b/library_generation/utils/utilities.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -set -exo pipefail +set -eo pipefail utilities_script_dir=$(dirname "$(realpath "${BASH_SOURCE[0]}")") # Utility functions used in `generate_library.sh` and showcase generation. From 315feb9fef79d780643c273684c4e7e7d0e89b08 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Mon, 13 May 2024 15:50:57 +0000 Subject: [PATCH 46/57] disable PROTOC in renovate --- renovate.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/renovate.json b/renovate.json index 92e644c1ed..45c9e50f45 100644 --- a/renovate.json +++ b/renovate.json @@ -153,7 +153,8 @@ }, { "matchPackagePatterns": [ - "^com.google.protobuf" + "^com.google.protobuf", + "^protocolbuffers/protobuf" ], "groupName": "Protobuf dependencies", "enabled": false From 291f911ba3bd9fdc993e8aaaa798c7b07b6fa304 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 14 May 2024 19:47:48 +0000 Subject: [PATCH 47/57] default to protoc version in docker image if not found --- .../test/generate_library_unit_tests.sh | 13 ++ ...gapic-generator-java-pom-parent-2.24.0.pom | 197 ++++++++++++++++++ library_generation/utils/utilities.sh | 3 + 3 files changed, 213 insertions(+) create mode 100644 library_generation/test/resources/output/gapic-generator-java-pom-parent-2.24.0.pom diff --git a/library_generation/test/generate_library_unit_tests.sh b/library_generation/test/generate_library_unit_tests.sh index 68d70b7d91..b13c8e53bd 100755 --- a/library_generation/test/generate_library_unit_tests.sh +++ b/library_generation/test/generate_library_unit_tests.sh @@ -28,6 +28,18 @@ get_grpc_version_failed_with_invalid_generator_version_test() { assertEquals 1 $((res)) } +get_protoc_version_succeed_docker_env_var_test() { + local version_with_docker + local version_without_docker + export DOCKER_PROTOC_VERSION="9.9.9" + version_with_docker=$(get_protoc_version "2.24.0") + assertEquals "${DOCKER_PROTOC_VERSION}" "${version_with_docker}" + unset DOCKER_PROTOC_VERSION + version_without_docker=$(get_protoc_version "2.24.0") + assertEquals "23.2" "${version_without_docker}" + rm "gapic-generator-java-pom-parent-2.24.0.pom" +} + get_protoc_version_succeed_with_valid_generator_version_test() { local actual_version actual_version=$(get_protoc_version "2.24.0") @@ -277,6 +289,7 @@ test_list=( extract_folder_name_test get_grpc_version_succeed_with_valid_generator_version_test get_grpc_version_failed_with_invalid_generator_version_test + get_protoc_version_succeed_docker_env_var_test get_protoc_version_succeed_with_valid_generator_version_test get_protoc_version_failed_with_invalid_generator_version_test get_gapic_opts_with_rest_test diff --git a/library_generation/test/resources/output/gapic-generator-java-pom-parent-2.24.0.pom b/library_generation/test/resources/output/gapic-generator-java-pom-parent-2.24.0.pom new file mode 100644 index 0000000000..2a590d77f2 --- /dev/null +++ b/library_generation/test/resources/output/gapic-generator-java-pom-parent-2.24.0.pom @@ -0,0 +1,197 @@ + + + 4.0.0 + com.google.api + gapic-generator-java-pom-parent + 2.24.0 + pom + GAPIC Generator Java POM Parent + https://github.com/googleapis/sdk-platform-java + + The top-level parent for all modules in the repository. + + + com.google.cloud + google-cloud-shared-config + 1.5.7 + + + + + false + java.header + + + 1.3.2 + 1.10.2 + 1.56.1 + 1.19.0 + 1.43.3 + 2.10.1 + 32.1.2-jre + + 3.23.2 + 8 + + + + + suztomo + Tomo Suzuki + suztomo@google.com + Google + + Developer + + + + + Google LLC + + + scm:git:git@github.com:googleapis/sdk-platform-java.git + scm:git:git@github.com:googleapis/sdk-platform-java.git + https://github.com/googleapis/sdk-platform-java + HEAD + + + https://github.com/googleapis/sdk-platform-java/issues + GitHub Issues + + + + + Apache-2.0 + https://www.apache.org/licenses/LICENSE-2.0.txt + + + + + + + checkstyle-tests + + [11,) + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + + + checkstyle + validate + + check + + + ${checkstyle.header.file} + + + + + + + + + + test-coverage + + + enableShowcaseTestCoverage + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 3.0.0-M8 + + + + **/*SmokeTest.java + **/IT*.java + + sponge_log + ${surefire.jacoco.args} + ${skipUnitTests} + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 3.0.0 + + + + integration-test + verify + + + + + 3600 + sponge_log + + **/IT*.java + **/*SmokeTest.java + + ${failsafe.jacoco.args} + + + + + + + org.jacoco + jacoco-maven-plugin + 0.8.8 + + + unit-test-execution + + prepare-agent + + + surefire.jacoco.args + + + + integration-test-execution + pre-integration-test + + prepare-agent + + + failsafe.jacoco.args + + + + + + + + + + + google-maven-central-copy + Google Maven Central copy + https://maven-central.storage-download.googleapis.com/maven2 + + + maven-central + Maven Central + https://repo1.maven.org/maven2 + + + diff --git a/library_generation/utils/utilities.sh b/library_generation/utils/utilities.sh index 79af9691a1..93c9e3accb 100755 --- a/library_generation/utils/utilities.sh +++ b/library_generation/utils/utilities.sh @@ -111,6 +111,9 @@ get_grpc_version() { get_protoc_version() { local gapic_generator_version=$1 local protoc_version + if [[ -n "${DOCKER_PROTOC_VERSION}" ]]; then + echo "${DOCKER_PROTOC_VERSION}" + fi pushd "${output_folder}" > /dev/null # get protobuf version from gapic-generator-java-pom-parent/pom.xml download_gapic_generator_pom_parent "${gapic_generator_version}" From 5fe0a976d9ef1092374872db8eeb8c578b731c27 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 14 May 2024 19:51:19 +0000 Subject: [PATCH 48/57] add message when using baked protoc version --- library_generation/utils/utilities.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/library_generation/utils/utilities.sh b/library_generation/utils/utilities.sh index 93c9e3accb..2b8d1c8b88 100755 --- a/library_generation/utils/utilities.sh +++ b/library_generation/utils/utilities.sh @@ -112,6 +112,7 @@ get_protoc_version() { local gapic_generator_version=$1 local protoc_version if [[ -n "${DOCKER_PROTOC_VERSION}" ]]; then + >&2 echo "Using protoc version baked into the container: ${DOCKER_PROTOC_VERSION}" echo "${DOCKER_PROTOC_VERSION}" fi pushd "${output_folder}" > /dev/null From eb48f452c4c01e99d62aeeb99d51e19efbc55650 Mon Sep 17 00:00:00 2001 From: Diego Marquez Date: Thu, 16 May 2024 11:33:32 -0400 Subject: [PATCH 49/57] Update .cloudbuild/library_generation/library_generation.Dockerfile Co-authored-by: Joe Wang <106995533+JoeWang1127@users.noreply.github.com> --- .cloudbuild/library_generation/library_generation.Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index fe3a71fed5..88167e0eb7 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -30,7 +30,7 @@ RUN apt-get update && apt-get install -y \ # copy source code COPY library_generation /src -# install protobuf +# install protoc WORKDIR /protoc RUN ls /src RUN source /src/utils/utilities.sh \ From 706d0955e3fee98364523e3fa49dcac8e581833a Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Tue, 21 May 2024 21:55:55 +0000 Subject: [PATCH 50/57] remove debug dockerfile directive --- .cloudbuild/library_generation/library_generation.Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index 88167e0eb7..fdfab7081d 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -32,7 +32,6 @@ COPY library_generation /src # install protoc WORKDIR /protoc -RUN ls /src RUN source /src/utils/utilities.sh \ && download_protoc "${PROTOC_VERSION}" "linux-x86_64" # we indicate protoc is available in the container via env vars From 868a1bf49ad6faa4346bdcfb1293fd269cc627fa Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 22 May 2024 00:33:21 +0000 Subject: [PATCH 51/57] move docker embedded protoc logic outside of download_protoc --- library_generation/utils/utilities.sh | 28 +++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/library_generation/utils/utilities.sh b/library_generation/utils/utilities.sh index 2b8d1c8b88..5b4ac2d1e9 100755 --- a/library_generation/utils/utilities.sh +++ b/library_generation/utils/utilities.sh @@ -130,7 +130,18 @@ download_tools() { local os_architecture=$4 pushd "${output_folder}" download_generator_artifact "${gapic_generator_version}" "gapic-generator-java-${gapic_generator_version}.jar" - download_protoc "${protoc_version}" "${os_architecture}" + + # the variable protoc_path is used in generate_library.sh. It is explicitly + # exported to make clear that it is used outside this utilities file. + if [[ "${DOCKER_PROTOC_VERSION}" == "${protoc_version}" ]]; then + # if the specified protoc_version matches the one baked in the docker + # container, we just point protoc_path to its location. + export protoc_path="${DOCKER_PROTOC_LOCATION}/protoc-${protoc_version}" \ + "${output_folder}" + else + export protoc_path=$(download_protoc "${protoc_version}" "${os_architecture}") + fi + download_grpc_plugin "${grpc_version}" "${os_architecture}" popd } @@ -162,19 +173,7 @@ download_protoc() { local protoc_version=$1 local os_architecture=$2 - protoc_dirname="protoc-${protoc_version}" - protoc_path="${output_folder}/${protoc_dirname}/bin" - if [[ -f "${protoc_path}/protoc" ]]; then - return - fi - - if [[ "${DOCKER_PROTOC_VERSION}" == "${protoc_version}" ]]; then - # if the specified protoc_version matches the one baked in the docker - # container, we just copy it into the output folder - mkdir -p "${output_folder}/${protoc_dirname}" - cp -r "${DOCKER_PROTOC_LOCATION}/${protoc_dirname}" \ - "${output_folder}" - fi + local protoc_path="${output_folder}/protoc-${protoc_version}/bin" if [ ! -d "${protoc_path}" ]; then # pull proto files and protoc from protobuf repository as maven central @@ -187,6 +186,7 @@ download_protoc() { cp -r "protoc-${protoc_version}/include/google" . rm "protoc-${protoc_version}.zip" fi + echo "${protoc_path}" } From 6d7684380396c6761013eb0dcca6a756863fc2f5 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 22 May 2024 00:39:37 +0000 Subject: [PATCH 52/57] return from function early --- library_generation/utils/utilities.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/library_generation/utils/utilities.sh b/library_generation/utils/utilities.sh index ba85a65232..f929fd3c08 100755 --- a/library_generation/utils/utilities.sh +++ b/library_generation/utils/utilities.sh @@ -119,6 +119,7 @@ get_protoc_version() { if [[ -n "${DOCKER_PROTOC_VERSION}" ]]; then >&2 echo "Using protoc version baked into the container: ${DOCKER_PROTOC_VERSION}" echo "${DOCKER_PROTOC_VERSION}" + return fi pushd "${output_folder}" > /dev/null # get protobuf version from gapic-generator-java-pom-parent/pom.xml From 8a57737c9533e40f8eb3f25e44ad440623eed1cc Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 22 May 2024 00:41:29 +0000 Subject: [PATCH 53/57] remove test file from commit history --- ...gapic-generator-java-pom-parent-2.24.0.pom | 197 ------------------ 1 file changed, 197 deletions(-) delete mode 100644 library_generation/test/resources/output/gapic-generator-java-pom-parent-2.24.0.pom diff --git a/library_generation/test/resources/output/gapic-generator-java-pom-parent-2.24.0.pom b/library_generation/test/resources/output/gapic-generator-java-pom-parent-2.24.0.pom deleted file mode 100644 index 2a590d77f2..0000000000 --- a/library_generation/test/resources/output/gapic-generator-java-pom-parent-2.24.0.pom +++ /dev/null @@ -1,197 +0,0 @@ - - - 4.0.0 - com.google.api - gapic-generator-java-pom-parent - 2.24.0 - pom - GAPIC Generator Java POM Parent - https://github.com/googleapis/sdk-platform-java - - The top-level parent for all modules in the repository. - - - com.google.cloud - google-cloud-shared-config - 1.5.7 - - - - - false - java.header - - - 1.3.2 - 1.10.2 - 1.56.1 - 1.19.0 - 1.43.3 - 2.10.1 - 32.1.2-jre - - 3.23.2 - 8 - - - - - suztomo - Tomo Suzuki - suztomo@google.com - Google - - Developer - - - - - Google LLC - - - scm:git:git@github.com:googleapis/sdk-platform-java.git - scm:git:git@github.com:googleapis/sdk-platform-java.git - https://github.com/googleapis/sdk-platform-java - HEAD - - - https://github.com/googleapis/sdk-platform-java/issues - GitHub Issues - - - - - Apache-2.0 - https://www.apache.org/licenses/LICENSE-2.0.txt - - - - - - - checkstyle-tests - - [11,) - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - - - checkstyle - validate - - check - - - ${checkstyle.header.file} - - - - - - - - - - test-coverage - - - enableShowcaseTestCoverage - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.0.0-M8 - - - - **/*SmokeTest.java - **/IT*.java - - sponge_log - ${surefire.jacoco.args} - ${skipUnitTests} - - - - - org.apache.maven.plugins - maven-failsafe-plugin - 3.0.0 - - - - integration-test - verify - - - - - 3600 - sponge_log - - **/IT*.java - **/*SmokeTest.java - - ${failsafe.jacoco.args} - - - - - - - org.jacoco - jacoco-maven-plugin - 0.8.8 - - - unit-test-execution - - prepare-agent - - - surefire.jacoco.args - - - - integration-test-execution - pre-integration-test - - prepare-agent - - - failsafe.jacoco.args - - - - - - - - - - - google-maven-central-copy - Google Maven Central copy - https://maven-central.storage-download.googleapis.com/maven2 - - - maven-central - Maven Central - https://repo1.maven.org/maven2 - - - From 550f16263506af1fc173d6fde26bd4ca93c421d6 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 22 May 2024 01:11:15 +0000 Subject: [PATCH 54/57] fix unit tests --- .../test/generate_library_unit_tests.sh | 32 +++++++++++-------- library_generation/utils/utilities.sh | 3 +- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/library_generation/test/generate_library_unit_tests.sh b/library_generation/test/generate_library_unit_tests.sh index b13c8e53bd..5384d6982c 100755 --- a/library_generation/test/generate_library_unit_tests.sh +++ b/library_generation/test/generate_library_unit_tests.sh @@ -35,9 +35,6 @@ get_protoc_version_succeed_docker_env_var_test() { version_with_docker=$(get_protoc_version "2.24.0") assertEquals "${DOCKER_PROTOC_VERSION}" "${version_with_docker}" unset DOCKER_PROTOC_VERSION - version_without_docker=$(get_protoc_version "2.24.0") - assertEquals "23.2" "${version_without_docker}" - rm "gapic-generator-java-pom-parent-2.24.0.pom" } get_protoc_version_succeed_with_valid_generator_version_test() { @@ -146,25 +143,32 @@ download_protoc_failed_with_invalid_arch_test() { assertEquals 1 $((res)) } -download_protoc_succeed_with_baked_protoc() { +download_tools_succeed_with_baked_protoc() { # This mimics a docker container scenario. # This test consists of creating an empty /tmp/.../protoc-99.99/bin folder and map # it to the DOCKER_PROTOC_LOCATION env var (which is treated specially in the - # `download_protoc` function). If `DOCKER_PROTOC_VERSION` matches exactly as + # `download_tools` function). If `DOCKER_PROTOC_VERSION` matches exactly as # the version passed to `download_protoc`, then we will not download protoc - # but simply copy it from DOCKER_PROTOC_LOCATION into ${output_folder} (which - # we manually created in this test), so we should expect ${output_folder} to - # contain a folder called protoc-99.99. + # but simply have the variable `protoc_path` pointing to DOCKER_PROTOC_LOCATION + # (which we manually created in this test) + local test_dir=$(mktemp -d) + pushd "${test_dir}" export DOCKER_PROTOC_LOCATION=$(mktemp -d) export DOCKER_PROTOC_VERSION="99.99" export output_folder=$(get_output_folder) - mkdir -p "${DOCKER_PROTOC_LOCATION}/protoc-99.99/bin" - download_protoc "99.99" "linux-x86_64" - assertFileOrDirectoryExists "${output_folder}/protoc-99.99" - rm -rf "${output_folder}/protoc-99.99" + mkdir "${output_folder}" + local protoc_bin_folder="${DOCKER_PROTOC_LOCATION}/protoc-99.99/bin" + mkdir -p "${protoc_bin_folder}" + + local test_ggj_version="2.40.0" + local test_grpc_version="1.64.0" + download_tools "${test_ggj_version}" "99.99" "${test_grpc_version}" "linux-x86_64" + assertEquals "${protoc_bin_folder}" "${protoc_path}" + + rm -rdf "${output_folder}" unset DOCKER_PROTOC_LOCATION unset DOCKER_PROTOC_VERSION - rm -rdf $(get_output_folder) + unset output_folder } download_grpc_plugin_succeed_with_valid_version_linux_test() { @@ -302,7 +306,7 @@ test_list=( download_protoc_succeed_with_valid_version_macos_test download_protoc_failed_with_invalid_version_linux_test download_protoc_failed_with_invalid_arch_test - download_protoc_succeed_with_baked_protoc + download_tools_succeed_with_baked_protoc download_grpc_plugin_succeed_with_valid_version_linux_test download_grpc_plugin_succeed_with_valid_version_macos_test download_grpc_plugin_failed_with_invalid_version_linux_test diff --git a/library_generation/utils/utilities.sh b/library_generation/utils/utilities.sh index f929fd3c08..2e26ed6027 100755 --- a/library_generation/utils/utilities.sh +++ b/library_generation/utils/utilities.sh @@ -142,8 +142,7 @@ download_tools() { if [[ "${DOCKER_PROTOC_VERSION}" == "${protoc_version}" ]]; then # if the specified protoc_version matches the one baked in the docker # container, we just point protoc_path to its location. - export protoc_path="${DOCKER_PROTOC_LOCATION}/protoc-${protoc_version}" \ - "${output_folder}" + export protoc_path="${DOCKER_PROTOC_LOCATION}/protoc-${protoc_version}/bin" else export protoc_path=$(download_protoc "${protoc_version}" "${os_architecture}") fi From 340622c2492ee05e26dd95141a00d18cd7114184 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 22 May 2024 01:17:24 +0000 Subject: [PATCH 55/57] fix python units --- .../test/model/generation_config_unit_tests.py | 2 +- .../test/utils/generation_config_comparator_unit_tests.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/library_generation/test/model/generation_config_unit_tests.py b/library_generation/test/model/generation_config_unit_tests.py index 8f94ecae1e..dafbe238da 100644 --- a/library_generation/test/model/generation_config_unit_tests.py +++ b/library_generation/test/model/generation_config_unit_tests.py @@ -52,7 +52,7 @@ def test_from_yaml_succeeds(self): self.assertEqual( "1a45bf7393b52407188c82e63101db7dc9c72026", config.googleapis_commitish ) - self.assertEqual("26.37.0", config.libraris_bom_version) + self.assertEqual("26.37.0", config.libraries_bom_version) self.assertEqual( [ ".github/*", diff --git a/library_generation/test/utils/generation_config_comparator_unit_tests.py b/library_generation/test/utils/generation_config_comparator_unit_tests.py index 5792ead347..be0568c1f4 100644 --- a/library_generation/test/utils/generation_config_comparator_unit_tests.py +++ b/library_generation/test/utils/generation_config_comparator_unit_tests.py @@ -90,8 +90,8 @@ def test_compare_config_generator_update(self): self.assertEqual("1.2.4", config_change.current_value) def test_compare_config_libraries_bom_update(self): - self.baseline_config.libraris_bom_version = "26.36.0" - self.current_config.libraris_bom_version = "26.37.0" + self.baseline_config.libraries_bom_version = "26.36.0" + self.current_config.libraries_bom_version = "26.37.0" result = compare_config( baseline_config=self.baseline_config, current_config=self.current_config, @@ -100,7 +100,7 @@ def test_compare_config_libraries_bom_update(self): len(result.change_to_libraries[ChangeType.REPO_LEVEL_CHANGE]) == 1 ) config_change = result.change_to_libraries[ChangeType.REPO_LEVEL_CHANGE][0] - self.assertEqual("libraris_bom_version", config_change.changed_param) + self.assertEqual("libraries_bom_version", config_change.changed_param) self.assertEqual("26.37.0", config_change.current_value) def test_compare_protobuf_update(self): From 5e71efa12937552faf965cf2520994d2d4e2a74d Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Wed, 22 May 2024 01:57:23 +0000 Subject: [PATCH 56/57] fix IT --- .../library_generation/library_generation.Dockerfile | 2 +- library_generation/test/integration_tests.py | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/.cloudbuild/library_generation/library_generation.Dockerfile b/.cloudbuild/library_generation/library_generation.Dockerfile index f48f6ff2f4..9de0bc1c2c 100644 --- a/.cloudbuild/library_generation/library_generation.Dockerfile +++ b/.cloudbuild/library_generation/library_generation.Dockerfile @@ -17,7 +17,7 @@ FROM gcr.io/cloud-devrel-public-resources/python SHELL [ "/bin/bash", "-c" ] -ARG SYNTHTOOL_COMMITTISH=a2c9b4a5da2d7f583c8a1869fd2843c206145834 +ARG SYNTHTOOL_COMMITTISH=e36d2f164ca698f0264fb6f79ddc4b0fa024a940 ARG OWLBOT_CLI_COMMITTISH=ac84fa5c423a0069bbce3d2d869c9730c8fdf550 ARG PROTOC_VERSION=25.3 ENV HOME=/home diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index e4d298cd9c..d3ac7b7988 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -52,10 +52,6 @@ class IntegrationTest(unittest.TestCase): def setUpClass(cls) -> None: IntegrationTest.__build_image(docker_file=build_file, cwd=repo_root_dir) - @classmethod - def tearDownClass(cls) -> None: - cls.__remove_docker_image() - @classmethod def setUp(cls) -> None: cls.__remove_generated_files() @@ -308,6 +304,3 @@ def __recursive_diff_files( sub_dcmp, diff_files, left_only, right_only, dirname + sub_dirname + "/" ) - @classmethod - def __remove_docker_image(cls): - subprocess.check_call(["docker", "image", "rmi", image_tag]) From c4b7f72927ea0aa3e46da5ef0254b7950906afe5 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 23 May 2024 14:09:31 +0000 Subject: [PATCH 57/57] lint --- library_generation/test/integration_tests.py | 1 - 1 file changed, 1 deletion(-) diff --git a/library_generation/test/integration_tests.py b/library_generation/test/integration_tests.py index d3ac7b7988..5e5d219c61 100644 --- a/library_generation/test/integration_tests.py +++ b/library_generation/test/integration_tests.py @@ -303,4 +303,3 @@ def __recursive_diff_files( cls.__recursive_diff_files( sub_dcmp, diff_files, left_only, right_only, dirname + sub_dirname + "/" ) -