From b7b424ccd6db2a430879ed23c5d614016b88a68f Mon Sep 17 00:00:00 2001 From: Johnny Bieren Date: Fri, 13 Sep 2024 15:33:36 -0400 Subject: [PATCH] feat(RELEASE-1001): add script to bump catalog task images This commit adds a script that can be used in a final pipeline to bump all the release-service-utils image references in tasks contained in the release-service-catalog. It will also update the task version strings and READMEs. Signed-off-by: Johnny Bieren --- utils/bump-catalog-task-refs | 61 ++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 utils/bump-catalog-task-refs diff --git a/utils/bump-catalog-task-refs b/utils/bump-catalog-task-refs new file mode 100755 index 0000000..b48eb91 --- /dev/null +++ b/utils/bump-catalog-task-refs @@ -0,0 +1,61 @@ +#!/bin/bash +# +# script: bump-catalog-task-refs +# +# description: This script inspects the passed commit from release-service-utils. If it is +# not a bot commit, it will create a pull request to the release-service-catalog +# repo to bump the release-service-utils image reference in each task and test using +# it. +# +# example command: +# get-catalog-task-refs SHA where SHA is a release-service-utils commit sha +# + +UTILS_SHA=$1 + +if [ -z "${UTILS_SHA}" ] ; then + echo -e "Please pass a release-service-utils commit sha to bump the task references to" + exit 1 +fi + +UTILS_REPO=https://github.com/konflux-ci/release-service-utils.git +CATALOG_REPO= +CATALOG_BASE_BRANCH=development +CATALOG_PR_BRANCH=automated_update_task_image_refs +VERSION_LABEL=app.kubernetes.io/version +COMMIT_TITLE="" + +git clone "$UTILS_REPO" utils +pushd utils +COMMIT_TITLE="$(git show -s --format=%s $UTILS_SHA)" +if [[ "$(git show -s --format='%ae' $UTILS_SHA)" == *"bot"* ]] ; then + echo "This release-service-utils commit was made by a bot." + echo "We do not bump the catalog task image references for bot commits. Exiting..." + exit 0 +fi +popd + +TODO - git clone the repo with perms +cd catalog +git checkout "$CATALOG_BASE_BRANCH" +git checkout -b "$CATALOG_PR_BRANCH" +# Replace image references +find tasks -type f -name *.yaml | \ + xargs sed -i "s|quay.io/konflux-ci/release-service-utils:.*$|quay.io/konflux-ci/release-service-utils:$UTILS_SHA|g" +# Get all task directories, exclude tests directories +for TASK_DIR in "$(find tasks/ -type d | cut -d '/' -f -2 | uniq)" ; do + # Update x.y.z version string by bumping y and setting z to 0 + oldVersion="$(yq ".metadata.labels.[\"$VERSION_LABEL\"]" $TASK_DIR/*.yaml)" + yVersion="$(echo $oldVersion | cut -d '.' -f 2)" + newVersion="$(echo $version | cut -d '.' -f 1).$((y_version+1)).0" + yq e -i ".metadata.labels.[\"$VERSION_LABEL\"] = \"$newVersion\"" $TASK_DIR/*.yaml + + # Update READMEs + sed "0,/## Changes in/s//## Changes in $newVersion\n* Release Service Utils Image Update\n * $COMMIT_TITLE\n\n&/" $TASK_DIR/README.md +done + +git add . +git commit -s -m "chore: bump release-service-utils image refs" +git push -f origin "$CATALOG_PR_BRANCH" + +TODO - git cli stuff to open PR