@@ -288,6 +288,63 @@ def modify_pod_file(pod_file, pod_version_map, dryrun=True):
288
288
podfile .writelines (existing_lines )
289
289
print ()
290
290
291
+
292
+ RE_README_POD_VERSION = re .compile (
293
+ r"<br>(?P<pod_name>.+) Cocoapod \((?P<version>.+)\)" )
294
+
295
+ def modify_readme_file_pods (readme_filepath , version_map , dryrun = True ):
296
+ """Modify a readme Markdown file to reference correct cocoapods versions.
297
+
298
+ Looks for lines like:
299
+ <br>Firebase/AdMob Cocoapod (7.11.0)
300
+ for pods matching the ones in the version map, and modifies them in-place.
301
+
302
+ Args:
303
+ readme_filepath: Path to readme file to edit.
304
+ version_map: Dictionary of packages to version numbers, e.g. {
305
+ 'FirebaseAuth': '15.0.0' }
306
+ dryrun (bool, optional): Just print the substitutions.
307
+ Do not write to file. Defaults to True.
308
+ """
309
+ logging .debug ('Reading readme file: {0}' .format (readme_filepath ))
310
+
311
+ lines = None
312
+ with open (readme_filepath , "r" ) as readme_file :
313
+ lines = readme_file .readlines ()
314
+ if not lines :
315
+ logging .fatal ('Could not read contents of file %s' , readme_filepath )
316
+
317
+ output_lines = []
318
+
319
+ # Replacement function, look up the version number of the given pkg.
320
+ def replace_module_line (m ):
321
+ if not m .group ('pod_name' ):
322
+ return m .group (0 )
323
+ pod_key = m .group ('pod_name' ).replace ('/' , '' )
324
+ if pod_key not in version_map :
325
+ return m .group (0 )
326
+ repl = '%s Cocoapod (%s)' % (m .group ('pod_name' ), version_map [pod_key ])
327
+ return '<br>{0}' .format (repl )
328
+
329
+ substituted_pairs = []
330
+ for line in lines :
331
+ substituted_line = re .sub (RE_README_ANDROID_VERSION , replace_module_line ,
332
+ line )
333
+ output_lines .append (substituted_line )
334
+ if substituted_line != line :
335
+ substituted_pairs .append ((line , substituted_line ))
336
+ to_update = True
337
+
338
+ if to_update :
339
+ print ('Updating contents of {0}' .format (readme_filepath ))
340
+ for original , substituted in substituted_pairs :
341
+ print ('(-) ' + original + '(+) ' + substituted )
342
+
343
+ if not dryrun :
344
+ with open (readme_filepath , 'w' ) as readme_file :
345
+ readme_file .writelines (output_lines )
346
+ print ()
347
+
291
348
########## END: iOS pods versions update #####################################
292
349
293
350
########## Android versions update #############################
@@ -483,12 +540,17 @@ def parse_cmdline_args():
483
540
484
541
def main ():
485
542
args = parse_cmdline_args ()
543
+ # Readme files have to be updated for both android and iOS dependencies.
544
+ readme_files = get_files (args .readmefiles , file_extension = '.md' ,
545
+ file_name = 'readme' )
486
546
if not args .skip_ios :
487
547
#latest_pod_versions_map = get_latest_pod_versions(args.specs_repo, PODS)
488
548
latest_pod_versions_map = {'FirebaseAuth' : '8.0.0' , 'FirebaseRemoteConfig' :'9.9.9' }
489
549
pod_files = get_files (args .podfiles , file_extension = '' , file_name = 'Podfile' )
490
550
for pod_file in pod_files :
491
551
modify_pod_file (pod_file , latest_pod_versions_map , args .dryrun )
552
+ for readme_file in readme_files :
553
+ modify_readme_file_pods (readme_file , latest_pod_versions_map , args .dryrun )
492
554
493
555
if not args .skip_android :
494
556
#latest_android_versions_map = get_latest_maven_versions()
@@ -502,10 +564,8 @@ def main():
502
564
for dep_file in dep_files :
503
565
modify_dependency_file (dep_file , latest_android_versions_map , args .dryrun )
504
566
505
- readme_files = get_files (args .readmefiles , file_extension = '.md' ,
506
- file_name = 'readme' )
507
567
for readme_file in readme_files :
508
- modify_readme_file (readme_file , latest_android_versions_map , args .dryrun )
568
+ modify_readme_file_android (readme_file , latest_android_versions_map , args .dryrun )
509
569
510
570
511
571
if __name__ == '__main__' :
0 commit comments