Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions scripts/auto-rebase/rebase_history.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,26 @@ show_details() {
echo
}

SOURCE_VERSION=$(awk '{print $3}' Makefile.version.aarch64.var | cut -f1 -d-)
MINOR_VERSION=$(echo "${SOURCE_VERSION}" | cut -f2 -d.)
PREVIOUS_MINOR_VERSION=$(( "${MINOR_VERSION}" - 1 ))
PREVIOUS_RELEASE_BRANCH="origin/release-4.${PREVIOUS_MINOR_VERSION}"
SOURCE_VERSION=$(grep '^OCP_VERSION' Makefile.version.aarch64.var | cut -d'=' -f2 | tr -d ' ' | cut -d'-' -f1)
MAJOR_VERSION=$(echo "${SOURCE_VERSION}" | cut -d'.' -f1)
MINOR_VERSION=$(echo "${SOURCE_VERSION}" | cut -d'.' -f2)

# Calculate previous version, handling cross-major boundaries (e.g., 5.0 -> 4.22)
if (( MINOR_VERSION > 0 )); then
PREVIOUS_MAJOR_VERSION="${MAJOR_VERSION}"
PREVIOUS_MINOR_VERSION=$(( MINOR_VERSION - 1 ))
else
# Cross-major boundary: map of last minor version for each major
declare -A LAST_MINOR_FOR_MAJOR=([4]=22)
PREVIOUS_MAJOR_VERSION=$(( MAJOR_VERSION - 1 ))
PREVIOUS_MINOR_VERSION="${LAST_MINOR_FOR_MAJOR[${PREVIOUS_MAJOR_VERSION}]:-}"
if [[ -z "${PREVIOUS_MINOR_VERSION}" ]]; then
echo "ERROR: No last minor version defined for major ${PREVIOUS_MAJOR_VERSION}" >&2
exit 1
fi
fi

PREVIOUS_RELEASE_BRANCH="origin/release-${PREVIOUS_MAJOR_VERSION}.${PREVIOUS_MINOR_VERSION}"
FIRST_RELEASE_COMMIT=$(branch_start "${PREVIOUS_RELEASE_BRANCH}")

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

