Mercurial
comparison third_party/emsdk/scripts/create_release.py @ 179:8d17f6e6e290
[ThirdParty] Added emsdk bazel rules that can be supported by bazel 9.0.0
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Thu, 22 Jan 2026 21:23:17 -0800 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 178:94705b5986b3 | 179:8d17f6e6e290 |
|---|---|
| 1 #!/usr/bin/env python3 | |
| 2 | |
| 3 import argparse | |
| 4 import json | |
| 5 import os | |
| 6 import re | |
| 7 import subprocess | |
| 8 import sys | |
| 9 from collections import OrderedDict | |
| 10 | |
| 11 script_dir = os.path.dirname(os.path.abspath(__file__)) | |
| 12 root_dir = os.path.dirname(script_dir) | |
| 13 sys.path.append(root_dir) | |
| 14 | |
| 15 import emsdk # noqa | |
| 16 | |
| 17 | |
| 18 def version_key(version_string): | |
| 19 parts = re.split('[.-]', version_string) | |
| 20 key = [[int(part) for part in parts[:3]], -len(parts), parts[3:]] | |
| 21 return key | |
| 22 | |
| 23 | |
| 24 def main(): | |
| 25 if subprocess.check_output(['git', 'status', '--porcelain'], cwd=root_dir).strip(): | |
| 26 print('tree is not clean') | |
| 27 sys.exit(1) | |
| 28 | |
| 29 parser = argparse.ArgumentParser() | |
| 30 parser.add_argument('-r', '--release-hash') | |
| 31 parser.add_argument('-a', '--asserts-hash') | |
| 32 parser.add_argument('-v', '--new-version') | |
| 33 parser.add_argument('--gh-action', action='store_true') | |
| 34 options = parser.parse_args() | |
| 35 | |
| 36 release_info = emsdk.load_releases_info() | |
| 37 if options.new_version: | |
| 38 new_version = options.new_version | |
| 39 else: | |
| 40 new_version = version_key(release_info['aliases']['latest'])[0] | |
| 41 new_version[-1] += 1 | |
| 42 new_version = '.'.join(str(part) for part in new_version) | |
| 43 | |
| 44 asserts_hash = None | |
| 45 if options.release_hash: | |
| 46 new_hash = options.release_hash | |
| 47 asserts_hash = options.asserts_hash | |
| 48 else: | |
| 49 new_hash = emsdk.get_emscripten_releases_tot() | |
| 50 | |
| 51 print('Creating new release: %s -> %s' % (new_version, new_hash)) | |
| 52 release_info['releases'][new_version] = new_hash | |
| 53 if asserts_hash: | |
| 54 asserts_name = new_version + '-asserts' | |
| 55 release_info['releases'][asserts_name] = asserts_hash | |
| 56 | |
| 57 releases = [(k, v) for k, v in release_info['releases'].items()] | |
| 58 releases.sort(key=lambda pair: version_key(pair[0])) | |
| 59 | |
| 60 release_info['releases'] = OrderedDict(reversed(releases)) | |
| 61 release_info['aliases']['latest'] = new_version | |
| 62 | |
| 63 with open(os.path.join(root_dir, 'emscripten-releases-tags.json'), 'w') as f: | |
| 64 f.write(json.dumps(release_info, indent=2)) | |
| 65 f.write('\n') | |
| 66 | |
| 67 subprocess.check_call( | |
| 68 [sys.executable, os.path.join(script_dir, 'update_bazel_workspace.py')], | |
| 69 cwd=root_dir) | |
| 70 | |
| 71 branch_name = 'version_' + new_version | |
| 72 | |
| 73 if options.gh_action: # For GitHub Actions workflows | |
| 74 with open(os.environ['GITHUB_ENV'], 'a') as f: | |
| 75 f.write(f'RELEASE_VERSION={new_version}') | |
| 76 else: # Local use | |
| 77 # Create a new git branch | |
| 78 subprocess.check_call(['git', 'checkout', '-b', branch_name, 'origin/main'], cwd=root_dir) | |
| 79 | |
| 80 # Create auto-generated changes to the new git branch | |
| 81 subprocess.check_call(['git', 'add', '-u', '.'], cwd=root_dir) | |
| 82 subprocess.check_call(['git', 'commit', '-m', new_version], cwd=root_dir) | |
| 83 print('New release created in branch: `%s`' % branch_name) | |
| 84 | |
| 85 # Push new branch to origin | |
| 86 subprocess.check_call(['git', 'push', 'origin', branch_name], cwd=root_dir) | |
| 87 | |
| 88 return 0 | |
| 89 | |
| 90 | |
| 91 if __name__ == '__main__': | |
| 92 sys.exit(main()) |