Skip to content

Commit

Permalink
feat(RELEASE-1001): add script to bump catalog task images
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
johnbieren committed Sep 13, 2024
1 parent 12ba767 commit b7b424c
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions utils/bump-catalog-task-refs
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b7b424c

Please sign in to comment.