Skip to content

Commit 385ba52

Browse files
authored
chore: add librarian state.yaml (googleapis#14108)
Fixes googleapis/librarian#867
1 parent 212dc0f commit 385ba52

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed

.librarian/state.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
image: google-cloud-python-generator:latest
2+
libraries:
3+
- apis:
4+
- path: google/cloud/language/v1beta2
5+
service_config: ''
6+
- path: google/cloud/language/v2
7+
service_config: ''
8+
- path: google/cloud/language/v1
9+
service_config: ''
10+
id: google-cloud-language
11+
last_generated_commit: 97a83d76a09a7f6dcab43675c87bdfeb5bcf1cb5
12+
preserve_regex: ''
13+
remove_regex: ''
14+
sourcePaths:
15+
- packages/google-cloud-language
16+
version: 2.17.2
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
import json
17+
from pathlib import Path
18+
from typing import List
19+
import yaml
20+
21+
SCRIPT_DIR = Path(__file__).resolve().parent
22+
ROOT_DIR = Path(SCRIPT_DIR / ".." / "..").resolve()
23+
PACKAGES_DIR = ROOT_DIR / "packages"
24+
PACKAGES_TO_ONBOARD_YAML = SCRIPT_DIR / "packages_to_onboard.yaml"
25+
LIBRARIAN_DIR = ROOT_DIR / ".librarian"
26+
LIBRARIAN_YAML = LIBRARIAN_DIR / "state.yaml"
27+
RELEASE_PLEASE_MANIFEST_JSON = ROOT_DIR / ".release-please-manifest.json"
28+
GAPIC_METADATA_JSON = "gapic_metadata.json"
29+
30+
31+
def configure_state_yaml() -> None:
32+
"""
33+
This method updates the `state.yaml` file in the directory
34+
`.librarian`.
35+
"""
36+
37+
state_dict = {}
38+
39+
release_please_manifest = {}
40+
with open(RELEASE_PLEASE_MANIFEST_JSON, "r") as release_please_manifest_json_file:
41+
release_please_manifest = json.load(release_please_manifest_json_file)
42+
43+
packages_to_onboard = {}
44+
with open(PACKAGES_TO_ONBOARD_YAML, "r") as packages_to_onboard_yaml_file:
45+
packages_to_onboard = yaml.safe_load(packages_to_onboard_yaml_file)
46+
47+
state_dict["image"] = "google-cloud-python-generator:latest"
48+
state_dict["libraries"] = []
49+
for package_name in packages_to_onboard["packages_to_onboard"]:
50+
package_path = Path(PACKAGES_DIR / package_name).resolve()
51+
api_paths = []
52+
for individual_metadata_file in package_path.rglob(f"**/{GAPIC_METADATA_JSON}"):
53+
with open(individual_metadata_file, "r") as gapic_metadata_json_file:
54+
gapic_metadata = json.load(gapic_metadata_json_file)
55+
api_paths.extend(
56+
[
57+
{
58+
"path": gapic_metadata["protoPackage"].replace(".", "/"),
59+
"service_config": "",
60+
}
61+
]
62+
)
63+
state_dict["libraries"].append(
64+
{
65+
"id": package_name,
66+
"version": release_please_manifest[f"packages/{package_name}"],
67+
"last_generated_commit": "97a83d76a09a7f6dcab43675c87bdfeb5bcf1cb5",
68+
"apis": api_paths,
69+
"sourcePaths": [f"packages/{package_name}"],
70+
"preserve_regex": "",
71+
"remove_regex": "",
72+
}
73+
)
74+
75+
with open(LIBRARIAN_YAML, "w") as f:
76+
yaml.dump(state_dict, f)
77+
78+
79+
if __name__ == "__main__":
80+
configure_state_yaml()
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
16+
packages_to_onboard: [
17+
"google-cloud-language"
18+
]

0 commit comments

Comments
 (0)