diff --git a/scripts/helm/publish-chart-yaml.sh b/scripts/helm/publish-chart-yaml.sh index e224b27e3..dcda2d2f9 100755 --- a/scripts/helm/publish-chart-yaml.sh +++ b/scripts/helm/publish-chart-yaml.sh @@ -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 @@ -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() @@ -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 diff --git a/scripts/helm/test-publish-chart-yaml.sh b/scripts/helm/test-publish-chart-yaml.sh index 1f12f6cae..7f87108cb 100755 --- a/scripts/helm/test-publish-chart-yaml.sh +++ b/scripts/helm/test-publish-chart-yaml.sh @@ -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