Skip to content

Commit

Permalink
Textually replace CodeQL version in package.json (#2269)
Browse files Browse the repository at this point in the history
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 <henrymercer@github.com>
  • Loading branch information
angelapwen and henrymercer committed May 1, 2024
1 parent 8fcfedf commit 41857ba
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions .github/update-release-branch.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import argparse
import datetime
import fileinput
import re
from github import Github
import json
Expand Down Expand Up @@ -171,6 +172,19 @@ def get_current_version():
with open('package.json', 'r') as f:
return json.load(f)['version']

# `npm version` doesn't always work because of merge conflicts, so we
# replace the version in package.json textually.
def replace_version_package_json(prev_version, new_version):
prev_line_is_codeql = False
for line in fileinput.input('package.json', inplace = True, encoding='utf-8'):
if prev_line_is_codeql and f'\"version\": \"{prev_version}\"' in line:
print(line.replace(prev_version, new_version), end='')
else:
prev_line_is_codeql = False
print(line, end='')
if '\"name\": \"codeql\",' in line:
prev_line_is_codeql = True

def get_today_string():
today = datetime.datetime.today()
return '{:%d %b %Y}'.format(today)
Expand Down Expand Up @@ -374,9 +388,9 @@ def main():
run_git('commit', '--no-edit')

# Migrate the package version number from a vLatest version number to a vOlder version number
print(f'Setting version number to {version}')
subprocess.check_output(['npm', 'version', version, '--no-git-tag-version'])
run_git('add', 'package.json', 'package-lock.json')
print(f'Setting version number to {version} in package.json')
replace_version_package_json(get_current_version(), version) # We rely on the `Update dependencies` workflow to update package-lock.json
run_git('add', 'package.json')

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

0 comments on commit 41857ba

Please sign in to comment.