export_release_notes.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #!/usr/bin/env python3
  2. # Copyright 2025 Google LLC
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. """Creates release notes files."""
  16. import argparse
  17. import os
  18. import subprocess
  19. import sys
  20. def main():
  21. changelog_location = find_changelog_location()
  22. parser = argparse.ArgumentParser(description='Create release notes files.')
  23. parser.add_argument(
  24. '--version', '-v', required=True, help='Specify the release number.'
  25. )
  26. parser.add_argument('--date', help='Specify the date.')
  27. parser.add_argument(
  28. '--repo',
  29. '-r',
  30. required=True,
  31. help='The absolute path to the root of the repo containing changelogs.',
  32. )
  33. parser.add_argument(
  34. 'products',
  35. help=(
  36. 'The products to create changelogs for, separated by a comma (no'
  37. ' space).'
  38. ),
  39. )
  40. args = parser.parse_args()
  41. # Check all inputs are valid product names
  42. products = args.products.split(',')
  43. product_paths = product_relative_locations()
  44. for i, product in enumerate(products):
  45. if product_paths[product] is None:
  46. print('Unknown product ' + product, file=sys.stderr)
  47. sys.exit(-1)
  48. created_files = []
  49. repo = args.repo
  50. for i, product in enumerate(products):
  51. changelog = ''
  52. if product == 'Firestore' or product == 'Crashlytics':
  53. changelog = product + '/CHANGELOG.md'
  54. else:
  55. changelog = 'Firebase' + product + '/CHANGELOG.md'
  56. result = subprocess.run(
  57. [
  58. 'python3',
  59. 'scripts/make_release_notes.py',
  60. changelog,
  61. '-r',
  62. 'firebase/firebase-ios-sdk',
  63. ],
  64. cwd=repo,
  65. capture_output=True,
  66. text=True,
  67. check=True,
  68. )
  69. generated_note = result.stdout
  70. target_path = (
  71. changelog_location
  72. + product_paths[product]
  73. + '-m'
  74. + args.version
  75. + '.md'
  76. )
  77. with open(target_path, 'w') as file:
  78. file.write(generated_note)
  79. created_files.append(target_path)
  80. output = '\n'.join(created_files)
  81. print(output)
  82. def find_changelog_location():
  83. wd = os.getcwd()
  84. google3_index = wd.rfind('google3')
  85. if google3_index == -1:
  86. print('This script must be invoked from a SrcFS volume', file=sys.stderr)
  87. sys.exit(-1)
  88. google3_root = wd[: google3_index + len('google3')]
  89. changelog_relative = (
  90. '/third_party/devsite/firebase/en/docs/ios/_ios-release-notes/'
  91. )
  92. changelog_absolute = google3_root + changelog_relative
  93. return changelog_absolute
  94. def product_relative_locations():
  95. module_names = [
  96. 'ABTesting',
  97. 'AI',
  98. # Note: Analytics is generated separately.
  99. 'AppCheck',
  100. 'Auth',
  101. 'Core',
  102. 'Crashlytics',
  103. 'Database',
  104. 'Firestore',
  105. 'Functions',
  106. 'Installations',
  107. 'Messaging',
  108. 'Storage',
  109. 'RemoteConfig',
  110. # Note: Data Connect must be generated manually.
  111. ]
  112. # Most products follow the format Product/_product(-version.md)
  113. relative_paths = {}
  114. for index, name in enumerate(module_names):
  115. path = name + '/_' + name.lower()
  116. relative_paths[name] = path
  117. # There are a few exceptions
  118. relative_paths['AppDistribution'] = 'AppDistribution/_appdist'
  119. relative_paths['InAppMessaging'] = 'InAppMessaging/_fiam'
  120. relative_paths['Performance'] = 'Performance/_perf'
  121. return relative_paths
  122. if __name__ == '__main__':
  123. main()