Path: blob/main/tools/maint/create_release.py
4150 views
#!/usr/bin/env python31# Copyright 2022 The Emscripten Authors. All rights reserved.2# Emscripten is available under two separate licenses, the MIT license and the3# University of Illinois/NCSA Open Source License. Both these licenses can be4# found in the LICENSE file.56from datetime import datetime7import os8import subprocess9import sys1011script_dir = os.path.dirname(os.path.abspath(__file__))12root_dir = os.path.dirname(os.path.dirname(script_dir))1314sys.path.insert(0, root_dir)15from tools import utils161718def update_version_txt(release_version, new_version):19version_file = os.path.join(root_dir, 'emscripten-version.txt')20old_content = utils.read_file(version_file)21utils.write_file(version_file, old_content.replace(release_version, new_version))222324def update_changelog(release_version, new_version):25changelog_file = os.path.join(root_dir, 'ChangeLog.md')26changelog = utils.read_file(changelog_file)27marker = f'{release_version} (in development)'28pos = changelog.find(marker)29assert pos != -130pos += len(marker) + 131# Skip the next line which should just be hyphens32assert changelog[pos] == '-'33pos = changelog.find('\n', pos)34assert pos != -13536# Add new entry37today = datetime.now().strftime('%m/%d/%y')38new_entry = f'{release_version} - {today}'39new_entry = '\n\n' + new_entry + '\n' + ('-' * len(new_entry))40changelog = changelog[:pos] + new_entry + changelog[pos:]4142# Update the "in development" entry43changelog = changelog.replace(f'{release_version} (in development)', f'{new_version} (in development)')4445utils.write_file(changelog_file, changelog)464748def create_git_branch(release_version):49branch_name = 'version_' + release_version5051# Create a new git branch52subprocess.check_call(['git', 'checkout', '-b', branch_name, 'upstream/main'], cwd=root_dir)5354# Create auto-generated changes to the new git branch55subprocess.check_call(['git', 'add', '-u', '.'], cwd=root_dir)56subprocess.check_call(['git', 'commit', '-m', f'Mark {release_version} as released'], cwd=root_dir)57print('New release created in branch: `%s`' % branch_name)5859if '-n' not in sys.argv:60# Push new branch to upstream61subprocess.check_call(['git', 'push', 'upstream', branch_name], cwd=root_dir)626364def main(argv):65if subprocess.check_output(['git', 'status', '-uno', '--porcelain'], cwd=root_dir).strip():66print('tree is not clean')67return 16869is_github_runner = len(argv) > 1 and argv[1] == '--action'7071utils.set_version_globals()7273release_version = [utils.EMSCRIPTEN_VERSION_MAJOR, utils.EMSCRIPTEN_VERSION_MINOR,74utils.EMSCRIPTEN_VERSION_TINY]75new_dev_version = list(release_version)76new_dev_version[2] += 17778release_version = '.'.join(str(v) for v in release_version)79new_dev_version = '.'.join(str(v) for v in new_dev_version)8081update_version_txt(release_version, new_dev_version)82update_changelog(release_version, new_dev_version)8384print('Creating new release: %s' % release_version)8586if is_github_runner: # For GitHub Actions workflows87with open(os.environ['GITHUB_ENV'], 'a') as f:88f.write(f'RELEASE_VERSION={release_version}')89else: # Local use90create_git_branch(release_version)91# TODO(sbc): Maybe create the tag too9293return 0949596if __name__ == '__main__':97sys.exit(main(sys.argv))9899100