This repository has been archived by the owner on Sep 15, 2022. It is now read-only.
/
release.sh
executable file
·91 lines (71 loc) · 2.69 KB
/
release.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env bash
set -xe
REMOTE=${REMOTE:-origin}
if [ "$#" -eq 1 ]; then
YATAI_IMAGE=$1
VERSION=$1
elif [ "$#" -eq 2 ]; then
YATAI_IMAGE=$1
VERSION=$2
else
echo "Usage: $0 [YATAI_IMAGE] [VERSION]"
exit 1
fi
echo "Updating Yatai image to $YATAI_IMAGE and version to $VERSION"
GIT_ROOT=$(git rev-parse --show-toplevel)
git checkout main
echo "Updating the value.yaml file with the new Yatai image..."
echo "Updating appVersion and version in Chart.yaml"
if [[ "$OSTYPE" =~ ^darwin ]] && ! sed --version | grep -q GNU; then
# Note
# for Mac users who get an invalid command code C error... For in-place
# replacements, BSD sed requires a file extension after the -i flag because it
# saves a backup file with the given extension. For example: sed -i '.bak'
# 's/find/replace/' /file.txt You can skip the backup by using an empty
# string like so: sed -i '' 's/find/replace/' /file.txt –
sed -i '' "s/^ tag:.*$/ tag: \"$YATAI_IMAGE\"/" values.yaml
sed -i '' "s/^version:.*$/version: \"$VERSION\"/" Chart.yaml
sed -i '' "s/^appVersion:.*$/appVersion: \"$VERSION\"/" Chart.yaml
else
sed -i "s/^ tag:.*$/ tag: \"$YATAI_IMAGE\"/" values.yaml
sed -i "s/^version:.*$/version: \"$VERSION\"/" Chart.yaml
sed -i "s/^appVersion:.*$/appVersion: \"$VERSION\"/" Chart.yaml
fi
# Add changed files to git
git add values.yaml Chart.yaml
git commit -m "Update Yatai and Helm version to $VERSION"
git push ${REMOTE} main
tag_name="v$VERSION"
if git rev-parse "$tag_name" >/dev/null 2>&1; then
echo "Tag $tag_name already exists"
echo "To overwrite existing tag, run the following command:"
echo "git tag -d $tag_name && git push --delete ${REMOTE} $tag_name"
git checkout "$tag_name"
else
echo "Creating tag $tag_name"
git tag -a "$tag_name" -m "Tag generated by bentoctl/dev/release.sh, version: $VERSION"
git push ${REMOTE} "$tag_name"
fi
# generate index.yaml and .tgz file
echo "Package helm chart to .tgz file..."
helm package .
TAR_FILE="yatai-$VERSION.tgz"
# Restore the changes from
git restore values.yaml Chart.yaml
git stash --include-untracked
# Checkout the `artifacthub-io-release` branch
echo "Checking out the artifacthub-io-release branch..."
git checkout artifacthub-io-release
git pull ${REMOTE} artifacthub-io-release:artifacthub-io-release -r
git stash pop
echo "Re-index helm charts..."
helm repo index .
# commit the changes
echo "Committing the changes..."
# Find the .tgz file name and add it to the commit
git add "$TAR_FILE" index.yaml
# commit the changes
git commit -m "Update Yatai image to $YATAI_IMAGE and Helm chart version to $VERSION"
# push the changes
git push ${REMOTE} artifacthub-io-release
echo "Done!"