Skip to content

Commit

Permalink
chore(bors): merge pull request #588
Browse files Browse the repository at this point in the history
588: Cherry-pick PR 579 and PR 584 r=tiagolobocastro a=tiagolobocastro

    chore: fix helm-testing versioning in publish-chart-yaml
    
    Replace hard coded patch and minor values of 0,
    with values derived from the chart version
    
    That way we get versions derived from chart/Chart.yaml,
    like 2.7.2-... instead of hard coded values like 2.7.0-... or 2.0.0-....
    
    Signed-off-by: Blaise Dias <[email protected]>



Co-authored-by: Tiago Castro <[email protected]>
Co-authored-by: Blaise Dias <[email protected]>
  • Loading branch information
3 people committed Dec 16, 2024
2 parents 747ec59 + 3003146 commit 8f85073
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 5 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/release-chart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ jobs:
- name: Publish locally in the workspace
run: |
tag="${{ github.ref_name }}"
nix-shell --pure --run "./scripts/helm/publish-chart-yaml.sh --released "$tag"" ./scripts/helm/shell.nix
BASE_REF="${{ github.event.base_ref }}"
BRANCH="${BASE_REF#refs/heads/}"
nix-shell --pure --run "./scripts/helm/publish-chart-yaml.sh --released "$tag" --released-branch "$BRANCH"" ./scripts/helm/shell.nix
nix-shell --pure --run "SKIP_GIT=1 ./scripts/helm/generate-readme.sh" ./scripts/helm/shell.nix
- name: Create Pull Request
id: cpr
Expand All @@ -69,6 +71,9 @@ jobs:
automated-pr
draft: false
signoff: true
delete-branch: true
branch-suffix: "random"
base: ${{ github.event.base_ref }}
token: ${{ secrets.ORG_CI_GITHUB }}
- name: Approve Pull Request by CI Bot
if: ${{ steps.cpr.outputs.pull-request-number }}
Expand Down
43 changes: 39 additions & 4 deletions scripts/helm/publish-chart-yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ helm_testing_branch_version() {

local latest_version="${release_branch#*release/}"
if [[ "$latest_version" =~ ^[0-9]+$ ]]; then
latest_version=${latest_version}.0.0
latest_version=${latest_version}.$(semver get minor ${CHART_VERSION}).$(semver get patch ${CHART_VERSION})
elif [[ "$latest_version" =~ ^[0-9]+.[0-9]+$ ]]; then
latest_version=${latest_version}.0
latest_version=${latest_version}.$(semver get patch ${CHART_VERSION})
elif [[ "$latest_version" =~ ^[0-9]+.[0-9]+.[0-9]+$ ]]; then
latest_version=${latest_version}
else
Expand Down Expand Up @@ -212,6 +212,7 @@ Options:
--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.
--released <released-tag> Bumps the future chart version after releasing the given tag.
--released-branch <branch_name> The name of the current releasing branch.
--helm-testing <branch> Upgrade the chart to the appropriate branch chart version.
--app-tag <tag> The appVersion tag.
--override-index <latest_version> Override the latest chart version from the published chart's index.
Expand Down Expand Up @@ -256,6 +257,7 @@ DATE_TIME=
IGNORE_INDEX_CHECK=
LATEST_RELEASE_BRANCH=
BUMP_MAJOR_FOR_MAIN=
BRANCH=

# Check if all needed tools are installed
semver --version >/dev/null
Expand Down Expand Up @@ -283,7 +285,12 @@ while [ "$#" -gt 0 ]; do
;;
--released)
shift
UPDATE_REL=$1
UPDATE_REL=${1#v}
shift
;;
--released-branch)
shift
BRANCH=$1
shift
;;
--helm-testing)
Expand Down Expand Up @@ -363,7 +370,35 @@ else
if [ -n "$APP_TAG" ]; then
die "Cannot specify --update-release and --app-tag together"
fi
APP_TAG=$(semver bump "patch" "$UPDATE_REL")
if [ "$(semver get build "$UPDATE_REL")" != "" ]; then
die "Build not supported"
fi
if [ -n "$BRANCH" ]; then
if ! [[ "$BRANCH" =~ ^release/[0-9]+.[0-9]+$ ]]; then
die "Updates on $BRANCH not supported"
fi
BRANCH_VERSION="${BRANCH#release/}.0"
allowed_diff=( "" "patch" )
diff="$(semver diff "$BRANCH_VERSION" "$CHART_APP_VERSION")"
if ! [[ "${allowed_diff[*]}" =~ $diff ]]; then
die "Branch $BRANCH is incompatible due to semver diff of $diff with current $CHART_APP_VERSION"
fi
fi
diff="$(semver diff "$UPDATE_REL" "$CHART_APP_VERSION")"
if [ "$diff" = "prerelease" ]; then
# It's a pre-release, nothing to do here
APP_TAG="$CHART_APP_VERSION"
else
APP_TAG=$(semver bump "patch" "$UPDATE_REL")

