Skip to content

Commit a9b812b

Browse files
committed
USHIFT-6718: Update logic for previous major rollover
1 parent d23bd66 commit a9b812b

17 files changed

+111
-31
lines changed

scripts/auto-rebase/rebase_history.sh

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,26 @@ show_details() {
2222
echo
2323
}
2424

25-
SOURCE_VERSION=$(awk '{print $3}' Makefile.version.aarch64.var | cut -f1 -d-)
26-
MINOR_VERSION=$(echo "${SOURCE_VERSION}" | cut -f2 -d.)
27-
PREVIOUS_MINOR_VERSION=$(( "${MINOR_VERSION}" - 1 ))
28-
PREVIOUS_RELEASE_BRANCH="origin/release-4.${PREVIOUS_MINOR_VERSION}"
25+
SOURCE_VERSION=$(grep '^OCP_VERSION' Makefile.version.aarch64.var | cut -d'=' -f2 | tr -d ' ' | cut -d'-' -f1)
26+
MAJOR_VERSION=$(echo "${SOURCE_VERSION}" | cut -d'.' -f1)
27+
MINOR_VERSION=$(echo "${SOURCE_VERSION}" | cut -d'.' -f2)
28+
29+
# Calculate previous version, handling cross-major boundaries (e.g., 5.0 -> 4.22)
30+
if (( MINOR_VERSION > 0 )); then
31+
PREVIOUS_MAJOR_VERSION="${MAJOR_VERSION}"
32+
PREVIOUS_MINOR_VERSION=$(( MINOR_VERSION - 1 ))
33+
else
34+
# Cross-major boundary: map of last minor version for each major
35+
declare -A LAST_MINOR_FOR_MAJOR=([4]=22)
36+
PREVIOUS_MAJOR_VERSION=$(( MAJOR_VERSION - 1 ))
37+
PREVIOUS_MINOR_VERSION="${LAST_MINOR_FOR_MAJOR[${PREVIOUS_MAJOR_VERSION}]:-}"
38+
if [[ -z "${PREVIOUS_MINOR_VERSION}" ]]; then
39+
echo "ERROR: No last minor version defined for major ${PREVIOUS_MAJOR_VERSION}" >&2
40+
exit 1
41+
fi
42+
fi
43+
44+
PREVIOUS_RELEASE_BRANCH="origin/release-${PREVIOUS_MAJOR_VERSION}.${PREVIOUS_MINOR_VERSION}"
2945
FIRST_RELEASE_COMMIT=$(branch_start "${PREVIOUS_RELEASE_BRANCH}")
3046

3147
mkdir -p _output
@@ -36,7 +52,7 @@ COMMIT_LIST=_output/commit_list.txt
3652
echo "Getting the list of changes since ${PREVIOUS_RELEASE_BRANCH} was created..."
3753
git log --date-order --reverse --pretty=format:"%H %s" "${FIRST_RELEASE_COMMIT}"..origin/main scripts/auto-rebase/changelog.txt >"${COMMIT_LIST}"
3854

39-
HISTORY_FILE="_output/rebase_history_4_${MINOR_VERSION}.txt"
55+
HISTORY_FILE="_output/rebase_history_${MAJOR_VERSION}_${MINOR_VERSION}.txt"
4056
rm -f "${HISTORY_FILE}"
4157
# shellcheck disable=SC2162
4258
while read commit summary; do

