Skip to content

Commit 4ad2a48

Browse files
committed
Automate FBC upgrade graph flow
During publish of the operator to OperatorHub, "PREVIOUS_VERSION" variable is used to configure upgrade path for FBC. Currently, this variable is maintainer manually and in case of missing update to the relevant version, leads to a gate job failure. Automate "PREVIOUS_VERSION" variable detection, based on the "VERSION" variable, which is updated as part of the release flow and based on "git tag" detection to catch the latest released version. Signed-off-by: Maxim Babushkin <mbabushk@redhat.com>
1 parent 86719cc commit 4ad2a48

2 files changed

Lines changed: 55 additions & 4 deletions

File tree

Makefile.core.mk

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,25 @@ OLD_VARS := $(.VARIABLES)
2222
VERSION ?= 1.30.0
2323
MINOR_VERSION := $(shell echo "${VERSION}" | cut -f1,2 -d'.')
2424

25-
# This version will be used to generate the OLM upgrade graph in the FBC as a version to be replaced by the new operator version defined in $VERSION.
26-
# This applies for stable releases, for nightly releases we are getting previous version directly from the FBC.
25+
# Auto-detect PREVIOUS_VERSION from git tags relative to VERSION
26+
# This is used to generate the OLM upgrade graph in FBC for stable releases.
27+
# For nightly releases, the previous version is fetched directly from the FBC catalog.
28+
#
29+
# The VERSION variable should be updated to the new release version before running bundle-publish.
30+
# The query will find the latest existing tag less than VERSION (e.g., VERSION=1.31.0 → finds 1.30.0).
31+
#
2732
# Currently we are pushing the operator to two operator hubs https://github.com/k8s-operatorhub/community-operators and
2833
# https://github.com/redhat-openshift-ecosystem/community-operators-prod. Nightly builds go only to community-operators-prod which already
29-
# supports FBC. FBC yaml files and kept in community-operators-prod repo and we only generate a PR with changes using make targets from this Makefile.
34+
# supports FBC. FBC yaml files are kept in community-operators-prod repo and we only generate a PR with changes using make targets from this Makefile.
3035
# There are also GH workflows defined to release nightly and stable operators.
3136
# There is no need to define `replaces` and `skipRange` fields in the CSV as those fields are defined in the FBC and CSV values are ignored.
3237
# FBC is source of truth for OLM upgrade graph.
33-
PREVIOUS_VERSION ?= 1.29.1
38+
#
39+
# To override: make bundle-publish -e PREVIOUS_VERSION=X.Y.Z
40+
#
41+
PREVIOUS_VERSION ?= $(shell \
42+
MAJOR=$$(echo "$(VERSION)" | cut -f1 -d'.'); \
43+
git tag --list "$${MAJOR}.*.*" 2>/dev/null | sort -V | awk -v ver="$(VERSION)" '$$0 < ver {latest=$$0} END {print latest}')
3444

3545
OPERATOR_NAME ?= sailoperator
3646
VERSIONS_YAML_DIR ?= pkg/istioversion

hack/operatorhub/publish-bundle.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,47 @@ GIT_CONFIG_USER_EMAIL="${GIT_CONFIG_USER_EMAIL:-}"
3232
: "${CHANNELS:?"Missing CHANNELS variable"}"
3333
: "${PREVIOUS_VERSION:?"Missing PREVIOUS_VERSION variable"}"
3434

35+
# Validate PREVIOUS_VERSION is a valid semantic version
36+
if ! validate_semantic_versioning "v${PREVIOUS_VERSION}" 2>/dev/null; then
37+
echo "ERROR: PREVIOUS_VERSION (${PREVIOUS_VERSION}) is not a valid semantic version" >&2
38+
exit 1
39+
fi
40+
41+
# Validate PREVIOUS_VERSION exists as git tag
42+
if [[ ${OPERATOR_VERSION} != *"nightly"* ]]; then
43+
# Check if PREVIOUS_VERSION is empty (git tag query failed)
44+
if [ -z "${PREVIOUS_VERSION}" ]; then
45+
echo "ERROR: PREVIOUS_VERSION is empty!" >&2
46+
echo " This indicates git tag query failed to find a suitable previous version" >&2
47+
echo " Possible causes:" >&2
48+
echo " - No git tags exist for this major version" >&2
49+
echo " - Git repository is not available" >&2
50+
echo " - VERSION in Makefile is incorrect" >&2
51+
echo " Please verify VERSION is set correctly and git tags exist" >&2
52+
echo " Or explicitly set: make bundle-publish -e PREVIOUS_VERSION=X.Y.Z" >&2
53+
exit 1
54+
fi
55+
56+
if git rev-parse --git-dir > /dev/null 2>&1; then
57+
if ! git tag --list | grep -q "^${PREVIOUS_VERSION}$"; then
58+
echo "WARNING: PREVIOUS_VERSION (${PREVIOUS_VERSION}) does not exist as a git tag!" >&2
59+
echo " This may indicate the version detection failed or an override was used" >&2
60+
echo " Available recent tags:" >&2
61+
git tag --list | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | sort -V | tail -5 >&2
62+
63+
# In CI, this is an error
64+
if [ "${CI:-false}" = "true" ]; then
65+
echo "ERROR: PREVIOUS_VERSION must be a valid git tag in CI mode" >&2
66+
exit 1
67+
fi
68+
else
69+
echo "Verified: PREVIOUS_VERSION tag exists in git repository ✓"
70+
fi
71+
fi
72+
fi
73+
74+
echo "Using PREVIOUS_VERSION: ${PREVIOUS_VERSION} for OLM upgrade graph"
75+
3576
show_help() {
3677
echo "publish-bundle - raises PR to Operator Hub"
3778
echo " "

0 commit comments

Comments
 (0)