diff --git a/.librarian/state.yaml b/.librarian/state.yaml new file mode 100644 index 000000000000..5b496e7d6f4d --- /dev/null +++ b/.librarian/state.yaml @@ -0,0 +1,16 @@ +image: google-cloud-python-generator:latest +libraries: +- apis: + - path: google/cloud/language/v1beta2 + service_config: '' + - path: google/cloud/language/v2 + service_config: '' + - path: google/cloud/language/v1 + service_config: '' + id: google-cloud-language + last_generated_commit: 97a83d76a09a7f6dcab43675c87bdfeb5bcf1cb5 + preserve_regex: '' + remove_regex: '' + sourcePaths: + - packages/google-cloud-language + version: 2.17.2 diff --git a/scripts/configure_state_yaml/configure_state_yaml.py b/scripts/configure_state_yaml/configure_state_yaml.py new file mode 100644 index 000000000000..9a05aa6069ff --- /dev/null +++ b/scripts/configure_state_yaml/configure_state_yaml.py @@ -0,0 +1,80 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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 json +from pathlib import Path +from typing import List +import yaml + +SCRIPT_DIR = Path(__file__).resolve().parent +ROOT_DIR = Path(SCRIPT_DIR / ".." / "..").resolve() +PACKAGES_DIR = ROOT_DIR / "packages" +PACKAGES_TO_ONBOARD_YAML = SCRIPT_DIR / "packages_to_onboard.yaml" +LIBRARIAN_DIR = ROOT_DIR / ".librarian" +LIBRARIAN_YAML = LIBRARIAN_DIR / "state.yaml" +RELEASE_PLEASE_MANIFEST_JSON = ROOT_DIR / ".release-please-manifest.json" +GAPIC_METADATA_JSON = "gapic_metadata.json" + + +def configure_state_yaml() -> None: + """ + This method updates the `state.yaml` file in the directory + `.librarian`. + """ + + state_dict = {} + + release_please_manifest = {} + with open(RELEASE_PLEASE_MANIFEST_JSON, "r") as release_please_manifest_json_file: + release_please_manifest = json.load(release_please_manifest_json_file) + + packages_to_onboard = {} + with open(PACKAGES_TO_ONBOARD_YAML, "r") as packages_to_onboard_yaml_file: + packages_to_onboard = yaml.safe_load(packages_to_onboard_yaml_file) + + state_dict["image"] = "google-cloud-python-generator:latest" + state_dict["libraries"] = [] + for package_name in packages_to_onboard["packages_to_onboard"]: + package_path = Path(PACKAGES_DIR / package_name).resolve() + api_paths = [] + for individual_metadata_file in package_path.rglob(f"**/{GAPIC_METADATA_JSON}"): + with open(individual_metadata_file, "r") as gapic_metadata_json_file: + gapic_metadata = json.load(gapic_metadata_json_file) + api_paths.extend( + [ + { + "path": gapic_metadata["protoPackage"].replace(".", "/"), + "service_config": "", + } + ] + ) + state_dict["libraries"].append( + { + "id": package_name, + "version": release_please_manifest[f"packages/{package_name}"], + "last_generated_commit": "97a83d76a09a7f6dcab43675c87bdfeb5bcf1cb5", + "apis": api_paths, + "sourcePaths": [f"packages/{package_name}"], + "preserve_regex": "", + "remove_regex": "", + } + ) + + with open(LIBRARIAN_YAML, "w") as f: + yaml.dump(state_dict, f) + + +if __name__ == "__main__": + configure_state_yaml() diff --git a/scripts/configure_state_yaml/packages_to_onboard.yaml b/scripts/configure_state_yaml/packages_to_onboard.yaml new file mode 100644 index 000000000000..d7439feccec9 --- /dev/null +++ b/scripts/configure_state_yaml/packages_to_onboard.yaml @@ -0,0 +1,18 @@ +# Copyright 2025 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# 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. +# + +packages_to_onboard: [ + "google-cloud-language" +]