@@ -275,12 +275,20 @@ def update_bom_pom(filename: str, modules: List[module.Module]):
275
275
tree .write (filename , pretty_print = True , xml_declaration = True , encoding = "utf-8" )
276
276
277
277
def main ():
278
+ print (f"working directory: { os .getcwd ()} " )
278
279
with open (".repo-metadata.json" , "r" ) as fp :
279
280
repo_metadata = json .load (fp )
280
-
281
281
group_id , artifact_id = repo_metadata ["distribution_name" ].split (":" )
282
282
name = repo_metadata ["name_pretty" ]
283
283
existing_modules = load_versions ("versions.txt" , group_id )
284
+ monorepo = False
285
+ if not existing_modules :
286
+ # For single-component Release Please setup, the root versions.txt
287
+ # manages the versions of all submodules.
288
+ existing_modules = load_versions ("../versions.txt" , group_id )
289
+ if existing_modules :
290
+ monorepo = True
291
+ print (f"monorepo? { monorepo } " )
284
292
285
293
# extra modules that need to be manages in versions.txt
286
294
if "extra_versioned_modules" in repo_metadata :
@@ -300,6 +308,7 @@ def main():
300
308
else :
301
309
excluded_poms_list = ""
302
310
311
+ # Missing Case 1: When this library ('java-XXX' module) is new.
303
312
if artifact_id not in existing_modules :
304
313
existing_modules [artifact_id ] = module .Module (
305
314
group_id = group_id ,
@@ -322,9 +331,18 @@ def main():
322
331
323
332
required_dependencies = {}
324
333
for dependency_module in existing_modules :
325
- if dependency_module not in excluded_dependencies_list :
326
- required_dependencies [dependency_module ] = existing_modules [dependency_module ]
334
+ if dependency_module in excluded_dependencies_list :
335
+ continue
336
+ dep_artifact_id = existing_modules [dependency_module ].artifact_id
337
+ if monorepo and not os .path .isdir (dep_artifact_id ):
338
+ # In monorepo, existing_modules are loaded from the root
339
+ # versions.txt and thus includes irrelevant artifacts
340
+ continue
341
+ required_dependencies [dependency_module ] = existing_modules [dependency_module ]
327
342
343
+ # Missing Case 2: There's a new proto-XXX and grpc-XXX directory. It's a new
344
+ # version in the proto file to a library. Both a new library and existing
345
+ # library.
328
346
for path in glob .glob ("proto-google-*" ):
329
347
if not path in existing_modules :
330
348
existing_modules [path ] = module .Module (
@@ -463,10 +481,10 @@ def main():
463
481
name = name ,
464
482
)
465
483
466
- if os . path . isfile ( "versions.txt" ):
467
- print ( "updating modules in versions.txt" )
468
- else :
469
- print ("creating missing versions.txt " )
484
+ # For monorepo, we use the versions.txt at the root. The "./" is needed
485
+ # for the templates.render(), which tries to create a directory.
486
+ versions_txt_file = "../versions.txt" if monorepo else "./versions.txt"
487
+ print (f"updating modules in { versions_txt_file } " )
470
488
existing_modules .pop (parent_artifact_id )
471
489
472
490
# add extra modules to versions.txt
@@ -479,7 +497,7 @@ def main():
479
497
release_version = main_module .release_version ,
480
498
)
481
499
templates .render (
482
- template_name = "versions.txt.j2" , output_name = "./versions.txt" , modules = existing_modules .values (),
500
+ template_name = "versions.txt.j2" , output_name = versions_txt_file , modules = existing_modules .values (),
483
501
)
484
502
485
503
if __name__ == "__main__" :
0 commit comments