Skip to content

Commit f9845be

Browse files
igorbernstein2garrettjonesgoogle
authored andcommitted
generate-api: print component versions (#3552)
1 parent d55a0f4 commit f9845be

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

utilities/batch_generate_apis.py

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ def main():
9696
help='The path to the discovery-artifact-manager repo')
9797
args = parser.parse_args()
9898

99+
generate_api.dump_versions(googleapis=args.googleapis, discovery_repo=args.discovery_repo)
100+
99101
run_gapic_gen(args.googleapis)
100102
run_discogapic_gen(args.discovery_repo)
101103

utilities/generate_api.py

+36
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020
# $ python utilities/generate_api.py PATH_TO_ARTMAN_CONFIG_FILE ARTIFACT_NAME
2121

2222
import argparse
23+
import collections
2324
import io
2425
import os
26+
import re
2527
import shutil
2628
import subprocess
2729

@@ -40,6 +42,37 @@
4042
JAVA_GAPIC="java_gapic"
4143
JAVA_DISCOGAPIC="java_discogapic"
4244

45+
def get_git_repo_version(path):
46+
commit = subprocess.check_output(['git', '-C', path, 'rev-parse', 'HEAD']).strip()
47+
suffix = ''
48+
49+
changes = subprocess.check_output(['git', '-C', path, 'diff', '--stat'])
50+
51+
if changes:
52+
suffix = " ({})".format(changes.splitlines()[-1])
53+
54+
return ''.join([commit, suffix])
55+
56+
57+
def dump_versions(googleapis=None, discovery_repo=None):
58+
print("Component versions:")
59+
60+
print(subprocess.check_output(['artman', '--version'], stderr=subprocess.STDOUT).strip())
61+
62+
with io.open(os.path.expanduser("~/.artman/config.yaml"), encoding='UTF-8') as config_file:
63+
artman_config_data = yaml.load(config_file, Loader=yaml.Loader)
64+
toolkit_path = artman_config_data['local']['toolkit']
65+
print("gapic_generator {}".format(get_git_repo_version(toolkit_path)))
66+
67+
print("google-cloud-java {}".format(get_git_repo_version(os.path.dirname(__file__))))
68+
69+
if googleapis:
70+
print("googleapis {}".format(get_git_repo_version(googleapis)))
71+
72+
if discovery_repo:
73+
print("discovery_repo {}".format(get_git_repo_version(discovery_repo)))
74+
75+
4376
def run_generate_api(config_path, artifact_name, noisy=False):
4477
""" Generate an API client library.
4578
@@ -138,6 +171,9 @@ def main():
138171
help='Don\'t print informational instructions')
139172
args = parser.parse_args()
140173

174+
if not args.quiet:
175+
dump_versions(googleapis=os.path.dirname(args.config_file))
176+
141177
run_generate_api(args.config_file, args.artifact_name, not args.quiet)
142178

143179
if __name__ == '__main__':

0 commit comments

Comments
 (0)