Skip to content

Commit

Permalink
Merge branch 'main' into renovate/googleapis-java-cloud-bom-digest
Browse files Browse the repository at this point in the history
  • Loading branch information
lqiu96 authored Apr 17, 2024
2 parents 3730dcd + 76a7b38 commit edf46f4
Show file tree
Hide file tree
Showing 29 changed files with 293 additions and 207 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ target/
# library generation
**/output/
**/googleapis
library_generation/test/**/golden*/
library_generation/test/resources/test_monorepo_postprocessing/
**/*egg-info/
**/build/
Expand Down
8 changes: 7 additions & 1 deletion java-shared-dependencies/third-party-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<google.cloud.opentelemetry.version>0.27.0</google.cloud.opentelemetry.version>
<j2objc-annotations.version>3.0.0</j2objc-annotations.version>
<opentelemetry.version>1.36.0</opentelemetry.version>
<opentelemetry-grpc-instrumentation.version>2.1.0-alpha</opentelemetry-grpc-instrumentation.version>
<flogger.version>0.8</flogger.version>
<arrow.version>15.0.1</arrow.version>
</properties>
Expand Down Expand Up @@ -126,6 +127,11 @@
<artifactId>commons-codec</artifactId>
<version>${codec.version}</version>
</dependency>
<dependency>
<groupId>io.opentelemetry.instrumentation</groupId>
<artifactId>opentelemetry-grpc-1.6</artifactId>
<version>${opentelemetry-grpc-instrumentation.version}</version>
</dependency>

<!-- TODO: replace with opencensus-bom when available -->
<dependency>
Expand Down Expand Up @@ -190,4 +196,4 @@
</dependency>
</dependencies>
</dependencyManagement>
</project>
</project>
54 changes: 30 additions & 24 deletions library_generation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,24 @@ of versions.txt.
For each module (e.g. `google-cloud-java/java-asset`), the following files/folders
will be created/modified:

| Name | Notes |
|:----------------------------|:-------------------------------------------------------------------------|
| google-*/ | Source code generated by gapic-generator-java |
| google-*/pom.xml | Only be generated if it does not exist |
| grpc-*/ | Source code generated by grpc generator, one per each version |
| grpc-*/pom.xml | Only be generated if it does not exist |
| proto-*/ | Source code generated by Protobuf default compiler, one per each version |
| proto-*/pom.xml | Only be generated if it does not exist |
| samples/snippets/generated/ | Only be generated if `include_samples` is set to true |
| google-*-bom/pom.xml | Library BOM, only be generated if it does not exist |
| pom.xml | Library parent BOM, only be generated if it does not exist |
| .repo-metadata.json | Always generated from inputs |
| .OwlBot.yaml | Only be generated from a template if it does not exist |
| owlbot.py | Only be generated from a template if it does not exist |
| README.md | Always generated from inputs |
| gapic-libraries-bom/pom.xml | Always generated from inputs |
| pom.xml (repo root dir) | Always generated from inputs |
| versions.txt | New entries will be added if they don’t exist |
| Name | Notes |
|:------------------------------------|:-------------------------------------------------------------------------|
| google-*/ | Source code generated by gapic-generator-java |
| google-*/pom.xml | Only be generated if it does not exist |
| grpc-*/ | Source code generated by grpc generator, one per each version |
| grpc-*/pom.xml | Only be generated if it does not exist |
| proto-*/ | Source code generated by Protobuf default compiler, one per each version |
| proto-*/pom.xml | Only be generated if it does not exist |
| samples/snippets/generated/ | Only be generated if `include_samples` is set to true |
| google-*-bom/pom.xml | Library BOM, only be generated if it does not exist |
| pom.xml | Library parent BOM, only be generated if it does not exist |
| .repo-metadata.json | Always generated from inputs |
| .OwlBot-hermetic.yaml | Only be generated from a template if it does not exist |
| owlbot.py | Only be generated from a template if it does not exist |
| README.md | Always generated from inputs |
| gapic-libraries-bom/pom.xml | Always generated from inputs |
| pom.xml (repo root dir) | Always generated from inputs |
| versions.txt | New entries will be added if they don’t exist |

