|
| 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