Skip to content

Commit dfe4fa0

Browse files
committed
Fix: Skip new ser-ver-id for --release option (custom-release)
1 parent f623de6 commit dfe4fa0

File tree

2 files changed

+97
-92
lines changed

2 files changed

+97
-92
lines changed

script/CUSTOM_RELEASE_README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# README - OTP Custom/Fork Release Scripts
22

3-
**Note! This describes how you can set up and release OTP in your own GitHub fork, not how OTP in the
4-
main repo is released.**
3+
**Note! This describes how you can set up and release OTP in your own GitHub fork, not how OTP in
4+
the main repo is released.**
55

66

77
## Introduction
@@ -24,22 +24,22 @@ The release is made in the `release branch` in the forked git repository. The re
2424
based on the `base revision` - a branch, tag or commit, for example `otp/dev-2.x`.
2525

2626
1. The release script will start by _resetting_ the `release branch` to the given `base revision`.
27-
**Nothing is kept from previous releases.**
27+
**Nothing is kept from previous releases.**
2828
2. Then all pending PRs tagged with your `TEST` label is meged in. The name of the label is
29-
configured in the `custom-release-env.json` file.
29+
configured in the `custom-release-env.json` file.
3030
3. Then all your extension branches are meged in. These are normally branchech with your deployment
31-
config and GitHub workflow files. The name of these branches is configured in the
32-
`custom-release-env.json` file.
31+
config and GitHub workflow files. The name of these branches is configured in the
32+
`custom-release-env.json` file.
3333
4. The `custom-release-extension` script is run, if it exist. For example you may delete
34-
workflow scripts comming from the upstream `base revision`.
34+
workflow scripts comming from the upstream `base revision`.
3535
5. The old release is then merged with an _empty merge_, this is done to create a continuous line
36-
of releases in the release branch for easy viewing and navigation of the git history. Nothing
37-
from the previous release is copied into the new release. We call this an _empty merge_.
38-
6. Then the script update the _otp-serialization-version-id_ and OTP _version_. Each release is
39-
given a unique version number specific to your fork, like `v2.7.0-MY_ORG-1`. The release script
40-
uses both the git history and the GitHub GraphQL API (PRs labeled `bump serialization id`) to
41-
resolve the versions numbers.
42-
7. The script finally push the release.
36+
of releases in the release branch for easy viewing and navigation of the git history. Nothing
37+
from the previous release is copied into the new release. We call this an _empty merge_.
38+
6. Then the script update the _otp-serialization-version-id_ and the OTP _version_ in the pom.xml
39+
file. Each release is given a unique version number specific to your fork, like
40+
`v2.7.0-MY_ORG-1`. The release script uses both the git history and the GitHub GraphQL API
41+
(PRs labeled `bump serialization id`) to resolve the serialization version number.
42+
7. The script finally tag and push the release.
4343

4444
Do not worry about deleting more recent versions, the release script will preserve the history so
4545
nothing is lost.

script/custom-release.py

Lines changed: 83 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -86,28 +86,28 @@ def __str__(self):
8686
class ScriptState:
8787

8888
def __init__(self):
89-
self.current_ser_ver_id = None
90-
self.new_ser_ver_id = None
89+
self.latest_ser_ver_id = None
90+
self.next_ser_ver_id = None
9191
self.major_version = None
92-
self.current_version = None
93-
self.new_version = None
92+
self.latest_version = None
93+
self.next_version = None
9494
self.pr_labels = {}
9595
self.pr_titles = {}
9696
self.prs_bump_ser_ver_id = False
9797
self.gotoStep = False
9898
self.step = None
9999

100-
def new_version_tag(self):
101-
return f'v{self.new_version}'
100+
def next_version_tag(self):
101+
return f'v{self.next_version}'
102102

103-
def curr_version_tag(self):
104-
return f'v{self.current_version}'
103+
def latest_version_tag(self):
104+
return f'v{self.latest_version}'
105105

106-
def new_version_description(self):
107-
return f'Version {self.new_version} ({self.new_ser_ver_id})'
106+
def next_version_description(self):
107+
return f'Version {self.next_version} ({self.next_ser_ver_id})'
108108

109-
def is_ser_ver_id_new(self):
110-
return self.new_ser_ver_id != self.current_ser_ver_id
109+
def is_ser_ver_id_next(self):
110+
return self.next_ser_ver_id != self.latest_ser_ver_id
111111

112112
def run(self, step):
113113
if not self.gotoStep:
@@ -158,7 +158,7 @@ def main():
158158
set_maven_pom_version()
159159
set_ser_ver_id()
160160
run_maven_test()
161-
commit_new_versions()
161+
commit_next_versions()
162162
tag_release()
163163
push_release_branch_and_tag()
164164
print_summary()
@@ -182,9 +182,9 @@ def setup_and_verify():
182182
verify_release_base_and_release_branch_exist()
183183
verify_no_local_git_changes()
184184
resolve_version_number()
185-
resolve_new_version()
185+
resolve_next_version()
186186
list_labeled_prs()
187-
resolve_new_ser_ver_id()
187+
resolve_next_ser_ver_id()
188188
print_setup()
189189