### googleapis commit history

Expand All @@ -97,6 +97,7 @@ They are shared by library level parameters.
| protobuf_version | No | inferred from the generator if not specified |
| grpc_version | No | inferred from the generator if not specified |
| googleapis-commitish | Yes | |
| libraries_bom_version | Yes | |
| owlbot-cli-image | Yes | |
| synthtool-commitish | Yes | |
| template_excludes | Yes | |
Expand Down Expand Up @@ -147,6 +148,7 @@ The GAPIC level parameters define how to generate a GAPIC library.
gapic_generator_version: 2.34.0
protobuf_version: 25.2
googleapis_commitish: 1a45bf7393b52407188c82e63101db7dc9c72026
libraries_bom_version: 26.37.0
owlbot_cli_image: sha256:623647ee79ac605858d09e60c1382a716c125fb776f69301b72de1cd35d49409
synthtool_commitish: 6612ab8f3afcd5e292aecd647f0fa68812c9f5b5
destination_path: google-cloud-java
Expand Down Expand Up @@ -192,11 +194,15 @@ libraries:
# Local Environment Setup before running `entry_point.py`

1. Assuming Python 3 is installed, follow official guide from [Python.org](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#create-and-use-virtual-environments) to create a virtual environment. The virtual environment can be installed to any folder, usually it is recommended to be installed under the root folder of the project(`sdk-platform-java` in this case).
2. Assuming the virtual environment is installed under `sdk-platform-java`. Run the following command under the root folder of `sdk-platform-java` to install the dependencies of `library_generation`
1. Assuming Python 3 is installed, follow official guide from [Python.org](https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/#create-and-use-virtual-environments) to create a virtual environment.
The virtual environment can be installed to any folder, usually it is recommended to be installed under the root folder of the project(`sdk-platform-java` in this case).
2. Assuming the virtual environment is installed under `sdk-platform-java`.
Run the following command under the root folder of `sdk-platform-java` to install the dependencies of `library_generation`

```bash
python -m pip install -r library_generation/requirements.txt
```

3. Run the following command to install `library_generation` as a module, which allows the `library_generation` module to be imported from anywhere
```bash
python -m pip install library_generation/
Expand All @@ -206,8 +212,8 @@ python -m pip install library_generation/

```bash
python library_generation/entry_point.py generate \
--baseline-generation-config=/path/to/baseline_config_file \
--current-generation-config=/path/to/current_config_file \
--baseline-generation-config-path=/path/to/baseline_config_file \
--current-generation-config-path=/path/to/current_config_file \
--repository-path=path/to/repository
```
If you run `entry_point.py` with the example [configuration](#an-example-of-generation-configuration)
Expand All @@ -231,7 +237,7 @@ $repository_path
| |_samples
| | |_snippets
| | | |_generated
| |_.OwlBot.yaml
| |_.OwlBot-hermetic.yaml
| |_.repo-metadata.json
| |_owlbot.py
| |_pom.xml
Expand Down Expand Up @@ -275,7 +281,7 @@ $repository_path
| |_samples
| | |_snippets
| | | |_generated
| |_.OwlBot.yaml
| |_.OwlBot-hermetic.yaml
| |_.repo-metadata.json
| |_owlbot.py
| |_pom.xml
Expand Down
39 changes: 21 additions & 18 deletions library_generation/cli/entry_point.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def main(ctx):

@main.command()
@click.option(
"--baseline-generation-config",
"--baseline-generation-config-path",
required=False,
default=None,
type=str,
Expand All @@ -40,7 +40,7 @@ def main(ctx):
""",
)
@click.option(
"--current-generation-config",
"--current-generation-config-path",
required=False,
default=None,
type=str,
Expand All @@ -62,8 +62,8 @@ def main(ctx):
""",
)
def generate(
baseline_generation_config: str,
current_generation_config: str,
baseline_generation_config_path: str,
current_generation_config_path: str,
repository_path: str,
):
"""
Expand All @@ -87,47 +87,50 @@ def generate(
The commit history, if generated, will be available in
repository_path/pr_description.txt.
"""
default_generation_config = f"{os.getcwd()}/generation_config.yaml"
default_generation_config_path = f"{os.getcwd()}/generation_config.yaml"

if baseline_generation_config is None and current_generation_config is None:
if not os.path.isfile(default_generation_config):
if (
baseline_generation_config_path is None
and current_generation_config_path is None
):
if not os.path.isfile(default_generation_config_path):
raise FileNotFoundError(
f"{default_generation_config} does not exist. "
f"{default_generation_config_path} does not exist. "
"A valid generation config has to be passed in as "
"current_generation_config or exist in the current working "
"directory."
)
current_generation_config = default_generation_config
elif current_generation_config is None:
current_generation_config_path = default_generation_config_path
elif current_generation_config_path is None:
raise FileNotFoundError(
"current_generation_config is not specified when "
"baseline_generation_config is specified. "
"current_generation_config should be the source of truth of "
"library generation."
)

current_generation_config = os.path.abspath(current_generation_config)
current_generation_config_path = os.path.abspath(current_generation_config_path)
repository_path = os.path.abspath(repository_path)
if not baseline_generation_config:
if not baseline_generation_config_path:
# Execute full generation based on current_generation_config if
# baseline_generation_config is not specified.
# Do not generate pull request description.
generate_from_yaml(
config_path=current_generation_config,
config=from_yaml(current_generation_config),
config_path=current_generation_config_path,
config=from_yaml(current_generation_config_path),
repository_path=repository_path,
)
return

# Compare two generation configs and only generate changed libraries.
# Generate pull request description.
baseline_generation_config = os.path.abspath(baseline_generation_config)
baseline_generation_config_path = os.path.abspath(baseline_generation_config_path)
config_change = compare_config(
baseline_config=from_yaml(baseline_generation_config),
current_config=from_yaml(current_generation_config),
baseline_config=from_yaml(baseline_generation_config_path),
current_config=from_yaml(current_generation_config_path),
)
generate_from_yaml(
config_path=current_generation_config,
config_path=current_generation_config_path,
config=config_change.current_config,
repository_path=repository_path,
target_library_names=config_change.get_changed_libraries(),
Expand Down
2 changes: 1 addition & 1 deletion library_generation/generate_composed_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def generate_composed_library(
build_file_folder = Path(f"{output_folder}/{gapic.proto_path}").resolve()
print(f"build_file_folder: {build_file_folder}")
gapic_inputs = parse_build_file(build_file_folder, gapic.proto_path)
# generate prerequisite files (.repo-metadata.json, .OwlBot.yaml,
# generate prerequisite files (.repo-metadata.json, .OwlBot-hermetic.yaml,
# owlbot.py) here because transport is parsed from BUILD.bazel,
# which lives in a versioned proto_path.
util.generate_prerequisite_files(
Expand Down
8 changes: 8 additions & 0 deletions library_generation/generate_pr_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def generate_pr_descriptions(
The pull request description will be generated into
description_path/pr_description.txt.
If baseline_commit is the same as googleapis commit in the given generation
config, no pr_description.txt will be generated.
:param config: a GenerationConfig object. The googleapis commit in this
configuration is the latest commit, inclusively, from which the commit
message is considered.
Expand All @@ -90,6 +93,9 @@ def generate_pr_descriptions(
:param repo_url: the GitHub repository from which retrieves the commit
history.
"""
if baseline_commit == config.googleapis_commitish:
return

paths = config.get_proto_path_to_library_name()
description = get_commit_messages(
repo_url=repo_url,
Expand Down Expand Up @@ -126,6 +132,8 @@ def get_commit_messages(
:param paths: a mapping from file paths to library_name.
:param is_monorepo: whether to generate commit messages in a monorepo.
:return: commit messages.
:raise ValueError: if current_commit is older than or equal to
baseline_commit.
"""
tmp_dir = "/tmp/repo"
shutil.rmtree(tmp_dir, ignore_errors=True)
Expand Down
3 changes: 3 additions & 0 deletions library_generation/model/generation_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(
self,
gapic_generator_version: str,
googleapis_commitish: str,
libraries_bom_version: str,
owlbot_cli_image: str,
synthtool_commitish: str,
template_excludes: List[str],
Expand All @@ -38,6 +39,7 @@ def __init__(
):
self.gapic_generator_version = gapic_generator_version
self.googleapis_commitish = googleapis_commitish
self.libraris_bom_version = libraries_bom_version
self.owlbot_cli_image = owlbot_cli_image
self.synthtool_commitish = synthtool_commitish
self.template_excludes = template_excludes
Expand Down Expand Up @@ -116,6 +118,7 @@ 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"),
libraries_bom_version=__required(config, "libraries_bom_version"),
owlbot_cli_image=__required(config, "owlbot_cli_image"),
synthtool_commitish=__required(config, "synthtool_commitish"),
template_excludes=__required(config, "template_excludes"),
Expand Down
17 changes: 4 additions & 13 deletions library_generation/owlbot/bin/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,10 @@ set -ex
scripts_root=$1
versions_file=$2
configuration_yaml=$3
is_monorepo=$4


# This script can be used to process HW libraries and monorepo
# (google-cloud-java) libraries, which require a slightly different treatment
# monorepo folders have an .OwlBot.yaml file in the module folder (e.g.
# java-asset/.OwlBot.yaml), whereas HW libraries have the yaml in
# `.github/.OwlBot.yaml`
monorepo="false"
if [[ -f "$(pwd)/.OwlBot.yaml" ]]; then
monorepo="true"
fi

if [[ "${monorepo}" == "true" ]]; then
if [[ "${is_monorepo}" == "true" ]]; then
mv owl-bot-staging/* temp
rm -rd owl-bot-staging/
mv temp owl-bot-staging
Expand All @@ -50,7 +41,7 @@ fi

# apply repo templates
echo "Rendering templates"
python3 "${scripts_root}/owlbot/src/apply_repo_templates.py" "${configuration_yaml}" "${monorepo}"
python3 "${scripts_root}/owlbot/src/apply_repo_templates.py" "${configuration_yaml}" "${is_monorepo}"

# templates as well as retrieving files from owl-bot-staging
echo "Retrieving files from owl-bot-staging directory..."
Expand All @@ -66,7 +57,7 @@ echo "...done"

# write or restore pom.xml files
echo "Generating missing pom.xml..."
python3 "${scripts_root}/owlbot/src/fix-poms.py" "${versions_file}" "${monorepo}"
python3 "${scripts_root}/owlbot/src/fix-poms.py" "${versions_file}" "${is_monorepo}"
echo "...done"

# write or restore clirr-ignored-differences.xml
Expand Down
1 change: 1 addition & 0 deletions library_generation/owlbot/src/apply_repo_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def apply_repo_templates(configuration_yaml_path: str, monorepo: bool) -> None:
excludes=config.template_excludes,
template_path=Path(repo_templates_path),
monorepo=monorepo,
libraries_bom_version=config.libraris_bom_version,
)


Expand Down
2 changes: 1 addition & 1 deletion library_generation/owlbot/templates/java_library/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ If you are using Maven with [BOM][libraries-bom], add this to your pom.xml file:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>{{ metadata['latest_bom_version'] }}</version>
<version>{{ metadata['libraries_bom_version'] }}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
Loading

0 comments on commit edf46f4

Please sign in to comment.