From d4b291604f148cde065838c498bc8aa79b8dc10e Mon Sep 17 00:00:00 2001 From: Tomo Suzuki Date: Sun, 6 Nov 2022 23:06:11 -0500 Subject: [PATCH] chore(java): add a note in README for migrated split repos (#1687) * chore(java): add a note in README for migrated split repos Disable renovate bot and flaky bot for split repositories that have moved to the Java monorepo. The Java monorepo will pass the "monorepo=True" parameter to java.common_templates method in its owlbot.py files so that the migration note will not appear in the README in the monorepo. Co-authored-by: Jeff Ching --- docker/owlbot/java/README.md | 50 +++++++++++++++++++ .../.github/ISSUE_TEMPLATE/bug_report.md | 7 ++- .../.github/ISSUE_TEMPLATE/feature_request.md | 7 ++- .../.kokoro/nightly/integration.cfg | 2 +- .../.kokoro/nightly/java11-integration.cfg | 2 +- .../java_library/.kokoro/nightly/samples.cfg | 2 +- .../gcp/templates/java_library/README.md | 9 +++- .../gcp/templates/java_library/renovate.json | 6 ++- synthtool/languages/java.py | 32 +++++++++++- 9 files changed, 108 insertions(+), 9 deletions(-) diff --git a/docker/owlbot/java/README.md b/docker/owlbot/java/README.md index 3682452c3..55b8a1f12 100644 --- a/docker/owlbot/java/README.md +++ b/docker/owlbot/java/README.md @@ -19,6 +19,38 @@ docker run --rm -v $(pwd):/workspace --user "$(id -u):$(id -g)" gcr.io/repo-auto ### Building the image +#### Local Docker + +From the root of the synthtool repository, run: + +```bash +synthtool$ docker build -f docker/owlbot/java/Dockerfile . +... +Removing intermediate container e6d071e39d1b + ---> a7d7e0c80b00 +Successfully built a7d7e0c80b00 +``` + +"a7d7e0c80b00" is the ID of the container image build. Try running the +postprocessor image with a target repository. +Here is an example with java-aiplatform repository below: + +```bash +java-aiplatform$ git checkout -b test_postprocessor origin/main +branch 'test_postprocessor' set up to track 'origin/main'. +Switched to a new branch 'test_postprocessor' +java-aiplatform$ docker run --rm -v $(pwd):/workspace a7d7e0c80b00 +... +Reformatting source... +...done +java-aiplatform$ git diff +... (shows the generated file differences) ... +``` + +This manual confirmation identifies syntax errors in Python scripts and the +templates. + +#### Cloud Build This image is built via Cloud Build. From the root of this repository, run: ```bash @@ -32,3 +64,21 @@ To rebuild the golden test fixtures: 1. Delete the `golden` directory. 2. Copy the `input` directory recursively to `golden` 3. [Run the latest owlbot image](#running-locally) against the `golden` directory. + +### Lint error + +When you modify Python scripts, you may encounter lint errors +Kokoro build: + +``` +nox > black --check synthtool tests +would reformat synthtool/languages/java.py + +Oh no! 💥 💔 💥 +1 file would be reformatted, 78 files would be left unchanged. +``` + +In this case, install [nox](https://nox.thea.codes/en/stable/) and run +`nox -s lint` to reproduce the lint problems and `black synthtool` applies +the suggested formatting. + diff --git a/synthtool/gcp/templates/java_library/.github/ISSUE_TEMPLATE/bug_report.md b/synthtool/gcp/templates/java_library/.github/ISSUE_TEMPLATE/bug_report.md index c24d5984c..c7539a687 100644 --- a/synthtool/gcp/templates/java_library/.github/ISSUE_TEMPLATE/bug_report.md +++ b/synthtool/gcp/templates/java_library/.github/ISSUE_TEMPLATE/bug_report.md @@ -3,7 +3,12 @@ name: Bug report about: Create a report to help us improve --- - +{% if migrated_split_repo %} +:bus: This library has moved to +[google-cloud-java/{{ metadata['repo']['repo_short'] }}]( +https://github.com/googleapis/google-cloud-java/tree/main/{{ metadata['repo']['repo_short'] }}). +This repository will be archived in the future. +{% endif %} Thanks for stopping by to let us know something could be better! **PLEASE READ**: If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response. diff --git a/synthtool/gcp/templates/java_library/.github/ISSUE_TEMPLATE/feature_request.md b/synthtool/gcp/templates/java_library/.github/ISSUE_TEMPLATE/feature_request.md index 754e30c68..f89a7dc59 100644 --- a/synthtool/gcp/templates/java_library/.github/ISSUE_TEMPLATE/feature_request.md +++ b/synthtool/gcp/templates/java_library/.github/ISSUE_TEMPLATE/feature_request.md @@ -3,7 +3,12 @@ name: Feature request about: Suggest an idea for this library --- - +{% if migrated_split_repo %} +:bus: This library has moved to +[google-cloud-java/{{ metadata['repo']['repo_short'] }}]( +https://github.com/googleapis/google-cloud-java/tree/main/{{ metadata['repo']['repo_short'] }}). +This repository will be archived in the future. +{% endif %} Thanks for stopping by to let us know something could be better! **PLEASE READ**: If you have a support contract with Google, please create an issue in the [support console](https://cloud.google.com/support/) instead of filing on GitHub. This will ensure a timely response. diff --git a/synthtool/gcp/templates/java_library/.kokoro/nightly/integration.cfg b/synthtool/gcp/templates/java_library/.kokoro/nightly/integration.cfg index a2907a257..8944ac33e 100644 --- a/synthtool/gcp/templates/java_library/.kokoro/nightly/integration.cfg +++ b/synthtool/gcp/templates/java_library/.kokoro/nightly/integration.cfg @@ -23,7 +23,7 @@ env_vars: { env_vars: { key: "ENABLE_FLAKYBOT" - value: "true" + value: {% if migrated_split_repo %}"false"{% else %}"true"{% endif %} } env_vars: { diff --git a/synthtool/gcp/templates/java_library/.kokoro/nightly/java11-integration.cfg b/synthtool/gcp/templates/java_library/.kokoro/nightly/java11-integration.cfg index 58049cc38..2981759c1 100644 --- a/synthtool/gcp/templates/java_library/.kokoro/nightly/java11-integration.cfg +++ b/synthtool/gcp/templates/java_library/.kokoro/nightly/java11-integration.cfg @@ -23,7 +23,7 @@ env_vars: { env_vars: { key: "ENABLE_FLAKYBOT" - value: "true" + value: {% if migrated_split_repo %}"false"{% else %}"true"{% endif %} } env_vars: { diff --git a/synthtool/gcp/templates/java_library/.kokoro/nightly/samples.cfg b/synthtool/gcp/templates/java_library/.kokoro/nightly/samples.cfg index 9761fd864..bc9b4e2a8 100644 --- a/synthtool/gcp/templates/java_library/.kokoro/nightly/samples.cfg +++ b/synthtool/gcp/templates/java_library/.kokoro/nightly/samples.cfg @@ -34,5 +34,5 @@ env_vars: { env_vars: { key: "ENABLE_FLAKYBOT" - value: "true" + value: {% if migrated_split_repo %}"false"{% else %}"true"{% endif %} } diff --git a/synthtool/gcp/templates/java_library/README.md b/synthtool/gcp/templates/java_library/README.md index e50e4b920..085f84506 100644 --- a/synthtool/gcp/templates/java_library/README.md +++ b/synthtool/gcp/templates/java_library/README.md @@ -17,7 +17,14 @@ Java idiomatic client for [{{metadata['repo']['name_pretty']}}][product-docs]. > Note: This client is a work-in-progress, and may occasionally > make backwards-incompatible changes. {% endif %} - +{% if migrated_split_repo %} +:bus: In October 2022, this library has moved to +[google-cloud-java/{{ metadata['repo']['repo_short'] }}]( +https://github.com/googleapis/google-cloud-java/tree/main/{{ metadata['repo']['repo_short'] }}). +This repository will be archived in the future. +Future releases will appear in the new repository (https://github.com/googleapis/google-cloud-java/releases). +The Maven artifact coordinates (`{{ group_id }}:{{ artifact_id }}`) remain the same. +{% endif %} ## Quickstart {% if 'snippets' in metadata and metadata['snippets'][metadata['repo']['api_shortname'] + '_install_with_bom'] -%} diff --git a/synthtool/gcp/templates/java_library/renovate.json b/synthtool/gcp/templates/java_library/renovate.json index 6855f0e13..b4b9ba1d4 100644 --- a/synthtool/gcp/templates/java_library/renovate.json +++ b/synthtool/gcp/templates/java_library/renovate.json @@ -1,5 +1,7 @@ -{ - "extends": [ +{% if migrated_split_repo %}{ + "enabled": false, +{% else %}{ +{% endif %} "extends": [ ":separateMajorReleases", ":combinePatchMinorReleases", ":ignoreUnstable", diff --git a/synthtool/languages/java.py b/synthtool/languages/java.py index 2202c69e8..12cfe24aa 100644 --- a/synthtool/languages/java.py +++ b/synthtool/languages/java.py @@ -484,7 +484,37 @@ def common_templates( excludes (List[str], optional): List of template paths to ignore **kwargs: Additional options for CommonTemplates.java_library() """ - kwargs["metadata"] = _common_template_metadata() + metadata = _common_template_metadata() + kwargs["metadata"] = metadata + + # Generate flat to tell this repository is a split repo that have migrated + # to monorepo. The owlbot.py in the monorepo sets monorepo=True. + monorepo = kwargs.get("monorepo", False) + split_repo = not monorepo + repo_metadata = metadata["repo"] + repo_short = repo_metadata["repo_short"] + # Special libraries that are not GAPIC_AUTO but in the monorepo + special_libs_in_monorepo = [ + "java-translate", + "java-dns", + "java-notification", + "java-resourcemanager", + ] + kwargs["migrated_split_repo"] = split_repo and ( + repo_metadata["library_type"] == "GAPIC_AUTO" + or (repo_short and repo_short in special_libs_in_monorepo) + ) + logger.info( + "monorepo: {}, split_repo: {}, library_type: {}," + " repo_short: {}, migrated_split_repo: {}".format( + monorepo, + split_repo, + repo_metadata["library_type"], + repo_short, + kwargs["migrated_split_repo"], + ) + ) + templates = gcp.CommonTemplates(template_path=template_path).java_library(**kwargs) # skip README generation on Kokoro (autosynth)