Skip to content

Commit c7416fd

Browse files
authored
Add tools/maint/create_release.py. NFC (#17876)
1 parent 06951ff commit c7416fd

File tree

2 files changed

+79
-3
lines changed

2 files changed

+79
-3
lines changed

docs/process.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ How:
8585
1. [Tag][emscripten_tags] the `emscripten` repo with the new version number, on
8686
the commit referred to in the [DEPS][DEPS] (or DEPS.tagged-release) file
8787
above.
88-
1. Update [`emscripten-version.txt`][emscripten_version] and
89-
[`ChangeLog.md`][changelog] in the emscripten repo to refer the next,
90-
upcoming, version. An example of this PR is emscripten-core/emscripten#17439.
88+
1. Run the `tools/maint/create_release.py` tool in the emscripten repo to update
89+
[`emscripten-version.txt`][emscripten_version] and
90+
[`ChangeLog.md`][changelog]. An example of such PR is
91+
emscripten-core/emscripten#17439.
9192

9293
Major version update (1.X.Y to 1.(X+1).0)
9394
-----------------------------------------

tools/maint/create_release.py

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#!/usr/bin/env python3
2+
# Copyright 2022 The Emscripten Authors. All rights reserved.
3+
# Emscripten is available under two separate licenses, the MIT license and the
4+
# University of Illinois/NCSA Open Source License. Both these licenses can be
5+
# found in the LICENSE file.
6+
7+
from datetime import datetime
8+
import os
9+
import subprocess
10+
import sys
11+
12+
script_dir = os.path.dirname(os.path.abspath(__file__))
13+
root_dir = os.path.dirname(os.path.dirname(script_dir))
14+
15+
sys.path.append(root_dir)
16+
from tools import shared, utils
17+
18+
19+
def main():
20+
if subprocess.check_output(['git', 'status', '-uno', '--porcelain'], cwd=root_dir).strip():
21+
print('tree is not clean')
22+
return 1
23+
24+
shared.set_version_globals()
25+
26+
old_version = [shared.EMSCRIPTEN_VERSION_MAJOR, shared.EMSCRIPTEN_VERSION_MINOR,
27+
shared.EMSCRIPTEN_VERSION_TINY]
28+
new_version = list(old_version)
29+
new_version[2] += 1
30+
31+
old_version = '.'.join(str(v) for v in old_version)
32+
new_version = '.'.join(str(v) for v in new_version)
33+
34+
print('Creating new release: %s' % new_version)
35+
36+
version_file = os.path.join(root_dir, 'emscripten-version.txt')
37+
changelog_file = os.path.join(root_dir, 'ChangeLog.md')
38+
39+
old_content = utils.read_file(version_file)
40+
utils.write_file(version_file, old_content.replace(old_version, new_version))
41+
42+
changelog = utils.read_file(changelog_file)
43+
marker = f'{old_version} (in development)'
44+
pos = changelog.find(marker)
45+
assert pos != -1
46+
pos += 2 * len(marker) + 1
47+
48+
# Add new entry
49+
today = datetime.now().strftime('%m/%d/%y')
50+
new_entry = f'{old_version} - {today}'
51+
new_entry = '\n\n' + new_entry + '\n' + ('-' * len(new_entry))
52+
changelog = changelog[:pos] + new_entry + changelog[pos:]
53+
54+
# Update the "in development" entry
55+
changelog = changelog.replace(f'{old_version} (in development)', f'{new_version} (in development)')
56+
57+
utils.write_file(changelog_file, changelog)
58+
59+
branch_name = 'version_' + new_version
60+
61+
# Create a new git branch
62+
subprocess.check_call(['git', 'checkout', '-b', branch_name], cwd=root_dir)
63+
64+
# Create auto-generated changes to the new git branch
65+
subprocess.check_call(['git', 'add', '-u', '.'], cwd=root_dir)
66+
subprocess.check_call(['git', 'commit', '-m', new_version], cwd=root_dir)
67+
68+
print('New relase created in branch: `%s`' % branch_name)
69+
70+
# TODO(sbc): Maybe create the tag too, and even push both to `origin`?
71+
return 0
72+
73+
74+
if __name__ == '__main__':
75+
sys.exit(main())

0 commit comments

Comments
 (0)