Skip to content

Commit 991cdba

Browse files
committed
update cocoapod versions in readme
1 parent 3e210f2 commit 991cdba

File tree

1 file changed

+63
-3
lines changed

1 file changed

+63
-3
lines changed

scripts/update_ios_android_dependencies.py

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,63 @@ def modify_pod_file(pod_file, pod_version_map, dryrun=True):
288288
podfile.writelines(existing_lines)
289289
print()
290290

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+
291348
########## END: iOS pods versions update #####################################
292349

293350
########## Android versions update #############################
@@ -483,12 +540,17 @@ def parse_cmdline_args():
483540

484541
def main():
485542
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')
486546
if not args.skip_ios:
487547
#latest_pod_versions_map = get_latest_pod_versions(args.specs_repo, PODS)
488548
latest_pod_versions_map = {'FirebaseAuth': '8.0.0', 'FirebaseRemoteConfig':'9.9.9'}
489549
pod_files = get_files(args.podfiles, file_extension='', file_name='Podfile')
490550
for pod_file in pod_files:
491551
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)
492554

493555
if not args.skip_android:
494556
#latest_android_versions_map = get_latest_maven_versions()
@@ -502,10 +564,8 @@ def main():
502564
for dep_file in dep_files:
503565
modify_dependency_file(dep_file, latest_android_versions_map, args.dryrun)
504566

505-
readme_files = get_files(args.readmefiles, file_extension='.md',
506-
file_name='readme')
507567
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)
509569

510570

511571
if __name__ == '__main__':

0 commit comments

Comments
 (0)