Skip to content

Commit 6b9e0ea

Browse files
mayastor-borstiagolobocastro
mayastor-bors
andcommitted
chore(bors): merge pull request #579
579: ci: various release chart update fixes r=tiagolobocastro a=tiagolobocastro ci: various release chart update fixes Don't update the chart on a pre-release Set missing base branch for pull-request Add stricter release validation Add more tests Signed-off-by: Tiago Castro <tiagolobocastro@gmail.com> Co-authored-by: Tiago Castro <tiagolobocastro@gmail.com>
2 parents f061be9 + 5fd5c0d commit 6b9e0ea

File tree

3 files changed

+88
-3
lines changed

3 files changed

+88
-3
lines changed

.github/workflows/release-chart.yml

+6-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ jobs:
5454
- name: Publish locally in the workspace
5555
run: |
5656
tag="${{ github.ref_name }}"
57-
nix-shell --pure --run "./scripts/helm/publish-chart-yaml.sh --released "$tag"" ./scripts/helm/shell.nix
57+
BASE_REF="${{ github.event.base_ref }}"
58+
BRANCH="${BASE_REF#refs/heads/}"
59+
nix-shell --pure --run "./scripts/helm/publish-chart-yaml.sh --released "$tag" --released-branch "$BRANCH"" ./scripts/helm/shell.nix
5860
nix-shell --pure --run "SKIP_GIT=1 ./scripts/helm/generate-readme.sh" ./scripts/helm/shell.nix
5961
- name: Create Pull Request
6062
id: cpr
@@ -69,6 +71,9 @@ jobs:
6971
automated-pr
7072
draft: false
7173
signoff: true
74+
delete-branch: true
75+
branch-suffix: "random"
76+
base: ${{ github.event.base_ref }}
7277
token: ${{ secrets.ORG_CI_GITHUB }}
7378
- name: Approve Pull Request by CI Bot
7479
if: ${{ steps.cpr.outputs.pull-request-number }}

scripts/helm/publish-chart-yaml.sh

+37-2
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ Options:
255255
--check-chart <branch> Check if the chart version/app version is correct for the branch.
256256
--develop-to-release Also upgrade the chart to the release version matching the branch.
257257
--released <released-tag> Bumps the future chart version after releasing the given tag.
258+
--released-branch <branch_name> The name of the current releasing branch.
258259
--helm-testing <branch> Upgrade the chart to the appropriate branch chart version.
259260
--app-tag <tag> The appVersion tag.
260261
--override-index <latest_version> Override the latest chart version from the published chart's index.
@@ -301,6 +302,7 @@ DATE_TIME=
301302
IGNORE_INDEX_CHECK=
302303
LATEST_RELEASE_BRANCH=
303304
BUMP_MAJOR_FOR_MAIN=
305+
BRANCH=
304306

305307
# Check if all needed tools are installed
306308
semver --version >/dev/null
@@ -328,7 +330,12 @@ while [ "$#" -gt 0 ]; do
328330
;;
329331
--released)
330332
shift
331-
UPDATE_REL=$1
333+
UPDATE_REL=${1#v}
334+
shift
335+
;;
336+
--released-branch)
337+
shift
338+
BRANCH=$1
332339
shift
333340
;;
334341
--helm-testing)
@@ -408,7 +415,35 @@ else
408415
if [ -n "$APP_TAG" ]; then
409416
die "Cannot specify --update-release and --app-tag together"
410417
fi
411-
APP_TAG=$(semver bump "patch" "$UPDATE_REL")
418+
if [ "$(semver get build "$UPDATE_REL")" != "" ]; then
419+
die "Build not supported"
420+
fi
421+
if [ -n "$BRANCH" ]; then
422+
if ! [[ "$BRANCH" =~ ^release/[0-9]+.[0-9]+$ ]]; then
423+
die "Updates on $BRANCH not supported"
424+
fi
425+
BRANCH_VERSION="${BRANCH#release/}.0"
426+
allowed_diff=( "" "patch" )
427+
diff="$(semver diff "$BRANCH_VERSION" "$CHART_APP_VERSION")"
428+
if ! [[ "${allowed_diff[*]}" =~ $diff ]]; then
429+
die "Branch $BRANCH is incompatible due to semver diff of $diff with current $CHART_APP_VERSION"
430+
fi
431+
fi
432+
diff="$(semver diff "$UPDATE_REL" "$CHART_APP_VERSION")"
433+
if [ "$diff" = "prerelease" ]; then
434+
# It's a pre-release, nothing to do here
435+
APP_TAG="$CHART_APP_VERSION"
436+
else
437+
APP_TAG=$(semver bump "patch" "$UPDATE_REL")
438+
439+
if [ "$(semver compare "$CHART_APP_VERSION" "$UPDATE_REL" )" == "1" ]; then
440+
die "Future version can't possibly be older than the current next"
441+
fi
442+
443+
if [ "$(semver get prerel "$UPDATE_REL")" != "" ]; then
444+
die "$UPDATE_REL with $diff and preprelease change not allowed"
445+
fi
446+
fi
412447
fi
413448
if [ -z "$APP_TAG" ]; then
414449
die "--app-tag not specified"

