Skip to content

Commit 377735a

Browse files
chore: add scripts to update discovery artifacts
1 parent cc717a1 commit 377735a

File tree

7 files changed

+844
-66
lines changed

7 files changed

+844
-66
lines changed

scripts/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Discovery Artifact Automation
2+
Discovery Artifacts are automatically updated using a Github Action script. This
3+
documentation is intended for users that need to maintain the repository.
4+
5+
## Updating discovery artifacts locally
6+
7+
To update discovery artifacts locally:
8+
1. Create a virtual environment using `pyenv virtualenv updateartifacts`
9+
2. Activate the virtual environment using `pyenv activate updateartifacts`
10+
3. Clone the repository, and `cd` into the `scripts` directory
11+
4. Run `pip install -r requirements.txt`
12+
5. Run `pip install -e ../`
13+
6. Run `git checkout -b update-discovery-artifacts-manual`
14+
7. Run `python3 updatediscoveryartifacts.py`
15+
8. Run `./createcommits.sh`
16+
9. Create a pull request with the changes
17+
18+
## Questions
19+
Feel free to submit an issue!

scripts/buildprbody.py

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
# Copyright 2021 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+
# https://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+
from enum import IntEnum
16+
import numpy as np
17+
import os
18+
import pandas as pd
19+
20+
21+
class ChangeType(IntEnum):
22+
UNKNOWN = 0
23+
DELETED = 1
24+
ADDED = 2
25+
CHANGED = 3
26+
27+
28+
def get_commit_link(name):
29+
"""Return a string with a link to the last commit for the given
30+
API Name.
31+
args:
32+
name (str): The name of the api.
33+
"""
34+
35+
url = "https://github.com/googleapis/google-api-python-client/commit/"
36+
sha = None
37+
api_link = ""
38+
39+
file_path = os.path.join(directory, "{0}.sha".format(name))
40+
if os.path.exists(file_path):
41+
with open(file_path, "r") as f:
42+
sha = f.readline().rstrip()
43+
if sha:
44+
api_link = "[{0}]({1}{2})".format(" [More details]", url, sha)
45+
46+
return api_link
47+
48+
49+
if __name__ == "__main__":
50+
directory = "temp"
51+
dataframe = pd.read_csv("temp/allapis.dataframe")
52+
dataframe["Version"] = dataframe["Version"].astype(str)
53+
54+
dataframe["Commit"] = np.vectorize(get_commit_link)(dataframe["Name"])
55+
56+
stable_and_breaking = (
57+
dataframe[
58+
dataframe["IsStable"]
59+
& (dataframe["ChangeType"] == ChangeType.DELETED)
60+
][["Name", "Version", "Commit"]]
61+
.drop_duplicates()
62+
.agg("".join, axis=1)
63+
.values
64+
)
65+
66+
prestable_and_breaking = (
67+
dataframe[
68+
(dataframe["IsStable"] == False)
69+
& (dataframe["ChangeType"] == ChangeType.DELETED)
70+
][["Name", "Version", "Commit"]]
71+
.drop_duplicates()
72+
.agg("".join, axis=1)
73+
.values
74+
)
75+
76+
all_apis = (
77+
dataframe[["Name", "Version", "Commit"]]
78+
.drop_duplicates()
79+
.agg("".join, axis=1)
80+
.values
81+
)
82+
83+
with open(os.path.join(directory, "allapis.summary"), "w") as f:
84+
if len(stable_and_breaking) > 0:
85+
f.writelines(
86+
[
87+
"## Deleted keys were detected in the following stable discovery artifacts:\n",
88+
"\n".join(stable_and_breaking),
89+
"\n\n",
90+
]
91+
)
92+
93+
if len(prestable_and_breaking) > 0:
94+
f.writelines(
95+
[
96+
"## Deleted keys were detected in the following pre-stable discovery artifacts:\n",
97+
"\n".join(prestable_and_breaking),
98+
"\n\n",
99+
]
100+
)
101+
102+
if len(all_apis) > 0:
103+
f.writelines(
104+
["## Discovery Artifact Change Summary:\n", "\n".join(all_apis), "\n"]
105+
)

0 commit comments

Comments
 (0)