scripts/devenv-builder/configure-vm.sh

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,23 @@ function configure_rhel_repositories() {
196196
# Extract major version from Makefile.version
197197
local -r ocp_major="$(grep '^OCP_VERSION' "${MAKE_VERSION}" | cut -d'=' -f2 | tr -d ' ' | cut -d'.' -f1)"
198198

199+
# Map of last minor version for each major (for cross-major transitions)
200+
local -A last_minor_for_major=([4]=22)
201+
202+
# Calculate previous version handling cross-major boundaries
203+
# Sets prev_major and prev_minor variables
204+
get_prev_version() {
205+
local major=$1
206+
local minor=$2
207+
if (( minor > 0 )); then
208+
prev_major="${major}"
209+
prev_minor=$(( minor - 1 ))
210+
else
211+
prev_major=$(( major - 1 ))
212+
prev_minor="${last_minor_for_major[${prev_major}]:-}"
213+
fi
214+
}
215+
199216
RHOCP=$("${RHOCP_REPO}")
200217
if [[ "${RHOCP}" =~ ^[0-9]{1,2}$ ]]; then
201218
sudo subscription-manager repos --enable "rhocp-${ocp_major}.${RHOCP}-for-rhel-9-$(uname -m)-rpms"
@@ -211,14 +228,21 @@ enabled=1
211228
gpgcheck=0
212229
skip_if_unavailable=0
213230
EOF
214-
PREVIOUS_RHOCP=$("${RHOCP_REPO}" $((ver-1)))
215-
if [[ "${PREVIOUS_RHOCP}" =~ ^[0-9]{1,2}$ ]]; then
216-
sudo subscription-manager repos --enable "rhocp-${ocp_major}.${PREVIOUS_RHOCP}-for-rhel-9-$(uname -m)-rpms"
217-
else
218-
# If RHOCP Y-1 is not available, try RHOCP Y-2.
219-
Y2_RHOCP=$("${RHOCP_REPO}" $((ver-2)))
220-
if [[ "${Y2_RHOCP}" =~ ^[0-9]{1,2}$ ]]; then
221-
sudo subscription-manager repos --enable "rhocp-${ocp_major}.${Y2_RHOCP}-for-rhel-9-$(uname -m)-rpms"
231+
# Calculate Y-1 version
232+
get_prev_version "${ocp_major}" "${ver}"
233+
if [[ -n "${prev_minor}" ]]; then
234+
PREVIOUS_RHOCP=$("${RHOCP_REPO}" "${prev_minor}")
235+
if [[ "${PREVIOUS_RHOCP}" =~ ^[0-9]{1,2}$ ]]; then
236+
sudo subscription-manager repos --enable "rhocp-${prev_major}.${PREVIOUS_RHOCP}-for-rhel-9-$(uname -m)-rpms"
237+
else
238+
# If RHOCP Y-1 is not available, try RHOCP Y-2.
239+
get_prev_version "${prev_major}" "${prev_minor}"
240+
if [[ -n "${prev_minor}" ]]; then
241+
Y2_RHOCP=$("${RHOCP_REPO}" "${prev_minor}")
242+
if [[ "${Y2_RHOCP}" =~ ^[0-9]{1,2}$ ]]; then
243+
sudo subscription-manager repos --enable "rhocp-${prev_major}.${Y2_RHOCP}-for-rhel-9-$(uname -m)-rpms"
244+
fi
245+
fi
222246
fi
223247
fi
224248
fi
@@ -280,7 +304,7 @@ function install_openshift_clients() {
280304
OCP_MINOR="$(grep '^OCP_VERSION' "${MAKE_VERSION}" | cut -d'=' -f2 | tr -d ' ' | cut -d'.' -f2)"
281305
OCPVERSION="${OCP_MAJOR}.${OCP_MINOR}"
282306
OCC_SRC="https://mirror.openshift.com/pub/openshift-v${OCP_MAJOR}/$(uname -m)/dependencies/rpms/${OCPVERSION}-el9-beta"
283-
OCC_RPM="$(curl -s "${OCC_SRC}/" | grep -o "openshift-clients-4[^\"']*.rpm" | sort | uniq)"
307+
OCC_RPM="$(curl -s "${OCC_SRC}/" | grep -o "openshift-clients-${OCP_MAJOR}[^\"']*.rpm" | sort | uniq)"
284308
OCC_LOC="$(mktemp /tmp/openshift-client-XXXXX.rpm)"
285309
OCC_REM="${OCC_SRC}/${OCC_RPM}"
286310

scripts/release-notes/common.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,44 @@ def get_version_from_makefile():
6868
return major, minor
6969

7070

71+
# Map of last minor version for each major version (for cross-major transitions).
72+
# When moving from X.0 to previous version, we need to know X-1's last minor.
73+
LAST_MINOR_FOR_MAJOR = {
74+
4: 22
75+
}
76+
77+
78+
def get_previous_version(major, minor):
79+
"""
80+
Calculate the previous version (Y-1) handling cross-major boundaries.
81+
82+
When minor > 0, the previous version is simply (major, minor-1).
83+
When minor == 0, the previous version crosses to the prior major,
84+
using LAST_MINOR_FOR_MAJOR to determine the last minor of that major.
85+
86+
Args:
87+
major (int or str): The major version number.
88+
minor (int or str): The minor version number.
89+
90+
Returns:
91+
tuple: (previous_major, previous_minor) as strings.
92+
93+
Raises:
94+
KeyError: If the previous major version is not defined in LAST_MINOR_FOR_MAJOR.
95+
"""
96+
major_int = int(major)
97+
minor_int = int(minor)
98+
99+
if minor_int > 0:
100+
return (str(major_int), str(minor_int - 1))
101+
102+
prev_major = major_int - 1
103+
if prev_major not in LAST_MINOR_FOR_MAJOR:
104+
raise KeyError(f"Major version {prev_major} not found in LAST_MINOR_FOR_MAJOR. "
105+
f"Please add it with the last minor version.")
106+
return (str(prev_major), str(LAST_MINOR_FOR_MAJOR[prev_major]))
107+
108+
71109
def redact(input):
72110
if GITHUB_TOKEN == "":
73111
return input

scripts/release-notes/gen_gh_releases_from_mirror.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,18 @@ def main():
105105
# We build a default list of versions to scan using the current
106106
# version and the previous version. This assumes the script is run
107107
# out of the main branch where we can find the most current
108-
# version under development. During the period where 4.n is being
109-
# developed, 4.n-1 may still be producing only release candidates,
108+
# version under development. During the period where X.n is being
109+
# developed, X.n-1 may still be producing only release candidates,
110110
# so that scanning those 2 versions give us the 2 most recent
111111
# candidates for having no releases. During the period where the
112112
# main branch has not landed a rebase to update the version and
113113
# both main and the pre-release branch have the same version, we
114-
# will end up scanning for EC or RC releases of 4.n-2, but that's
114+
# will end up scanning for EC or RC releases of X.n-2, but that's
115115
# OK because the should all have been tagged already.
116+
prev_major, prev_minor = common.get_previous_version(major, minor)
116117
versions_to_scan = [
117118
'.'.join([major, minor]), # this minor version
118-
'.'.join([major, str(int(minor)-1)]), # the previous minor version
119+
'.'.join([prev_major, prev_minor]), # the previous minor version
119120
]
120121

121122
parser = argparse.ArgumentParser(

scripts/release-notes/gen_gh_releases_from_rhocp.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ def get_rpm_releases():
5050
# Try to add current-1 (continuing example from above, it'd be 4.20).
5151
# This is separate because DNF does not query remote repos in order, so enabling not active repo can derail whole cache update.
5252
try:
53-
r = base.repos.get(f"rhocp-{current_major}.{int(current_minor)-1}-for-rhel-9-{arch}-rpms")
53+
prev_major, prev_minor = common.get_previous_version(current_major, current_minor)
54+
r = base.repos.get(f"rhocp-{prev_major}.{prev_minor}-for-rhel-9-{arch}-rpms")
5455
r.enable()
5556
logging.info(f'Enabled repo: {r.id} - {r.name}')
5657
base.fill_sack()

test/bin/build_images.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ rm -f "${CONTAINER_LIST}"
723723
if ${EXTRACT_CONTAINER_IMAGES}; then
724724
extract_container_images "${SOURCE_VERSION}" "${LOCAL_REPO}" "${CONTAINER_LIST}"
725725
# The following images are specific to layers that use fake rpms built from source.
726-
extract_container_images "4.${FAKE_NEXT_MINOR_VERSION}.*" "${NEXT_REPO}" "${CONTAINER_LIST}"
726+
extract_container_images "${MAJOR_VERSION}.${FAKE_NEXT_MINOR_VERSION}.*" "${NEXT_REPO}" "${CONTAINER_LIST}"
727727
extract_container_images "${PREVIOUS_RELEASE_VERSION}" "${PREVIOUS_RELEASE_REPO}" "${CONTAINER_LIST}"
728728
extract_container_images "${YMINUS2_RELEASE_VERSION}" "${YMINUS2_RELEASE_REPO}" "${CONTAINER_LIST}"
729729
# The following images are specific to the brew release versions.

test/bin/scenario.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ exit_if_image_not_set() {
513513

514514
# Exit the script if microshift previous Z-stream version does not exist in rhocp repository
515515
exit_if_zprel_not_exist() {
516-
local -r rhocp_repo="rhocp-4.${MINOR_VERSION}-for-rhel-9-${UNAME_M}-rpms"
516+
local -r rhocp_repo="rhocp-${MAJOR_VERSION}.${MINOR_VERSION}-for-rhel-9-${UNAME_M}-rpms"
517517
local microshift_zprel
518518
if ! microshift_zprel="$(dnf repoquery -q --repo "${rhocp_repo}" --latest-limit 1 --nvr microshift 2>&1)"; then
519519
record_junit "repo ${rhocp_repo} does not exist or is not available: ${microshift_zprel}" "exit_if_zprel_not_exist" "SKIPPED"

test/scenarios/periodics/el96-prel@el98-src@upgrade-ok.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Sourced from scenario.sh and uses functions defined there.
44

55
scenario_create_vms() {
6-
prepare_kickstart host1 kickstart.ks.template "rhel-9.6-microshift-4.${PREVIOUS_MINOR_VERSION}"
6+
prepare_kickstart host1 kickstart.ks.template "rhel-9.6-microshift-${PREVIOUS_MAJOR_VERSION}.${PREVIOUS_MINOR_VERSION}"
77
launch_vm rhel-9.6
88
}
99

test/scenarios/periodics/el96-yminus2@el98-src@upgrade-ok.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Sourced from scenario.sh and uses functions defined there.
44

55
scenario_create_vms() {
6-
prepare_kickstart host1 kickstart.ks.template "rhel-9.6-microshift-4.${YMINUS2_MINOR_VERSION}"
6+
prepare_kickstart host1 kickstart.ks.template "rhel-9.6-microshift-${YMINUS2_MAJOR_VERSION}.${YMINUS2_MINOR_VERSION}"
77
launch_vm rhel-9.6
88
}
99

test/scenarios/presubmits/el96-prel@el98-src@upgrade-ok.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Sourced from scenario.sh and uses functions defined there.
44

55
scenario_create_vms() {
6-
prepare_kickstart host1 kickstart.ks.template "rhel-9.6-microshift-4.${PREVIOUS_MINOR_VERSION}"
6+
prepare_kickstart host1 kickstart.ks.template "rhel-9.6-microshift-${PREVIOUS_MAJOR_VERSION}.${PREVIOUS_MINOR_VERSION}"
77
launch_vm rhel-9.6
88
}
99

0 commit comments

Comments
 (0)