improve handling of changelog processing for backports
This commit is contained in:
parent
511f073971
commit
8e4a6c7a90
1 changed files with 53 additions and 5 deletions
58
.github/update-release-branch.py
vendored
58
.github/update-release-branch.py
vendored
|
|
@ -1,5 +1,6 @@
|
|||
import argparse
|
||||
import datetime
|
||||
import re
|
||||
from github import Github
|
||||
import json
|
||||
import os
|
||||
|
|
@ -174,6 +175,56 @@ def get_today_string():
|
|||
today = datetime.datetime.today()
|
||||
return '{:%d %b %Y}'.format(today)
|
||||
|
||||
def process_changelog_for_backports(target_version):
|
||||
|
||||
# changelog entries use a speficic format to indicate
|
||||
# that they only apply to newer versions
|
||||
regex = re.compile(r'\[v(\d+)\+ only\]')
|
||||
|
||||
output = ''
|
||||
|
||||
with open('CHANGELOG.md', 'r') as f:
|
||||
|
||||
# until we find the first section, just duplicate all lines
|
||||
while True:
|
||||
line = f.readline().rstrip()
|
||||
|
||||
output += line + '\n'
|
||||
if line.startswith('## '):
|
||||
# we have found the first section, so now handle things differently
|
||||
break
|
||||
|
||||
# found_content tracks whether we hit two headings in a row
|
||||
found_content = False
|
||||
output += '\n'
|
||||
while True:
|
||||
line = f.readline()
|
||||
if not line:
|
||||
break # EOF
|
||||
line = line.rstrip()
|
||||
|
||||
# filter out changenote entries that apply only to newer versions
|
||||
match = regex.search(line)
|
||||
if match:
|
||||
if int(target_version) < int(match.group(1)):
|
||||
continue
|
||||
|
||||
if line.startswith('## '):
|
||||
if found_content == False:
|
||||
# we have found two headings in a row, so we need to add the placeholder message.
|
||||
output += 'No user facing changes.\n'
|
||||
found_content = False
|
||||
output += '\n' +line + '\n\n'
|
||||
else:
|
||||
if line.strip() != '':
|
||||
found_content = True
|
||||
# we use the original line here, rather than the stripped version
|
||||
# so that we preserve indentation
|
||||
output += line + '\n'
|
||||
|
||||
with open('CHANGELOG.md', 'w') as f:
|
||||
f.write(output)
|
||||
|
||||
def update_changelog(version):
|
||||
if (os.path.exists('CHANGELOG.md')):
|
||||
content = ''
|
||||
|
|
@ -326,11 +377,8 @@ def main():
|
|||
print(f'Migrating changelog notes from v{source_branch_major_version} to v{target_branch_major_version}')
|
||||
subprocess.check_output(['sed', '-i', f's/^## {source_branch_major_version}\./## {target_branch_major_version}./g', 'CHANGELOG.md'])
|
||||
|
||||
# Remove changelog notes from all versions that do not apply to the vOlder branch
|
||||
print(f'Removing changelog notes that do not apply to v{target_branch_major_version}')
|
||||
for v in range(int(source_branch_major_version), int(target_branch_major_version), -1):
|
||||
print(f'Removing changelog notes that are tagged [v{v}+ only\]')
|
||||
subprocess.check_output(['sed', '-i', f'/^- \[v{v}+ only\]/d', 'CHANGELOG.md'])
|
||||
# process changelog for backport to target release branch
|
||||
process_changelog_for_backports(target_branch_major_version)
|
||||
|
||||
# Amend the commit generated by `npm version` to update the CHANGELOG
|
||||
run_git('add', 'CHANGELOG.md')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue