Skip to content

Commit 1f00f5d

Browse files
authored
Allow overriding version number in create_release.py (#1512)
This changes the CLI syntax for create_relase.py to be more compatible with argparse, but we don't run it often manually anyway.
1 parent 0e594bc commit 1f00f5d

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

.github/workflows/create-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Checkout repo
1818
uses: actions/checkout@v4
1919
- name: Run create_release.py
20-
run: python3 scripts/create_release.py ${{ inputs.lto-sha }} ${{ inputs.nonlto-sha }} --action
20+
run: python3 scripts/create_release.py -r ${{ inputs.lto-sha }} -a ${{ inputs.nonlto-sha }} --gh-action
2121
- name: Create PR
2222
id: cpr
2323
uses: peter-evans/create-pull-request@v6

scripts/create_release.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
22

3+
import argparse
34
import json
45
import os
56
import re
@@ -20,26 +21,33 @@ def version_key(version_string):
2021
return key
2122

2223

23-
def main(args):
24+
def main():
2425
if subprocess.check_output(['git', 'status', '--porcelain'], cwd=root_dir).strip():
2526
print('tree is not clean')
2627
sys.exit(1)
2728

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+
2836
release_info = emsdk.load_releases_info()
29-
new_version = version_key(release_info['aliases']['latest'])[0]
30-
new_version[-1] += 1
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)
3143

32-
new_version = '.'.join(str(part) for part in new_version)
3344
asserts_hash = None
34-
is_github_runner = False
35-
if args:
36-
new_hash = args[0]
37-
if len(args) > 1:
38-
asserts_hash = args[1]
39-
if len(args) > 2 and args[2] == '--action':
40-
is_github_runner = True
45+
if options.release_hash:
46+
new_hash = options.release_hash
47+
asserts_hash = options.asserts_hash
4148
else:
4249
new_hash = emsdk.get_emscripten_releases_tot()
50+
4351
print('Creating new release: %s -> %s' % (new_version, new_hash))
4452
release_info['releases'][new_version] = new_hash
4553
if asserts_hash:
@@ -62,7 +70,7 @@ def main(args):
6270

6371
branch_name = 'version_' + new_version
6472

65-
if is_github_runner: # For GitHub Actions workflows
73+
if options.gh_action: # For GitHub Actions workflows
6674
with open(os.environ['GITHUB_ENV'], 'a') as f:
6775
f.write(f'RELEASE_VERSION={new_version}')
6876
else: # Local use
@@ -81,4 +89,4 @@ def main(args):
8189

8290

8391
if __name__ == '__main__':
84-
sys.exit(main(sys.argv[1:]))
92+
sys.exit(main())

0 commit comments

Comments
 (0)