Skip to content

Commit

Permalink
Add support for RC to nonRC
Browse files Browse the repository at this point in the history
  • Loading branch information
tomleb committed Oct 16, 2024
1 parent a7c70c3 commit 6a0dae6
Showing 1 changed file with 43 additions and 9 deletions.
52 changes: 43 additions & 9 deletions .github/workflows/scripts/release-against-charts.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
#
# Bumps Webhook version in a locally checked out rancher/charts repository
#
Expand All @@ -19,11 +19,37 @@ Usage:
EOF
}

bump_patch() {
version=$1
major=$(echo "$version" | cut -d. -f1)
minor=$(echo "$version" | cut -d. -f2)
patch=$(echo "$version" | cut -d. -f3)
new_patch=$((patch + 1))
echo "${major}.${minor}.${new_patch}"
}

validate_version_format() {
version=$1
if ! echo "$version" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$'; then
echo "Error: Version $version must be in the format v<major>.<minor>.<patch> or v<major>.<minor>.<patch>-rc.<number>"
exit 1
fi
}

if [ -z "$CHARTS_DIR" ] || [ -z "$PREV_WEBHOOK_VERSION" ] || [ -z "$NEW_WEBHOOK_VERSION" ]; then
usage
exit 1
fi

validate_version_format "$PREV_WEBHOOK_VERSION"
validate_version_format "$NEW_WEBHOOK_VERSION"

if echo "$PREV_WEBHOOK_VERSION" | grep -q '-rc'; then
is_prev_rc=true
else
is_prev_rc=false
fi

if [ "$PREV_WEBHOOK_VERSION" = "$NEW_WEBHOOK_VERSION" ]; then
echo "Previous and new webhook version are the same: $NEW_WEBHOOK_VERSION, but must be different"
exit 1
Expand All @@ -35,7 +61,7 @@ NEW_WEBHOOK_VERSION_SHORT=$(echo "$NEW_WEBHOOK_VERSION" | sed 's|^v||') # e.g.

set -ue

pushd "${CHARTS_DIR}" > /dev/null
cd "${CHARTS_DIR}"

# Validate the given webhook version (eg: 0.5.0-rc.13)
if ! grep -q "${PREV_WEBHOOK_VERSION_SHORT}" ./packages/rancher-webhook/package.yaml; then
Expand All @@ -50,7 +76,12 @@ if ! PREV_CHART_VERSION=$(yq '.version' ./packages/rancher-webhook/package.yaml)
cat ./packages/rancher-webhook/package.yaml
exit 1
fi
NEW_CHART_VERSION=$PREV_CHART_VERSION

if [ "$is_prev_rc" = "false" ]; then
NEW_CHART_VERSION=$(bump_patch "$PREV_CHART_VERSION")
else
NEW_CHART_VERSION=$PREV_CHART_VERSION
fi

sed -i "s/${PREV_WEBHOOK_VERSION_SHORT}/${NEW_WEBHOOK_VERSION_SHORT}/g" ./packages/rancher-webhook/package.yaml

Expand All @@ -61,15 +92,18 @@ PACKAGE=rancher-webhook make charts
git add ./assets/rancher-webhook ./charts/rancher-webhook
git commit -m "make charts"

CHART=rancher-webhook VERSION=${PREV_CHART_VERSION}+up${PREV_WEBHOOK_VERSION_SHORT} make remove
git add ./assets/rancher-webhook ./charts/rancher-webhook ./index.yaml
git commit -m "make remove"
# When previous webhook version is an RC, then we want to remove that RC. We keep
# non-RC version.
if [ "$is_prev_rc" = "true" ]; then
CHART=rancher-webhook VERSION=${PREV_CHART_VERSION}+up${PREV_WEBHOOK_VERSION_SHORT} make remove
git add ./assets/rancher-webhook ./charts/rancher-webhook ./index.yaml
git commit -m "make remove"

yq --inplace "del(.rancher-webhook.[] | select(. == \"${PREV_CHART_VERSION}+up${PREV_WEBHOOK_VERSION_SHORT}\"))" release.yaml
fi

yq --inplace "del(.rancher-webhook.[] | select(. == \"${PREV_CHART_VERSION}+up${PREV_WEBHOOK_VERSION_SHORT}\"))" release.yaml
# Prepends to list
yq --inplace ".rancher-webhook = [\"${NEW_CHART_VERSION}+up${NEW_WEBHOOK_VERSION_SHORT}\"] + .rancher-webhook" release.yaml

git add release.yaml
git commit -m "Add rancher-webhook ${NEW_CHART_VERSION}+up${NEW_WEBHOOK_VERSION_SHORT} to release.yaml"

popd > /dev/null

0 comments on commit 6a0dae6

Please sign in to comment.