Skip to content

Commit fa404b0

Browse files
committed
feature: Improve the resolve_next_ser_ver_id() in custom-release.py
1 parent 1e19f2e commit fa404b0

File tree

1 file changed

+49
-33
lines changed

1 file changed

+49
-33
lines changed

script/custom-release.py

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -525,36 +525,52 @@ def read_pull_request_info_from_github():
525525
pullRequests.append(pr)
526526

527527

528+
# The script will resolve what the next serialization version id (SID) should be. This is a complex task.
529+
# Here is an overview:
530+
# 1. If the --serVerId option exist, then the latest SID is bumped and used.
531+
# 2. If the --release option exist, then the current pom.xml SID is validated, if ok it is used,
532+
# if not the script exit.
533+
# 3. All merged in PRs are checked. If a PR is labeled with 'bump serialization id' and the the
534+
# HEAD commit is not in the latest release, then the last release SID is bumped and used.
535+
# 4. Finally, the script look at the upstream SID for the last release and the base. If the SID
536+
# is not the same the SID of the last release is bumped. To find the *upstream* SIDs the script
537+
# look at the git history/log NOT matching the project serialization version id prefix - this
538+
# is assumed to be the latest SID for the upstream project.
539+
#
540+
# Tip! If the '--release' option is used, then the serialization version id is NOT updated. Use the
541+
# '--serVerId' option together with the '--release' to force update the serialization version id.
542+
#
528543
def resolve_next_ser_ver_id():
529544
info('Resolve the next serialization version id ...')
530545
latest_release_hash = state.latest_version_git_hash()
531-
latest_ser_ver_id = read_ser_ver_id_from_pom_file(latest_release_hash)
532-
bump_ser_ver_id = options.bump_ser_ver_id
533-
534-
# If none of the PRs have the 'bump serialization id' label set, then find the upstream
535-
# serialization-version-id for the release-base and the current version. If these
536-
# serialization-version-ids are different, then we need to bump the new release serialization
537-
# version id. To find the *upstream* ids we step back in the git history looking for an id
538-
# not matching the project serialization version id prefix - this is assumed to be the latest
539-
# serialization version from the upstream project.
540-
if not bump_ser_ver_id:
546+
state.latest_ser_ver_id = read_ser_ver_id_from_pom_file(latest_release_hash)
547+
548+
if options.bump_ser_ver_id:
549+
state.next_ser_ver_id = bump_release_ser_ver_id(state.latest_ser_ver_id)
550+
elif options.releaseOnly:
551+
current_ser_ver_id = read_ser_ver_id_from_pom_file("HEAD")
552+
if current_ser_ver_id.startswith(config.ser_ver_id_prefix):
553+
state.next_ser_ver_id = current_ser_ver_id
554+
else:
555+
error(f'The serialization-version-id ({current_ser_ver_id}) in the pom.xml must start with {config.ser_ver_id_prefix}.')
556+
elif state.prs_bump_ser_ver_id:
557+
state.next_ser_ver_id = bump_release_ser_ver_id(state.latest_ser_ver_id)
558+
else:
541559
info(' - Find upstream serialization version id for latest release ...')
542-
latest_upstream_id = find_upstream_ser_ver_id_in_history(latest_release_hash)
560+
latest_upstream_ser_id = find_upstream_ser_ver_id_in_history(latest_release_hash)
543561

544562
info(f' - Find base serialization version id ...')
545563
base_hash = options.release_base_git_hash()
546-
base_upstream_id = find_upstream_ser_ver_id_in_history(base_hash)
564+
base_upstream_ser_id = find_upstream_ser_ver_id_in_history(base_hash)
547565

548566
# Update serialization version id in release if serialization version id has changed
549-
bump_ser_ver_id = latest_upstream_id != base_upstream_id
550-
info(f' - The latest upstream serialization.ver.id is {latest_upstream_id} '
551-
f'and the base upstream id is {base_upstream_id}.')
552-
553-
state.latest_ser_ver_id = latest_ser_ver_id
554-
if bump_ser_ver_id:
555-
state.next_ser_ver_id = bump_release_ser_ver_id(latest_ser_ver_id)
556-
else:
557-
state.next_ser_ver_id = latest_ser_ver_id
567+
if latest_upstream_ser_id != base_upstream_ser_id:
568+
info(f' - The latest upstream serialization.ver.id {latest_upstream_ser_id} '
569+
f'and the base upstream id {base_upstream_ser_id} is diffrent. '
570+
'The serialization.ver.id is bumped.')
571+
state.next_ser_ver_id = bump_release_ser_ver_id(latest_ser_ver_id)
572+
else:
573+
state.next_ser_ver_id = latest_ser_ver_id
558574

559575

560576
# Find the serialization-version-id for the upstream git project using the git log starting
@@ -801,14 +817,13 @@ def print_help():
801817
print(f"""
802818
This script is used to create a new release in a downstream fork of OTP. It will set both
803819
the Maven version(2.7.0-entur-23) and the serialization-version-id(EN-0020) to a unique id
804-
using the fork project name. For the script to work the git remote name must match the
805-
GitHub 'owner' name.
820+
using the provided configuration.
806821
807822
Release process overview
808-
1. The configured release-branch is reset hard to the <base-revision>.
809-
2. Then the labeled PRs are merged into the release-branch, if configured.
810-
3. The config-branches are merged into the release-branch.
811-
4. The pom.xml file is updated with a new version and serialization version id.
823+
1. The configured release-branch is reset hard to the <base-revision> script argument.
824+
2. Then the labeled PRs are merged into the release-branch [if configured].
825+
3. The config-branches are merged into the release-branch [if configured].
826+
4. The pom.xml file is updated with a new version and serialization version id [if requiered].
812827
5. The release is tested, tagged and pushed to Git repo.
813828
814829
See the RELEASE_README.md for more details.
@@ -818,17 +833,18 @@ def print_help():
818833
819834
Arguments
820835
<base-revision> : The base branch or commit to use as the base for the release. The
821-
'otp/dev-2.x' is the most common base branch to use, but you can
822-
create a new release on top of any <commit>.
823-
This parameter is required unless option --release is used.
836+
'otp/dev-2.x' is the most common base branch to use, but you can create a
837+
new release on top of any <commit>. This parameter is required unless
838+
option --release is used.
824839
825840
Options
826841
-h, --help : Print this help.
827842
--debug : Run script with debug output enabled.
828843
--dryRun : Run script locally, nothing is pushed to remote server.
829-
--release : Create a new release from the current local Git repo HEAD. It updates the
830-
maven-project-version and the serialization-version-id, creates a new tag
831-
and push the release. You should apply all fixes and commit BEFORE running
844+
--release : Create a new release from the checked out local Git repo HEAD. It updates the
845+
maven-project-version, but NOT the serialization-version-id. To increment the
846+
serialization-version-id use the --serVerId option as well. This create a new
847+
tag and push the release. You should apply all fixes and commit BEFORE running
832848
this script. Can not be used with the <base-revision> argument set. The
833849
'custom-release-extension' script is NOT run.
834850
--serVerId : Force incrementation of the serialization version id.

0 commit comments

Comments
 (0)