190190

@@ -222,7 +222,7 @@ def merge_in_ext_branches():
222222
info(f'Config branch merged: {config.release_path(branch)}')
223223

224224

225-
# Merge the old version into the new version. This only keep a reference to the old version, the
225+
# Merge the old version into the next version. This only keep a reference to the old version, the
226226
# resulting git tree of the merge is that of the new branch head, effectively ignoring all changes
227227
# from the old release. This creates a continuous line of releases in the release branch.
228228
def merge_in_old_release_with_no_changes():
@@ -243,41 +243,41 @@ def run_custom_release_extensions():
243243

244244
def set_maven_pom_version():
245245
section('Set Maven project version ...')
246-
execute('mvn', 'versions:set', f'-DnewVersion={state.new_version}',
246+
execute('mvn', 'versions:set', f'-DnewVersion={state.next_version}',
247247
'-DgenerateBackupPoms=false', quiet=True)
248-
info(f'New version set: {state.new_version}')
248+
info(f'New version set: {state.next_version}')
249249

250250

251251
def set_ser_ver_id():
252252
section('Set serialization.version.id ...')
253-
new_ser_ver_id_element = f'<{SER_VER_ID_PROPERTY}>{state.new_ser_ver_id}</{SER_VER_ID_PROPERTY}>'
253+
next_ser_ver_id_element = f'<{SER_VER_ID_PROPERTY}>{state.next_ser_ver_id}</{SER_VER_ID_PROPERTY}>'
254254

255255
with open(POM_FILE_NAME, 'r') as input_stream:
256256
pom_file = input_stream.read()
257-
pom_file = re.sub(SER_VER_ID_PATTERN, new_ser_ver_id_element, pom_file, count=1)
257+
pom_file = re.sub(SER_VER_ID_PATTERN, next_ser_ver_id_element, pom_file, count=1)
258258
with open(POM_FILE_NAME, 'w') as output:
259259
output.write(pom_file)
260-
prefix = 'New' if (state.is_ser_ver_id_new()) else 'Same'
261-
info(f'{prefix} serialization.version.id set: {state.new_ser_ver_id}')
260+
prefix = 'New' if (state.is_ser_ver_id_next()) else 'Same'
261+
info(f'{prefix} serialization.version.id set: {state.next_ser_ver_id}')
262262

263263

264-
def commit_new_versions():
265-
section('Commit new version with version and serialization version id set ...')
264+
def commit_next_versions():
265+
section('Commit pom.xml with next version and serialization version id set ...')
266266
git('add', '.')
267-
git_dr('commit', '--all', '-m', state.new_version_description())
268-
info(f'Commit done: {state.new_version_description()}')
267+
git_dr('commit', '--all', '-m', state.next_version_description())
268+
info(f'Commit done: {state.next_version_description()}')
269269

270270

271271
def tag_release():
272-
section(f'Tag release with {state.new_version} ...')
273-
git_im('tag', '-a', state.new_version_tag(), '-m', state.new_version_description())
274-
info(f'Tag done: {state.new_version_tag()}')
272+
section(f'Tag release with {state.next_version} ...')
273+
git_im('tag', '-a', state.next_version_tag(), '-m', state.next_version_description())
274+
info(f'Tag done: {state.next_version_tag()}')
275275

276276

277277
def push_release_branch_and_tag():
278-
section('Push new release with pom.xml versions and new tag')
278+
section('Push new release with pom.xml changes and new tag')
279279
git_dr('push', '-f', f'{config.release_remote}', f'{config.release_branch}')
280-
git_dr('push', '-f', f'{config.release_remote}', f'v{state.new_version}')
280+
git_dr('push', '-f', f'{config.release_remote}', f'v{state.next_version}')
281281
info(f'Release pushed to: {config.release_branch_path()}')
282282
delete_script_state()
283283
info('\nRELEASE SUCCESS!\n')
@@ -293,9 +293,9 @@ def print_summary():
293293
294294
## Version
295295
296-
- New version/git tag: `{state.new_version}`
297-
- New serialization version: `{state.new_ser_ver_id}`
298-
- Old serialization version: `{state.current_ser_ver_id}`
296+
- New version/git tag: `{state.next_version}`
297+
- New serialization version: `{state.next_ser_ver_id}`
298+
- Old serialization version: `{state.latest_ser_ver_id}`
299299
300300
"""
301301
with open(SUMMARY_FILE, mode="w", encoding="UTF-8") as f:
@@ -307,7 +307,7 @@ def print_summary():
307307
url = f"https://github.com/opentripplanner/OpenTripPlanner/pull/{pr}"
308308
print(f" - {state.pr_titles[pr]} [#{pr}]({url}) {state.pr_labels[pr]}".replace("'", "`"),
309309
file=f)
310-
p = execute("./script/changelog-diff.py", state.curr_version_tag(), state.new_version_tag())
310+
p = execute("./script/changelog-diff.py", state.latest_version_tag(), state.next_version_tag())
311311
print(p.stdout, file=f)
312312

313313

@@ -430,16 +430,16 @@ def resolve_version_number():
430430
state.major_version = read_major_version_from_pom(version_qualifier, options.release_base())
431431

432432

433-
def resolve_new_version():
434-
info('Resolve new version number ...')
433+
def resolve_next_version():
434+
info('Resolve next version number ...')
435435
p = git('tag', '--list', '--sort=-v:refname', error_msg='Fetch git tags failed!')
436436
tags = p.stdout.splitlines()
437437

438438
prefix = f'{state.major_version}-{config.release_remote}-'
439439
pattern = re.compile('v' + prefix.replace('.', r'\.') + r'(\d+)')
440440
max_tag_version = max((int(m.group(1)) for tag in tags if (m := pattern.match(tag))), default=0)
441-
state.current_version = prefix + str(max_tag_version)
442-
state.new_version = prefix + str(1 + max_tag_version)
441+
state.latest_version = prefix + str(max_tag_version)
442+
state.next_version = prefix + str(1 + max_tag_version)
443443

444444

445445
def list_labeled_prs():
@@ -501,36 +501,41 @@ def list_labeled_prs():
501501
LBL_BUMP_SER_VER_ID in labels for labels in state.pr_labels.values())
502502

503503

504-
def resolve_new_ser_ver_id():
505-
info('Resolve the new serialization version id ...')
506-
curr_release_hash = git_show_ref(git_tag(state.current_version))
507-
curr_ser_ver_id = read_ser_ver_id_from_pom_file(curr_release_hash)
504+
# Find out what the next serialization version id should be. First look at the merged pending PRs.
505+
# If none of the PRs have the 'bump serialization id' label set, then find the upstream
506+
# serialization-version-id for the release-base and the latest serialization version. If these
507+
# serialization-version-ids are different, then we need to bump the serialization version id. To
508+
# find the *upstream* ids we look at the git history/log for serialization ids NOT matching the
509+
# project serialization version id prefix - this is assumed to be the latest serialization version
510+
# from the upstream project.
511+
#
512+
# If the '--release' option is used then the serialization version id is NOT updated. Use the
513+
# '--serVerId' option together with the '--release' to force update the serialization version id.
514+
#
515+
def resolve_next_ser_ver_id():
516+
info('Resolve the next serialization version id ...')
517+
latest_release_hash = git_show_ref(git_tag(state.latest_version))
518+
latest_ser_ver_id = read_ser_ver_id_from_pom_file(latest_release_hash)
508519
bump_ser_ver_id = options.bump_ser_ver_id
509520

510-
# If none of the PRs have the 'bump serialization id' label set, then find the upstream
511-
# serialization-version-id for the release-base and the current version. If these
512-
# serialization-version-ids are different, then we need to bump the new release serialization
513-
# version id. To find the *upstream* ids we step back in the git history looking for an id
514-
# not matching the project serialization version id prefix - this is assumed to be the latest
515-
# serialization version from the upstream project.
516-
if not bump_ser_ver_id:
517-
info(' - Find upstream serialization version id for current release ...')
518-
curr_upstream_id = find_upstream_ser_ver_id_in_history(curr_release_hash)
521+
if not (bump_ser_ver_id or options.releaseOnly):
522+
info(' - Find upstream serialization version id for latest release ...')
523+
latest_upstream_id = find_upstream_ser_ver_id_in_history(latest_release_hash)
519524

520525
info(f' - Find base serialization version id ...')
521526
base_hash = git_show_ref(options.release_base())
522527
base_upstream_id = find_upstream_ser_ver_id_in_history(base_hash)
523528

524529
# Update serialization version id in release if serialization version id has changed
525-
bump_ser_ver_id = curr_upstream_id != base_upstream_id
526-
info(f' - The current upstream serialization.ver.id is {curr_upstream_id} '
530+
bump_ser_ver_id = latest_upstream_id != base_upstream_id
531+
info(f' - The latest upstream serialization.ver.id is {latest_upstream_id} '
527532
f'and the base upstream id is {base_upstream_id}.')
528533

529-
state.current_ser_ver_id = curr_ser_ver_id
534+
state.latest_ser_ver_id = latest_ser_ver_id
530535
if bump_ser_ver_id:
531-
state.new_ser_ver_id = bump_release_ser_ver_id(curr_ser_ver_id)
536+
state.next_ser_ver_id = bump_release_ser_ver_id(latest_ser_ver_id)
532537
else:
533-
state.new_ser_ver_id = curr_ser_ver_id
538+
state.next_ser_ver_id = latest_ser_ver_id
534539

535540

536541
# Find the serialization-version-id for the upstream git project using the git log starting
@@ -555,7 +560,7 @@ def print_setup():
555560
- Bump ser.ver.id ............. : {options.bump_ser_ver_id}
556561
- Dry run .................... : {options.dry_run}
557562
- Debugging ................... : {options.debugging}
558-
- Release ...................... : {options.releaseOnly}
563+
- Release ..................... : {options.releaseOnly}
559564
560565
Config
561566
- Upstream git repo remote name : {config.upstream_remote}
@@ -571,10 +576,10 @@ def print_setup():
571576
info(f'''
572577
Release info
573578
- Project major version ....... : {state.major_version}
574-
- Current version ............. : {state.current_version}
575-
- New version ................. : {state.new_version}
576-
- Current ser.ver.id .......... : {state.current_ser_ver_id}
577-
- New ser.ver.id .............. : {state.new_ser_ver_id}
579+
- Latest version .............. : {state.latest_version}
580+
- Next version ................ : {state.next_version}
581+
- Latest ser.ver.id ........... : {state.latest_ser_ver_id}
582+
- Next ser.ver.id ............. : {state.next_ser_ver_id}
578583
''')
579584

580585

@@ -623,16 +628,16 @@ def git_tag(version):
623628
return f'v{version}'
624629

625630

626-
def bump_release_ser_ver_id(current_id):
631+
def bump_release_ser_ver_id(latest_id):
627632
# The id format can be either 'A-00053' or 'AA-0053'
628633
if len(config.ser_ver_id_prefix) == 1:
629-
ver_number = int(current_id[2:])
634+
ver_number = int(latest_id[2:])
630635
ser_format = '{:05d}'
631636
else:
632-
ver_number = int(current_id[3:])
637+
ver_number = int(latest_id[3:])
633638
ser_format = '{:04d}'
634639
v = config.ser_ver_id_prefix + '-' + ser_format.format(ver_number + 1)
635-
debug(f'New serialization version id: {v}')
640+
debug(f'Next serialization version id: {v}')
636641
return v
637642

638643

@@ -768,14 +773,13 @@ def print_help():
768773
print(f"""
769774
This script is used to create a new release in a downstream fork of OTP. It will set both
770775
the Maven version(2.7.0-entur-23) and the serialization-version-id(EN-0020) to a unique id
771-
using the fork project name. For the script to work the git remote name must match the
772-
GitHub 'owner' name.
776+
using the provided configuration.
773777
774778
Release process overview
775-
1. The configured release-branch is reset hard to the <base-revision>.
776-
2. Then the labeled PRs are merged into the release-branch, if configured.
777-
3. The config-branches are merged into the release-branch.
778-
4. The pom.xml file is updated with a new version and serialization version id.
779+
1. The configured release-branch is reset hard to the <base-revision> script argument.
780+
2. Then the labeled PRs are merged into the release-branch [if configured].
781+
3. The config-branches are merged into the release-branch [if configured].
782+
4. The pom.xml file is updated with a new version and serialization version id [if requiered].
779783
5. The release is tested, tagged and pushed to Git repo.
780784
781785
See the RELEASE_README.md for more details.
@@ -785,17 +789,18 @@ def print_help():
785789
786790
Arguments
787791
<base-revision> : The base branch or commit to use as the base for the release. The
788-
'otp/dev-2.x' is the most common base branch to use, but you can
789-
create a new release on top of any <commit>.
790-
This parameter is required unless option --release is used.
792+
'otp/dev-2.x' is the most common base branch to use, but you can create a
793+
new release on top of any <commit>. This parameter is required unless
794+
option --release is used.
791795
792796
Options
793797
-h, --help : Print this help.
794798
--debug : Run script with debug output enabled.
795799
--dryRun : Run script locally, nothing is pushed to remote server.
796-
--release : Create a new release from the current local Git repo HEAD. It updates the
797-
maven-project-version and the serialization-version-id, creates a new tag
798-
and push the release. You should apply all fixes and commit BEFORE running
800+
--release : Create a new release from the checked out local Git repo HEAD. It updates the
801+
maven-project-version, but NOT the serialization-version-id. To increment the
802+
serialization-version-id use the --serVerId option as well. This create a new
803+
tag and push the release. You should apply all fixes and commit BEFORE running
799804
this script. Can not be used with the <base-revision> argument set. The
800805
'custom-release-extension' script is NOT run.
801806
--serVerId : Force incrementation of the serialization version id.

0 commit comments

Comments
 (0)