From 4728cd2a17954ca739240627432cb6b032435991 Mon Sep 17 00:00:00 2001 From: Niladri Halder Date: Fri, 22 Sep 2023 06:04:18 +0000 Subject: [PATCH] feat(publish_chart): use latest tag + bump version in main branch Signed-off-by: Niladri Halder --- scripts/helm/publish-chart-yaml.sh | 54 +++++++++++++++++++++++-- scripts/helm/test-publish-chart-yaml.sh | 33 ++++++++++++--- 2 files changed, 77 insertions(+), 10 deletions(-) diff --git a/scripts/helm/publish-chart-yaml.sh b/scripts/helm/publish-chart-yaml.sh index ce7f07169..8269c58c1 100755 --- a/scripts/helm/publish-chart-yaml.sh +++ b/scripts/helm/publish-chart-yaml.sh @@ -49,11 +49,28 @@ branch_chart_version() # Develop has no meaningful version echo "0.0.0" elif [ "$CHECK_BRANCH" == "main" ]; then - # Main has no meaningful version, other than the date-time + # Validate release branch name + if ! [[ "$LATEST_RELEASE_BRANCH" =~ ^(release\/[0-9]+\.[0-9]+)$ ]]; then + die "$LATEST_RELEASE_BRANCH is not a valid release branch" + fi + # It is possible that this version isn't released, and may never see an actual release. + # However, it is the latest possible release, and no newer version of a higher semver + # values likely exists on that repo. + # Adds a '.0' at the end to make the version semver compliant. + local latest_version=${LATEST_RELEASE_BRANCH#release/}.0 + # Main sits one version bump ahead of the latest possible release. + local bumped_latest="" + # Bump minor by default. + if [ "$BUMP_MAJOR_FOR_MAIN" = "true" ]; then + bumped_latest=$(semver bump major "$latest_version") + else + bumped_latest=$(semver bump minor "$latest_version") + fi + # Date-time appended to main tag, if present. if [ -n "$DATE_TIME" ]; then - echo "0.0.0-$DATE_TIME" + echo "$bumped_latest-$DATE_TIME" else - echo "0.0.0-main" + echo "$bumped_latest-main" fi elif [ "$RELEASE_V" != "${CHECK_BRANCH}" ]; then if [ "$(semver validate "$RELEASE_V")" == "valid" ]; then @@ -112,12 +129,16 @@ Options: -d, --dry-run Output actions that would be taken, but don't run them. -h, --help Display this text. --check-chart Check if the chart version/app version is correct for the branch. - --develop-to-release Also upgrade the chart to the release version matching the branch. + --develop-to-release Also upgrade the chart to the release version matching the branch. --app-tag The appVersion tag. --override-index Override the latest chart version from the published chart's index. --index-file Use the provided index.yaml instead of fetching from the git branch. --override-chart Override the Chart.yaml version and app version. --date-time The date-time in the format +"$DATE_TIME_FMT". + --github-org Set GitHub org name (default "openebs"). + --github-repo Set GitHub repository name (default "mayastor-extensions"). + --bump-major-for-main Bump latest released GitHub version tag major version for 'main' + branch, instead of the minor version. Examples: $(basename "$0") --app-tag v2.0.0-alpha.0 @@ -149,6 +170,8 @@ DEVELOP_TO_REL= DATE_TIME_FMT="%Y-%m-%d-%H-%M-%S" DATE_TIME= IGNORE_INDEX_CHECK= +LATEST_RELEASE_BRANCH= +BUMP_MAJOR_FOR_MAIN="false" # Check if all needed tools are installed semver --version >/dev/null @@ -204,6 +227,14 @@ while [ "$#" -gt 0 ]; do DATE_TIME=$1 shift ;; + --latest-release-branch) + LATEST_RELEASE_BRANCH=$1 + shift + ;; + --bump-major-for-main) + BUMP_MAJOR_FOR_MAIN="true" + shift + ;; *) help die "Unknown option: $1" @@ -234,6 +265,21 @@ else APP_TAG=$(version "$APP_TAG") fi +# The latest release branch name is required for generating the helm chart version/appVersion +# for the 'main' branch only. +# The 'git branch' command in the below lines only works when the release branches exist. And it is +# entirely possible that users/contributors don't have all of (or the latest) release branches +# checkout out. Checking remote refs for release/x.y branch entries requires rigorous searching and +# more user input, and also may not succeed for a lot of the possible cases. Because the 'main' +# branch is not a significant branch for a user/contributor, this approach towards finding the latest +# release branch assumes that this script is used only in an automated pipeline where all of the branches +# are checked out. +if [ "$CHECK_BRANCH" = "main" ] && [ -z "$LATEST_RELEASE_BRANCH" ]; then + cd "$ROOTDIR" + LATEST_RELEASE_BRANCH=$(git branch -l 'release/*.*' --format '%(refname:short)' --sort 'refname' | tail -n 1) + cd - >/dev/null +fi + echo "APP_TAG: $APP_TAG" echo "CHART_VERSION: $CHART_VERSION" echo "CHART_APP_VERSION: $CHART_APP_VERSION" diff --git a/scripts/helm/test-publish-chart-yaml.sh b/scripts/helm/test-publish-chart-yaml.sh index 4ab814bef..7585643f2 100755 --- a/scripts/helm/test-publish-chart-yaml.sh +++ b/scripts/helm/test-publish-chart-yaml.sh @@ -36,6 +36,8 @@ NEW_CHART_VERSION= # Updated AppVersion from the Chart.yaml NEW_CHART_APP_VERSION= INDEX_CHART_VERSIONS= +LATEST_RELEASE_BRANCH= +BUMP_MAJOR_FOR_MAIN= EXPECT_FAIL= FAILED= @@ -90,6 +92,12 @@ call_script() if [ -n "$DEVELOP_TO_REL" ]; then ARGS="--develop-to-release $ARGS" fi + if [ -n "$LATEST_RELEASE_BRANCH" ]; then + ARGS="--latest-release-branch $LATEST_RELEASE_BRANCH $ARGS" + if [ "$BUMP_MAJOR_FOR_MAIN" = "true" ]; then + ARGS="--bump-major-for-main $ARGS" + fi + fi else ARGS="--app-tag $APP_TAG $ARGS" fi @@ -157,15 +165,28 @@ test_one "Develop is special" CHECK_BRANCH=main DATE_TIME=$(date +"$DATE_TIME_FMT") -APP_TAG=0.0.0-$DATE_TIME -CHART_VERSION=0.0.0 -CHART_APP_VERSION=0.0.0 +LATEST_RELEASE_BRANCH="release/123.456" +BUMP_MAJOR_FOR_MAIN="false" +APP_TAG=123.457.0-$DATE_TIME +CHART_VERSION=123.457.0 +CHART_APP_VERSION=123.457.0 test_one "Main is special" CHECK_BRANCH=main -APP_TAG=0.0.0-main -CHART_VERSION=0.0.0 -CHART_APP_VERSION=0.0.0 +DATE_TIME=$(date +"$DATE_TIME_FMT") +LATEST_RELEASE_BRANCH="release/123.456" +BUMP_MAJOR_FOR_MAIN="true" +APP_TAG=124.456.0-$DATE_TIME +CHART_VERSION=124.456.0 +CHART_APP_VERSION=124.456.0 +test_one "Main is special" + +CHECK_BRANCH=main +LATEST_RELEASE_BRANCH="release/123.456" +BUMP_MAJOR_FOR_MAIN="false" +APP_TAG=123.457.0-main +CHART_VERSION=123.457.0 +CHART_APP_VERSION=123.457.0 test_one "Main is special" CHECK_BRANCH=release/2.0