Skip to content

Commit 455633d

Browse files
committed
Fix Helm chart version bump script
Instead of relying on semver which is not installed, just parse it with bash.
1 parent 63c0719 commit 455633d

1 file changed

Lines changed: 54 additions & 8 deletions

File tree

ci/build/update-repo.sh

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,62 @@
22

33
set -Eeuo pipefail
44

5+
# Given versions $1 and $2 figure out the first component that is different
6+
# (major, minor, patch).
7+
function find_version_diff() {
8+
local a=( ${1//./ } )
9+
local b=( ${2//./ } )
10+
11+
if [[ ${a[0]} != ${b[0]} ]] ; then
12+
echo major
13+
elif [[ ${a[1]} != ${b[1]} ]] ; then
14+
echo minor
15+
else
16+
echo patch
17+
fi
18+
}
19+
20+
# Bump $1 by the bump type (major, minor, patch) in $2.
21+
function bump_version() {
22+
local a=( ${1//./ } )
23+
case $2 in
24+
major)
25+
((a[0]++))
26+
a[1]=0
27+
a[2]=0
28+
;;
29+
minor)
30+
((a[1]++))
31+
a[2]=0
32+
;;
33+
*)
34+
((a[2]++))
35+
;;
36+
esac
37+
echo "${a[0]}.${a[1]}.${a[2]}"
38+
}
39+
540
function update_helm() {
6-
local current
7-
current=$(yq .version ci/helm-chart/Chart.yaml)
8-
local next
9-
next=$(semver "$current" -i minor)
10-
echo "Bumping version from $current to $next..."
11-
sed -i.bak "s/^version: $current\$/version: $next/" ci/helm-chart/Chart.yaml
12-
13-
echo "Setting app version and image to $version..."
41+
local chart_version
42+
chart_version=$(yq .version ci/helm-chart/Chart.yaml)
43+
local app_version
44+
app_version=$(yq .appVersion ci/helm-chart/Chart.yaml)
45+
local image_version
46+
image_version=$(yq .image.tag ci/helm-chart/values.yaml)
47+
48+
local bump_type
49+
bump_type=$(find_version_diff "$app_version" "$version")
50+
local chart_version_bump
51+
chart_version_bump=$(bump_version "$chart_version" "$bump_type")
52+
53+
# Use sed to replace because yq will reformat.
54+
echo "Bumping version from $chart_version to $chart_version_bump..."
55+
sed -i.bak "s/^version: $chart_version\$/version: $chart_version_bump/" ci/helm-chart/Chart.yaml
56+
57+
echo "Bumping app version from $app_version to $version..."
1458
sed -i.bak "s/^appVersion: .\+\$/appVersion: $version/" ci/helm-chart/Chart.yaml
59+
60+
echo "Bumping image version from $image_version to $version..."
1561
sed -i.bak "s/^ tag: .\+\$/ tag: '$version'/" ci/helm-chart/values.yaml
1662
}
1763

0 commit comments

Comments
 (0)