Skip to content

Commit

Permalink
chore(java): add a note in README for migrated split repos (#1687)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
suztomo and chingor13 authored Nov 7, 2022
1 parent e4969d0 commit d4b2916
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 9 deletions.
50 changes: 50 additions & 0 deletions docker/owlbot/java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.

Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ env_vars: {

env_vars: {
key: "ENABLE_FLAKYBOT"
value: "true"
value: {% if migrated_split_repo %}"false"{% else %}"true"{% endif %}
}

env_vars: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ env_vars: {

env_vars: {
key: "ENABLE_FLAKYBOT"
value: "true"
value: {% if migrated_split_repo %}"false"{% else %}"true"{% endif %}
}

env_vars: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@ env_vars: {

env_vars: {
key: "ENABLE_FLAKYBOT"
value: "true"
value: {% if migrated_split_repo %}"false"{% else %}"true"{% endif %}
}
9 changes: 8 additions & 1 deletion synthtool/gcp/templates/java_library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'] -%}
Expand Down
6 changes: 4 additions & 2 deletions synthtool/gcp/templates/java_library/renovate.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"extends": [
{% if migrated_split_repo %}{
"enabled": false,
{% else %}{
{% endif %} "extends": [
":separateMajorReleases",
":combinePatchMinorReleases",
":ignoreUnstable",
Expand Down
32 changes: 31 additions & 1 deletion synthtool/languages/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d4b2916

Please sign in to comment.