|
1 | 1 | import argparse
|
2 | 2 | import datetime
|
| 3 | +import fileinput |
3 | 4 | import re
|
4 | 5 | from github import Github
|
5 | 6 | import json
|
@@ -171,6 +172,19 @@ def get_current_version():
|
171 | 172 | with open('package.json', 'r') as f:
|
172 | 173 | return json.load(f)['version']
|
173 | 174 |
|
| 175 | +# `npm version` doesn't always work because of merge conflicts, so we |
| 176 | +# replace the version in package.json textually. |
| 177 | +def replace_version_package_json(prev_version, new_version): |
| 178 | + prev_line_is_codeql = False |
| 179 | + for line in fileinput.input('package.json', inplace = True, encoding='utf-8'): |
| 180 | + if prev_line_is_codeql and f'\"version\": \"{prev_version}\"' in line: |
| 181 | + print(line.replace(prev_version, new_version), end='') |
| 182 | + else: |
| 183 | + prev_line_is_codeql = False |
| 184 | + print(line, end='') |
| 185 | + if '\"name\": \"codeql\",' in line: |
| 186 | + prev_line_is_codeql = True |
| 187 | + |
174 | 188 | def get_today_string():
|
175 | 189 | today = datetime.datetime.today()
|
176 | 190 | return '{:%d %b %Y}'.format(today)
|
@@ -374,9 +388,9 @@ def main():
|
374 | 388 | run_git('commit', '--no-edit')
|
375 | 389 |
|
376 | 390 | # Migrate the package version number from a vLatest version number to a vOlder version number
|
377 |
| - print(f'Setting version number to {version}') |
378 |
| - subprocess.check_output(['npm', 'version', version, '--no-git-tag-version']) |
379 |
| - run_git('add', 'package.json', 'package-lock.json') |
| 391 | + print(f'Setting version number to {version} in package.json') |
| 392 | + replace_version_package_json(get_current_version(), version) # We rely on the `Update dependencies` workflow to update package-lock.json |
| 393 | + run_git('add', 'package.json') |
380 | 394 |
|
381 | 395 | # Migrate the changelog notes from vLatest version numbers to vOlder version numbers
|
382 | 396 | print(f'Migrating changelog notes from v{source_branch_major_version} to v{target_branch_major_version}')
|
|
0 commit comments