Skip to content

Commit

Permalink
Add tools/maint/create_release.py. NFC (#17876)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 authored Sep 19, 2022
1 parent 06951ff commit c7416fd
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 3 deletions.
7 changes: 4 additions & 3 deletions docs/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ How:
1. [Tag][emscripten_tags] the `emscripten` repo with the new version number, on
the commit referred to in the [DEPS][DEPS] (or DEPS.tagged-release) file
above.
1. Update [`emscripten-version.txt`][emscripten_version] and
[`ChangeLog.md`][changelog] in the emscripten repo to refer the next,
upcoming, version. An example of this PR is emscripten-core/emscripten#17439.
1. Run the `tools/maint/create_release.py` tool in the emscripten repo to update
[`emscripten-version.txt`][emscripten_version] and
[`ChangeLog.md`][changelog]. An example of such PR is
emscripten-core/emscripten#17439.

Major version update (1.X.Y to 1.(X+1).0)
-----------------------------------------
Expand Down
75 changes: 75 additions & 0 deletions tools/maint/create_release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env python3
# Copyright 2022 The Emscripten Authors. All rights reserved.
# Emscripten is available under two separate licenses, the MIT license and the
# University of Illinois/NCSA Open Source License. Both these licenses can be
# found in the LICENSE file.

from datetime import datetime
import os
import subprocess
import sys

script_dir = os.path.dirname(os.path.abspath(__file__))
root_dir = os.path.dirname(os.path.dirname(script_dir))

sys.path.append(root_dir)
from tools import shared, utils


def main():
if subprocess.check_output(['git', 'status', '-uno', '--porcelain'], cwd=root_dir).strip():
print('tree is not clean')
return 1

shared.set_version_globals()

old_version = [shared.EMSCRIPTEN_VERSION_MAJOR, shared.EMSCRIPTEN_VERSION_MINOR,
shared.EMSCRIPTEN_VERSION_TINY]
new_version = list(old_version)
new_version[2] += 1

old_version = '.'.join(str(v) for v in old_version)
new_version = '.'.join(str(v) for v in new_version)

print('Creating new release: %s' % new_version)

version_file = os.path.join(root_dir, 'emscripten-version.txt')
changelog_file = os.path.join(root_dir, 'ChangeLog.md')

old_content = utils.read_file(version_file)
utils.write_file(version_file, old_content.replace(old_version, new_version))

changelog = utils.read_file(changelog_file)
marker = f'{old_version} (in development)'
pos = changelog.find(marker)
assert pos != -1
pos += 2 * len(marker) + 1

# Add new entry
today = datetime.now().strftime('%m/%d/%y')
new_entry = f'{old_version} - {today}'
new_entry = '\n\n' + new_entry + '\n' + ('-' * len(new_entry))
changelog = changelog[:pos] + new_entry + changelog[pos:]

# Update the "in development" entry
changelog = changelog.replace(f'{old_version} (in development)', f'{new_version} (in development)')

utils.write_file(changelog_file, changelog)

branch_name = 'version_' + new_version

# Create a new git branch
subprocess.check_call(['git', 'checkout', '-b', branch_name], cwd=root_dir)

# Create auto-generated changes to the new git branch
subprocess.check_call(['git', 'add', '-u', '.'], cwd=root_dir)
subprocess.check_call(['git', 'commit', '-m', new_version], cwd=root_dir)

print('New relase created in branch: `%s`' % branch_name)

# TODO(sbc): Maybe create the tag too, and even push both to `origin`?
return 0


if __name__ == '__main__':
sys.exit(main())

0 comments on commit c7416fd

Please sign in to comment.