if [ "$(semver compare "$CHART_APP_VERSION" "$UPDATE_REL" )" == "1" ]; then
die "Future version can't possibly be older than the current next"
fi

if [ "$(semver get prerel "$UPDATE_REL")" != "" ]; then
die "$UPDATE_REL with $diff and preprelease change not allowed"
fi
fi
fi
if [ -z "$APP_TAG" ]; then
die "--app-tag not specified"
Expand Down
45 changes: 45 additions & 0 deletions scripts/helm/test-publish-chart-yaml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@ DATE_TIME=
DEVELOP_TO_REL=
# Update the release version after release
RELEASED=
# The release branch being updated
RELEASED_BRANCH=
# Upgrade from develop to helm-testing
HELM_TESTING=
# Tag that has been pushed
APP_TAG=
# Expected output of APP_TAG
OUT_APP_TAG=
# Version from the Chart.yaml
CHART_VERSION=
# AppVersion from the Chart.yaml
Expand Down Expand Up @@ -82,14 +86,21 @@ EOF
else
if [ -n "$RELEASED" ]; then
APP_TAG=$NEW_CHART_VERSION
if [ -n "$OUT_APP_TAG" ]; then
APP_TAG=$OUT_APP_TAG
fi
fi
cat <<EOF
APP_TAG: $APP_TAG
CHART_VERSION: $CHART_VERSION
CHART_APP_VERSION: $CHART_APP_VERSION
EOF
if [ -n "$NEW_CHART_VERSION" ]; then
cat <<EOF
NEW_CHART_VERSION: $NEW_CHART_VERSION
NEW_CHART_APP_VERSION: $NEW_CHART_APP_VERSION
EOF
fi
fi
}

Expand Down Expand Up @@ -181,6 +192,8 @@ test_one()
DATE_TIME=
DEVELOP_TO_REL=
RELEASED=
RELEASED_BRANCH=
OUT_APP_TAG=
HELM_TESTING=
APP_TAG=
CHART_VERSION=
Expand Down Expand Up @@ -399,11 +412,42 @@ test_one "A more stable version is already published, but the app tag stable is

RELEASED=2.0.0
CHART_VERSION=2.0.0
RELEASED_BRANCH=release/2.0
CHART_APP_VERSION=2.0.0
NEW_CHART_VERSION=2.0.1
NEW_CHART_APP_VERSION=2.0.1
test_one "After release 2.0.0, the next one is 2.0.1"

RELEASED=2.0.0-rc.1
CHART_VERSION=2.0.1
RELEASED_BRANCH=release/2.0
CHART_APP_VERSION=2.0.1
EXPECT_FAIL=1
test_one "Can't pre-release what's already released"

RELEASED=2.0.0-rc.1
CHART_VERSION=2.0.0
RELEASED_BRANCH=release/2.0
CHART_APP_VERSION=2.0.0
OUT_APP_TAG=2.0.0
test_one "Just a pre-release"

RELEASED=2.2.0-rc.1
CHART_VERSION=2.0.0
RELEASED_BRANCH=release/2.0
CHART_APP_VERSION=2.0.0
EXPECT_FAIL=1
test_one "A prerelease too far away"

RELEASED=2.0.0
CHART_VERSION=2.0.0
RELEASED_BRANCH=release/2.1
CHART_APP_VERSION=2.0.0
NEW_CHART_VERSION=2.0.1
NEW_CHART_APP_VERSION=2.0.1
EXPECT_FAIL=1
test_one "Branch does not match"

RELEASED=2.0.0
CHART_VERSION=2.0.0
CHART_APP_VERSION=2.0.0
Expand All @@ -412,6 +456,7 @@ EXPECT_FAIL=1
test_one "We've actually already release 2.0.1, so the next one is 2.0.2"

RELEASED=2.0.1
RELEASED_BRANCH=release/2.0
CHART_VERSION=2.0.0
CHART_APP_VERSION=2.0.0
INDEX_CHART_VERSIONS=(2.0.1 2.0.0-a.0)
Expand Down

0 comments on commit 8f85073

Please sign in to comment.