HISTORY_FILE="_output/rebase_history_4_${MINOR_VERSION}.txt"
HISTORY_FILE="_output/rebase_history_${MAJOR_VERSION}_${MINOR_VERSION}.txt"
rm -f "${HISTORY_FILE}"
# shellcheck disable=SC2162
while read commit summary; do
Expand Down
59 changes: 44 additions & 15 deletions scripts/devenv-builder/configure-vm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -193,29 +193,56 @@ function configure_rhel_subscription() {
function configure_rhel_repositories() {
sudo subscription-manager config --rhsm.manage_repos=1

# Extract major version from Makefile.version
local -r ocp_major="$(grep '^OCP_VERSION' "${MAKE_VERSION}" | cut -d'=' -f2 | tr -d ' ' | cut -d'.' -f1)"

# Map of last minor version for each major (for cross-major transitions)
local -A last_minor_for_major=([4]=22)

# Calculate previous version handling cross-major boundaries
# Sets prev_major and prev_minor variables
get_prev_version() {
local major=$1
local minor=$2
if (( minor > 0 )); then
prev_major="${major}"
prev_minor=$(( minor - 1 ))
else
prev_major=$(( major - 1 ))
prev_minor="${last_minor_for_major[${prev_major}]:-}"
fi
}

RHOCP=$("${RHOCP_REPO}")
if [[ "${RHOCP}" =~ ^[0-9]{2} ]]; then
sudo subscription-manager repos --enable "rhocp-4.${RHOCP}-for-rhel-9-$(uname -m)-rpms"
if [[ "${RHOCP}" =~ ^[0-9]{1,2}$ ]]; then
sudo subscription-manager repos --enable "rhocp-${ocp_major}.${RHOCP}-for-rhel-9-$(uname -m)-rpms"
elif [[ "${RHOCP}" =~ ^http ]]; then
url=$(echo "${RHOCP}" | cut -d, -f1)
ver=$(echo "${RHOCP}" | cut -d, -f2)
OCP_REPO_NAME="rhocp-4.${ver}-for-rhel-9-mirrorbeta-$(uname -i)-rpms"
OCP_REPO_NAME="rhocp-${ocp_major}.${ver}-for-rhel-9-mirrorbeta-$(uname -i)-rpms"
sudo tee "/etc/yum.repos.d/${OCP_REPO_NAME}.repo" >/dev/null <<EOF
[${OCP_REPO_NAME}]
name=Beta rhocp-4.${ver} RPMs for RHEL 9
name=Beta rhocp-${ocp_major}.${ver} RPMs for RHEL 9
baseurl=${url}
enabled=1
gpgcheck=0
skip_if_unavailable=0
EOF
PREVIOUS_RHOCP=$("${RHOCP_REPO}" $((ver-1)))
if [[ "${PREVIOUS_RHOCP}" =~ ^[0-9]{2} ]]; then
sudo subscription-manager repos --enable "rhocp-4.${PREVIOUS_RHOCP}-for-rhel-9-$(uname -m)-rpms"
else
# If RHOCP Y-1 is not available, try RHOCP Y-2.
Y2_RHOCP=$("${RHOCP_REPO}" $((ver-2)))
if [[ "${Y2_RHOCP}" =~ ^[0-9]{2} ]]; then
sudo subscription-manager repos --enable "rhocp-4.${Y2_RHOCP}-for-rhel-9-$(uname -m)-rpms"
# Calculate Y-1 version
get_prev_version "${ocp_major}" "${ver}"
if [[ -n "${prev_minor}" ]]; then
PREVIOUS_RHOCP=$("${RHOCP_REPO}" "${prev_minor}" "${prev_major}")
if [[ "${PREVIOUS_RHOCP}" =~ ^[0-9]{1,2}$ ]]; then
sudo subscription-manager repos --enable "rhocp-${prev_major}.${PREVIOUS_RHOCP}-for-rhel-9-$(uname -m)-rpms"
else
# If RHOCP Y-1 is not available, try RHOCP Y-2.
get_prev_version "${prev_major}" "${prev_minor}"
if [[ -n "${prev_minor}" ]]; then
Y2_RHOCP=$("${RHOCP_REPO}" "${prev_minor}" "${prev_major}")
if [[ "${Y2_RHOCP}" =~ ^[0-9]{1,2}$ ]]; then
sudo subscription-manager repos --enable "rhocp-${prev_major}.${Y2_RHOCP}-for-rhel-9-$(uname -m)-rpms"
fi
fi
fi
fi
fi
Expand Down Expand Up @@ -273,9 +300,11 @@ function install_openshift_clients() {
"${DNF_RETRY}" "install" "openshift-clients"
else
# Assume the current development version on non-RHEL OS
OCPVERSION="4.$(cut -d'.' -f2 "${MAKE_VERSION}")"
OCC_SRC="https://mirror.openshift.com/pub/openshift-v4/$(uname -m)/dependencies/rpms/${OCPVERSION}-el9-beta"
OCC_RPM="$(curl -s "${OCC_SRC}/" | grep -o "openshift-clients-4[^\"']*.rpm" | sort | uniq)"
OCP_MAJOR="$(grep '^OCP_VERSION' "${MAKE_VERSION}" | cut -d'=' -f2 | tr -d ' ' | cut -d'.' -f1)"
OCP_MINOR="$(grep '^OCP_VERSION' "${MAKE_VERSION}" | cut -d'=' -f2 | tr -d ' ' | cut -d'.' -f2)"
OCPVERSION="${OCP_MAJOR}.${OCP_MINOR}"
OCC_SRC="https://mirror.openshift.com/pub/openshift-v${OCP_MAJOR}/$(uname -m)/dependencies/rpms/${OCPVERSION}-el9-beta"
OCC_RPM="$(curl -s "${OCC_SRC}/" | grep -o "openshift-clients-${OCP_MAJOR}[^\"']*.rpm" | sort | uniq)"
OCC_LOC="$(mktemp /tmp/openshift-client-XXXXX.rpm)"
OCC_REM="${OCC_SRC}/${OCC_RPM}"

Expand Down
57 changes: 36 additions & 21 deletions scripts/get-latest-rhocp-repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@
# because repositories are only usable after the release.
# Accessing them before the release results in 403 error.
#
# Script can accept a minor version (e.g. 16) to check for RHOCP of specific version only.
# Script can accept:
# - A minor version (e.g. 16) to check for RHOCP of specific version only.
# - A minor and major version (e.g. 22 4) to check for RHOCP of a specific major.minor.
#
# Output is:
# - just a minor version in case of subscription RHOCP repository, e.g.: 15
# - or an URL to beta mirror followed by comma and minor version, e.g.:
# https://mirror.openshift.com/pub/openshift-v4/x86_64/dependencies/rpms/4.16-el9-beta/,16
# https://mirror.openshift.com/pub/openshift-v5/x86_64/dependencies/rpms/5.0-el9-beta/,0

set -euo pipefail

Expand All @@ -25,39 +28,51 @@ if ! sudo subscription-manager status >&/dev/null; then
exit 1
fi

if [[ "$#" -eq 1 ]]; then
# Get version of currently checked out branch.
# It's based on values stored in Makefile.version.$ARCH.var.
make_version="${REPOROOT}/Makefile.version.$(uname -m).var"
if [ ! -f "${make_version}" ] ; then
# Attempt to locate the Makefile version file next to the current script.
# This is necessary when bootstrapping the development environment for the first time.
make_version=$(find "${SCRIPTDIR}" -maxdepth 1 -name "Makefile.version.$(uname -m).*.var" | tail -1)
if [ ! -f "${make_version}" ] ; then
>&2 echo "Cannot find the Makefile.version.$(uname -m).var file"
exit 1
fi
fi
if [[ "$#" -ge 2 ]]; then
# Both minor and major provided as arguments
current_minor="${1}"
current_major="${2}"
stop="${current_minor}"
elif [[ "$#" -eq 1 ]]; then
# Only minor provided, get major from Makefile
current_minor="${1}"
current_major=$(grep '^OCP_VERSION' "${make_version}" | cut -d'=' -f2 | tr -d ' ' | cut -d'.' -f1)
stop="${current_minor}"
else
# Get minor version of currently checked out branch.
# It's based on values stored in Makefile.version.$ARCH.var.
make_version="${REPOROOT}/Makefile.version.$(uname -m).var"
if [ ! -f "${make_version}" ] ; then
# Attempt to locate the Makefile version file next to the current script.
# This is necessary when bootstrapping the development environment for the first time.
make_version=$(find "${SCRIPTDIR}" -maxdepth 1 -name "Makefile.version.$(uname -m).*.var" | tail -1)
if [ ! -f "${make_version}" ] ; then
>&2 echo "Cannot find the Makefile.version.$(uname -m).var file"
exit 1
fi
fi
current_minor=$(cut -d'.' -f2 "${make_version}")
# No arguments, get both from Makefile
current_major=$(grep '^OCP_VERSION' "${make_version}" | cut -d'=' -f2 | tr -d ' ' | cut -d'.' -f1)
current_minor=$(grep '^OCP_VERSION' "${make_version}" | cut -d'=' -f2 | tr -d ' ' | cut -d'.' -f2)
stop=$(( current_minor - 3 ))
if (( stop < 0 )); then
stop=0
fi
fi

# Go through minor versions, starting from current_mirror counting down
# Go through minor versions, starting from current_minor counting down
# to get latest available rhocp repository.
# For example, at the time of writing this comment, current_minor is 16,
# and following code will try to access rhocp-4.15 (which is not released yet)
# and then rhocp-4.14 (which will be returned from the script because it's usable).
# For example, if current version is 4.16, the code will try to access
# rhocp-4.15 (which may not be released yet) and then rhocp-4.14 (which
# will be returned if it's usable). Works similarly for version 5.x.
for ver in $(seq "${current_minor}" -1 "${stop}"); do
repository="rhocp-4.${ver}-for-rhel-9-$(uname -m)-rpms"
repository="rhocp-${current_major}.${ver}-for-rhel-9-$(uname -m)-rpms"
if sudo dnf repository-packages --showduplicates "${repository}" info cri-o 1>&2; then
echo "${ver}"
exit 0
fi

rhocp_beta_url="https://mirror.openshift.com/pub/openshift-v4/$(uname -m)/dependencies/rpms/4.${ver}-el9-beta/"
rhocp_beta_url="https://mirror.openshift.com/pub/openshift-v${current_major}/$(uname -m)/dependencies/rpms/${current_major}.${ver}-el9-beta/"
if sudo dnf repository-packages --showduplicates --disablerepo '*' --repofrompath "this,${rhocp_beta_url}" this info cri-o 1>&2; then
echo "${rhocp_beta_url},${ver}"
exit 0
Expand Down
38 changes: 38 additions & 0 deletions scripts/release-notes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,44 @@ def get_version_from_makefile():
return major, minor


# Map of last minor version for each major version (for cross-major transitions).
# When moving from X.0 to previous version, we need to know X-1's last minor.
LAST_MINOR_FOR_MAJOR = {
4: 22
}


def get_previous_version(major, minor):
"""
Calculate the previous version (Y-1) handling cross-major boundaries.

When minor > 0, the previous version is simply (major, minor-1).
When minor == 0, the previous version crosses to the prior major,
using LAST_MINOR_FOR_MAJOR to determine the last minor of that major.

Args:
major (int or str): The major version number.
minor (int or str): The minor version number.

Returns:
tuple: (previous_major, previous_minor) as strings.

Raises:
KeyError: If the previous major version is not defined in LAST_MINOR_FOR_MAJOR.
"""
major_int = int(major)
minor_int = int(minor)

if minor_int > 0:
return (str(major_int), str(minor_int - 1))

prev_major = major_int - 1
if prev_major not in LAST_MINOR_FOR_MAJOR:
raise KeyError(f"Major version {prev_major} not found in LAST_MINOR_FOR_MAJOR. "
f"Please add it with the last minor version.")
return (str(prev_major), str(LAST_MINOR_FOR_MAJOR[prev_major]))


def redact(input):
if GITHUB_TOKEN == "":
return input
Expand Down
52 changes: 35 additions & 17 deletions scripts/release-notes/gen_gh_releases_from_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s')

URL_BASE = "https://mirror.openshift.com/pub/openshift-v4/aarch64/microshift"
URL_BASE_X86 = "https://mirror.openshift.com/pub/openshift-v4/x86_64/microshift"

def get_mirror_url_base(major_version, arch):
"""Get the mirror URL base for the given major version and architecture."""
return f"https://mirror.openshift.com/pub/openshift-v{major_version}/{arch}/microshift"


# An EC RPM filename looks like
# microshift-4.13.0~ec.4-202303070857.p0.gcf0bce2.assembly.ec.4.el9.aarch64.rpm
Expand Down Expand Up @@ -102,17 +105,18 @@ def main():
# We build a default list of versions to scan using the current
# version and the previous version. This assumes the script is run
# out of the main branch where we can find the most current
# version under development. During the period where 4.n is being
# developed, 4.n-1 may still be producing only release candidates,
# version under development. During the period where X.n is being
# developed, X.n-1 may still be producing only release candidates,
# so that scanning those 2 versions give us the 2 most recent
# candidates for having no releases. During the period where the
# main branch has not landed a rebase to update the version and
# both main and the pre-release branch have the same version, we
# will end up scanning for EC or RC releases of 4.n-2, but that's
# will end up scanning for EC or RC releases of X.n-2, but that's
# OK because the should all have been tagged already.
prev_major, prev_minor = common.get_previous_version(major, minor)
versions_to_scan = [
'.'.join([major, minor]), # this minor version
'.'.join([major, str(int(minor)-1)]), # the previous minor version
'.'.join([prev_major, prev_minor]), # the previous minor version
]

parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -167,13 +171,22 @@ def main():
if args.versions_to_scan:
versions_to_scan = args.versions_to_scan

# Group versions by major to use correct mirror URL bases
versions_by_major = {}
for version in versions_to_scan:
scan_major = version.split('.', 1)[0]
versions_by_major.setdefault(scan_major, []).append(version)

new_releases = []
if args.ec:
new_releases.extend(find_new_releases(versions_to_scan, URL_BASE, 'ocp-dev-preview'))
new_releases.extend(find_new_releases(versions_to_scan, URL_BASE_X86, 'ocp-dev-preview'))
if args.rc:
new_releases.extend(find_new_releases(versions_to_scan, URL_BASE, 'ocp'))
new_releases.extend(find_new_releases(versions_to_scan, URL_BASE_X86, 'ocp'))
for scan_major, scan_versions in versions_by_major.items():
url_base_aarch64 = get_mirror_url_base(scan_major, 'aarch64')
url_base_x86 = get_mirror_url_base(scan_major, 'x86_64')
if args.ec:
new_releases.extend(find_new_releases(scan_versions, url_base_aarch64, 'ocp-dev-preview'))
new_releases.extend(find_new_releases(scan_versions, url_base_x86, 'ocp-dev-preview'))
if args.rc:
new_releases.extend(find_new_releases(scan_versions, url_base_aarch64, 'ocp'))
new_releases.extend(find_new_releases(scan_versions, url_base_x86, 'ocp'))

if not new_releases:
logging.info("No new releases found.")
Expand All @@ -194,7 +207,7 @@ def main():
class VersionListParser(html.parser.HTMLParser):
"""HTMLParser to extract version numbers from the mirror file list pages.

A page like https://mirror.openshift.com/pub/openshift-v4/aarch64/microshift/ocp-dev-preview/
A page like https://mirror.openshift.com/pub/openshift-v{major}/aarch64/microshift/ocp-dev-preview/

contains HTML like

Expand Down Expand Up @@ -355,20 +368,25 @@ def publish_candidate_release(new_release, take_action):
candidate_number = new_release.candidate_number
release_type = new_release.release_type

# Extract major version from product version (e.g., "4" from "4.16.0")
major_version = product_version.split('.')[0]
url_base_x86 = get_mirror_url_base(major_version, 'x86_64')
url_base_aarch64 = get_mirror_url_base(major_version, 'aarch64')

# Set up the release notes preamble with download links
preamble = textwrap.dedent(f"""
This is a candidate release for {product_version}.

See the mirror for build artifacts:
- {URL_BASE_X86}/{release_type}/{product_version}-{candidate_type}.{candidate_number}/
- {URL_BASE}/{release_type}/{product_version}-{candidate_type}.{candidate_number}/
- {url_base_x86}/{release_type}/{product_version}-{candidate_type}.{candidate_number}/
- {url_base_aarch64}/{release_type}/{product_version}-{candidate_type}.{candidate_number}/

Or add this RPM repository to your x86 systems:

```
[microshift-{product_version}-{candidate_type}-{candidate_number}]
name=MicroShift {product_version} EarlyAccess {candidate_type}.{candidate_number} RPMs
baseurl={URL_BASE_X86}/{release_type}/{product_version}-{candidate_type}.{candidate_number}/el9/os/
baseurl={url_base_x86}/{release_type}/{product_version}-{candidate_type}.{candidate_number}/el9/os/
enabled=1
gpgcheck=0
skip_if_unavailable=0
Expand All @@ -379,7 +397,7 @@ def publish_candidate_release(new_release, take_action):
```
[microshift-{product_version}-{candidate_type}-{candidate_number}]
name=MicroShift {product_version} EarlyAccess {candidate_type}.{candidate_number} RPMs
baseurl={URL_BASE}/{release_type}/{product_version}-{candidate_type}.{candidate_number}/el9/os/
baseurl={url_base_aarch64}/{release_type}/{product_version}-{candidate_type}.{candidate_number}/el9/os/
enabled=1
gpgcheck=0
skip_if_unavailable=0
Expand Down
Loading