Skip to content

Commit

Permalink
fix: check for version compat on publish script
Browse files Browse the repository at this point in the history
Signed-off-by: Tiago Castro <[email protected]>
  • Loading branch information
tiagolobocastro committed Oct 14, 2024
1 parent b445cac commit ae247c6
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
34 changes: 33 additions & 1 deletion scripts/helm/publish-chart-yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ branch_chart_version()
echo "$RELEASE_V"
elif [ "$(semver validate "$RELEASE_V.0")" == "valid" ]; then
echo "$RELEASE_V.0"
elif [ "$(semver validate "$RELEASE_V.0.0")" == "valid" ]; then
echo "$RELEASE_V.0.0"
else
die "Cannot determine Chart version from branch: $check_branch"
fi
Expand All @@ -150,6 +152,36 @@ branch_chart_version()
fi
}

branch_allowed_version()
{
local release_branch=$1
local version=$2

if ! [[ "$release_branch" =~ ^release\/[0-9.]+$ ]]; then
die "'$release_branch' is not a valid release branch"
fi

local allowed_diff=""
local branch_version="${release_branch#release/}"
if [[ "$branch_version" =~ ^[0-9]+$ ]]; then
branch_version=${branch_version}.0.0
allowed_diff=("" "minor" "patch" "prerelease")
elif [[ "$branch_version" =~ ^[0-9]+.[0-9]+$ ]]; then
branch_version=${branch_version}.0
allowed_diff=("" "patch" "prerelease")
elif [[ "$branch_version" =~ ^[0-9]+.[0-9]+.[0-9]+$ ]]; then
branch_version=${branch_version}
allowed_diff=("" "prerelease")
else
die "'$branch_version' is not a supported release"
fi

diff="$(semver diff "$branch_version" "$version")"
if ! [[ " ${allowed_diff[*]} " =~ " $diff " ]]; then
die "Difference($diff) between branch_version($branch_version) and version($version) not allowed!"
fi
}

# Get the version non-numeric prerelease prefix, eg:
# version_prefix 2.0.1-alpha.1 -> 2.0.1-alpha
version_prefix()
Expand Down Expand Up @@ -413,7 +445,7 @@ if [ -n "$CHECK_BRANCH" ]; then
if [ "$CHART_VERSION" == "0.0.0" ]; then
output_yaml "$APP_TAG" "$APP_TAG" "${CHECK_BRANCH////-}" "Always"
elif [ "$CHART_VERSION" != "$APP_TAG" ]; then
die "ERROR: Already on $CHART_VERSION which does not match $APP_TAG"
branch_allowed_version "$CHECK_BRANCH" "$CHART_VERSION"
fi
exit 0
fi
Expand Down
14 changes: 14 additions & 0 deletions scripts/helm/test-publish-chart-yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,20 @@ CHART_VERSION=2.0.1
CHART_APP_VERSION=2.0.1
test_one "Already on release, no new version"

CHECK_BRANCH=release/2.0
DEVELOP_TO_REL=1
APP_TAG=2.0.0
CHART_VERSION=2.0.1
CHART_APP_VERSION=2.0.1
test_one "Already on compatible release, no new version"

CHECK_BRANCH=release/2
DEVELOP_TO_REL=1
APP_TAG=2.0.0
CHART_VERSION=2.2.1
CHART_APP_VERSION=2.2.1
test_one "Already on compatible release, no new version"

APP_TAG=2.0.0-a.0
CHART_VERSION=2.0.0
CHART_APP_VERSION=2.0.0
Expand Down

0 comments on commit ae247c6

Please sign in to comment.