From fe7e1db52c871f5c7e8b661c4a68e9c1dd4fb363 Mon Sep 17 00:00:00 2001 From: Michael Edgar Date: Fri, 13 Dec 2024 12:21:08 -0500 Subject: [PATCH] add version check for bundle, pre/post processing of catalog resources Signed-off-by: Michael Edgar --- .github/workflows/integration.yml | 3 ++ .github/workflows/release.yml | 16 +++++++-- operator/bin/common.sh | 5 +++ operator/bin/modify-bundle-metadata.sh | 5 --- operator/bin/release-prepare.sh | 48 ++++++++++++++++++++++++++ operator/bin/version-check.sh | 19 ++++++++++ operator/pom.xml | 33 ++++++++++++++++++ pom.xml | 6 ++++ 8 files changed, 127 insertions(+), 8 deletions(-) create mode 100755 operator/bin/release-prepare.sh create mode 100755 operator/bin/version-check.sh diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index fe929f8c7..ea142e568 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -29,6 +29,9 @@ jobs: - name: Set Image Tag Env run: echo "PROJECT_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV + - name: Operator Version Check + run: ./operator/bin/version-check.sh "${{ env.PROJECT_VERSION }}" + - name: Set Up JDK 17 uses: actions/setup-java@v4 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 26c43c5d3..93037a1a8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -54,9 +54,8 @@ jobs: git config --global user.name "github-actions[bot]" git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" git checkout -b release - mvn -B release:prepare -DreleaseVersion=${{steps.metadata.outputs.current-version}} -DdevelopmentVersion=${{steps.metadata.outputs.next-version}} - git checkout ${{github.base_ref}} - git rebase release + + PRERELEASE_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout | tr '[:upper:]' '[:lower:]') export QUARKUS_CONTAINER_IMAGE_REGISTRY="${{ secrets.IMAGE_REPO_HOSTNAME }}" export QUARKUS_CONTAINER_IMAGE_GROUP="${{ secrets.IMAGE_REPO_NAMESPACE }}" export QUARKUS_CONTAINER_IMAGE_USERNAME="${{ secrets.IMAGE_REPO_USERNAME }}" @@ -64,7 +63,18 @@ jobs: export QUARKUS_CONTAINER_IMAGE_PUSH="true" export QUARKUS_CONTAINER_IMAGE_ADDITIONAL_TAGS=latest export QUARKUS_KUBERNETES_NAMESPACE='$${NAMESPACE}' + + mvn -B release:prepare \ + -DprereleaseVersion=${PRERELEASE_VERSION} \ + -DreleaseVersion=${{ steps.metadata.outputs.current-version }} \ + -DdevelopmentVersion=${{ steps.metadata.outputs.next-version }} \ + -Dcontainer-image.registry=${{ secrets.IMAGE_REPO_HOSTNAME }} + + git checkout ${{github.base_ref}} + git rebase release + export GIT_REVISION=$(git rev-parse --short release) + # Build and push the release images using the commit tagged in `release:prepare` mvn -B -P container-image release:perform --no-transfer-progress \ '-Drelease.arguments=-Dquarkus.docker.buildx.platform=${{ env.PLATFORMS }}' diff --git a/operator/bin/common.sh b/operator/bin/common.sh index d154a5f27..d69d3e107 100644 --- a/operator/bin/common.sh +++ b/operator/bin/common.sh @@ -1,5 +1,10 @@ #!/bin/bash +# Operator naming +OPERATOR_NAME="streamshub-console-operator" +OPERATOR_INSTANCE_NAME="${OPERATOR_NAME}-v${VERSION}" +OPERATOR_CSV_NAME="${OPERATOR_NAME}.v${VERSION}" + YQ="$(which yq 2>/dev/null)" || : if [ "${YQ}" == "" ] ; then diff --git a/operator/bin/modify-bundle-metadata.sh b/operator/bin/modify-bundle-metadata.sh index a53c59b59..d346331ff 100755 --- a/operator/bin/modify-bundle-metadata.sh +++ b/operator/bin/modify-bundle-metadata.sh @@ -27,11 +27,6 @@ fi source ${SCRIPT_PATH}/common.sh -# Operator naming -OPERATOR_NAME="streamshub-console-operator" -OPERATOR_INSTANCE_NAME="${OPERATOR_NAME}-v${VERSION}" -OPERATOR_CSV_NAME="${OPERATOR_NAME}.v${VERSION}" - BUNDLE_PATH=${SCRIPT_PATH}/../target/bundle/streamshub-console-operator/ CSV_FILE_PATH=${BUNDLE_PATH}/manifests/streamshub-console-operator.clusterserviceversion.yaml diff --git a/operator/bin/release-prepare.sh b/operator/bin/release-prepare.sh new file mode 100755 index 000000000..eeebd5f80 --- /dev/null +++ b/operator/bin/release-prepare.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +set -xEeuo pipefail + +SCRIPT_PATH="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P)" +OPERATOR_PATH="$(cd -- "${SCRIPT_PATH}/.." >/dev/null 2>&1 ; pwd -P)" + +PRERELEASE_VERSION="${1?prerelease version is required}" +RELEASE_VERSION="${2?release version is required}" +POSTRELEASE_VERSION="${3?postrelease version is required}" +VERSION="${4?current version is required}" +IMAGE_NAME="${5?image name is required}" +GIT_STAGE="${6:-false}" + +source ${SCRIPT_PATH}/common.sh + +PRERELEASE_CSV_NAME="${OPERATOR_NAME}.v${PRERELEASE_VERSION}" +RELEASE_CSV_NAME="${OPERATOR_NAME}.v${RELEASE_VERSION}" +POSTRELEASE_CSV_NAME="${OPERATOR_NAME}.v${POSTRELEASE_VERSION}" + +if [ "${VERSION}" == "${POSTRELEASE_VERSION}" ] ; then + # Running via the `completionGoals` of the maven-release-plugin + echo "[INFO] Running release completion with version ${VERSION}" + + # Create new entry for the next development cycle, "replaces" the version just released + ${YQ} -i '.entries += { + "name": "'${POSTRELEASE_CSV_NAME}'", + "replaces": "'${RELEASE_CSV_NAME}'" + }' ${OPERATOR_PATH}/src/main/olm/channel.alpha.yaml + + if [ "${GIT_STAGE}" == "true" ] ; then + git add ${OPERATOR_PATH}/src/main/olm/channel.alpha.yaml + fi +else + # Running via the `preparationGoals` of the maven-release-plugin + echo "[INFO] Running release preparation for version ${VERSION}" + + # Change the name of the entry to be the released version (e.g removing the -snapshot suffix) + ${YQ} -i '(.entries[].name | select(. == "'${PRERELEASE_CSV_NAME}'")) = "'${RELEASE_CSV_NAME}'"' \ + ${OPERATOR_PATH}/src/main/olm/channel.alpha.yaml + + # Create a file with a reference to the bundle image to be generated during the release + echo "image: ${IMAGE_NAME}:${VERSION}" > ${OPERATOR_PATH}/src/main/olm/bundles/${RELEASE_CSV_NAME}.yaml + + if [ "${GIT_STAGE}" == "true" ] ; then + git add ${OPERATOR_PATH}/src/main/olm/channel.alpha.yaml ${OPERATOR_PATH}/src/main/olm/bundles/${RELEASE_CSV_NAME}.yaml + fi +fi diff --git a/operator/bin/version-check.sh b/operator/bin/version-check.sh new file mode 100755 index 000000000..b71b945dd --- /dev/null +++ b/operator/bin/version-check.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -xEeuo pipefail + +SCRIPT_PATH="$(cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P)" +OPERATOR_PATH="$(cd -- "${SCRIPT_PATH}/.." >/dev/null 2>&1 ; pwd -P)" + +VERSION="${1?version is required}" + +source ${SCRIPT_PATH}/common.sh +ALPHA_CHANNEL=${OPERATOR_PATH}/src/main/olm/channel.alpha.yaml + +if [ "$(${YQ} '(.entries[].name | select(. == "'${OPERATOR_CSV_NAME}'"))' ${ALPHA_CHANNEL})" != "" ] ; then + echo "[INFO] Bundle ${OPERATOR_CSV_NAME} has an entry in ${ALPHA_CHANNEL}" + exit 0; +fi + +echo "[ERROR] Bundle ${OPERATOR_CSV_NAME} has no entry in ${ALPHA_CHANNEL}" +exit 1; diff --git a/operator/pom.xml b/operator/pom.xml index 29181da17..4b9aadeb4 100644 --- a/operator/pom.xml +++ b/operator/pom.xml @@ -145,5 +145,38 @@ + + release-preparation + + + + org.codehaus.mojo + exec-maven-plugin + 3.3.0 + + + olm-channel-update + process-resources + + exec + + + bin/release-prepare.sh + + ${prereleaseVersion} + ${releaseVersion} + ${developmentVersion} + ${project.version} + ${container-image.registry}/${container-image.group}/console-operator-bundle + + true + + + + + + + + diff --git a/pom.xml b/pom.xml index db8a82153..86cb5cb78 100644 --- a/pom.xml +++ b/pom.xml @@ -261,6 +261,12 @@ release-preparation + + + + + + \ No newline at end of file