Skip to content

Commit

Permalink
feat(publish_chart): use latest tag + bump version in main branch
Browse files Browse the repository at this point in the history
Signed-off-by: Niladri Halder <[email protected]>
  • Loading branch information
niladrih committed Sep 22, 2023
1 parent ceb8c77 commit 4728cd2
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 10 deletions.
54 changes: 50 additions & 4 deletions scripts/helm/publish-chart-yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <branch> 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 <tag> The appVersion tag.
--override-index <latest_version> Override the latest chart version from the published chart's index.
--index-file <index_yaml> Use the provided index.yaml instead of fetching from the git branch.
--override-chart <version> <app_version> Override the Chart.yaml version and app version.
--date-time <date-time> The date-time in the format +"$DATE_TIME_FMT".
--github-org <org_name> Set GitHub org name (default "openebs").
--github-repo <repo_name> 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
33 changes: 27 additions & 6 deletions scripts/helm/test-publish-chart-yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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=

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4728cd2

Please sign in to comment.