Skip to content

Commit 41857ba

Browse files
Textually replace CodeQL version in package.json (#2269)
Textually replace CodeQL version in `package.json` instead of using `npm version`, which occasionally fails due to merge conflicts that arise in the `package.json` process. Co-authored-by: Henry Mercer <[email protected]>
1 parent 8fcfedf commit 41857ba

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

.github/update-release-branch.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import argparse
22
import datetime
3+
import fileinput
34
import re
45
from github import Github
56
import json
@@ -171,6 +172,19 @@ def get_current_version():
171172
with open('package.json', 'r') as f:
172173
return json.load(f)['version']
173174

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+
174188
def get_today_string():
175189
today = datetime.datetime.today()
176190
return '{:%d %b %Y}'.format(today)
@@ -374,9 +388,9 @@ def main():
374388
run_git('commit', '--no-edit')
375389

376390
# 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')
380394

381395
# Migrate the changelog notes from vLatest version numbers to vOlder version numbers
382396
print(f'Migrating changelog notes from v{source_branch_major_version} to v{target_branch_major_version}')

0 commit comments

Comments
 (0)