scripts/helm/test-publish-chart-yaml.sh

+45
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,14 @@ DATE_TIME=
2727
DEVELOP_TO_REL=
2828
# Update the release version after release
2929
RELEASED=
30+
# The release branch being updated
31+
RELEASED_BRANCH=
3032
# Upgrade from develop to helm-testing
3133
HELM_TESTING=
3234
# Tag that has been pushed
3335
APP_TAG=
36+
# Expected output of APP_TAG
37+
OUT_APP_TAG=
3438
# Version from the Chart.yaml
3539
CHART_VERSION=
3640
# AppVersion from the Chart.yaml
@@ -82,14 +86,21 @@ EOF
8286
else
8387
if [ -n "$RELEASED" ]; then
8488
APP_TAG=$NEW_CHART_VERSION
89+
if [ -n "$OUT_APP_TAG" ]; then
90+
APP_TAG=$OUT_APP_TAG
91+
fi
8592
fi
8693
cat <<EOF
8794
APP_TAG: $APP_TAG
8895
CHART_VERSION: $CHART_VERSION
8996
CHART_APP_VERSION: $CHART_APP_VERSION
97+
EOF
98+
if [ -n "$NEW_CHART_VERSION" ]; then
99+
cat <<EOF
90100
NEW_CHART_VERSION: $NEW_CHART_VERSION
91101
NEW_CHART_APP_VERSION: $NEW_CHART_APP_VERSION
92102
EOF
103+
fi
93104
fi
94105
}
95106

@@ -181,6 +192,8 @@ test_one()
181192
DATE_TIME=
182193
DEVELOP_TO_REL=
183194
RELEASED=
195+
RELEASED_BRANCH=
196+
OUT_APP_TAG=
184197
HELM_TESTING=
185198
APP_TAG=
186199
CHART_VERSION=
@@ -399,11 +412,42 @@ test_one "A more stable version is already published, but the app tag stable is
399412

400413
RELEASED=2.0.0
401414
CHART_VERSION=2.0.0
415+
RELEASED_BRANCH=release/2.0
402416
CHART_APP_VERSION=2.0.0
403417
NEW_CHART_VERSION=2.0.1
404418
NEW_CHART_APP_VERSION=2.0.1
405419
test_one "After release 2.0.0, the next one is 2.0.1"
406420

421+
RELEASED=2.0.0-rc.1
422+
CHART_VERSION=2.0.1
423+
RELEASED_BRANCH=release/2.0
424+
CHART_APP_VERSION=2.0.1
425+
EXPECT_FAIL=1
426+
test_one "Can't pre-release what's already released"
427+
428+
RELEASED=2.0.0-rc.1
429+
CHART_VERSION=2.0.0
430+
RELEASED_BRANCH=release/2.0
431+
CHART_APP_VERSION=2.0.0
432+
OUT_APP_TAG=2.0.0
433+
test_one "Just a pre-release"
434+
435+
RELEASED=2.2.0-rc.1
436+
CHART_VERSION=2.0.0
437+
RELEASED_BRANCH=release/2.0
438+
CHART_APP_VERSION=2.0.0
439+
EXPECT_FAIL=1
440+
test_one "A prerelease too far away"
441+
442+
RELEASED=2.0.0
443+
CHART_VERSION=2.0.0
444+
RELEASED_BRANCH=release/2.1
445+
CHART_APP_VERSION=2.0.0
446+
NEW_CHART_VERSION=2.0.1
447+
NEW_CHART_APP_VERSION=2.0.1
448+
EXPECT_FAIL=1
449+
test_one "Branch does not match"
450+
407451
RELEASED=2.0.0
408452
CHART_VERSION=2.0.0
409453
CHART_APP_VERSION=2.0.0
@@ -412,6 +456,7 @@ EXPECT_FAIL=1
412456
test_one "We've actually already release 2.0.1, so the next one is 2.0.2"
413457

414458
RELEASED=2.0.1
459+
RELEASED_BRANCH=release/2.0
415460
CHART_VERSION=2.0.0
416461
CHART_APP_VERSION=2.0.0
417462
INDEX_CHART_VERSIONS=(2.0.1 2.0.0-a.0)

0 commit comments

Comments
 (0)