-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·187 lines (156 loc) · 4.85 KB
/
release.sh
File metadata and controls
executable file
·187 lines (156 loc) · 4.85 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#!/usr/bin/env bash
set -euo pipefail
CHART_FILE="charts/express-botx/Chart.yaml"
current_branch=$(git rev-parse --abbrev-ref HEAD)
if [[ "$current_branch" != "main" ]]; then
echo "Error: release.sh must be run from the main branch (current: $current_branch)"
exit 1
fi
usage() {
echo "Usage: $0 <command>"
echo ""
echo "Commands:"
echo " app Tag app release"
echo " chart Update Chart.yaml and tag chart release"
echo " both Tag app + update chart + tag chart"
echo " status Show current versions and latest tags"
exit 1
}
current_app_tag() {
git tag --sort=-v:refname | grep -v chart | head -1
}
current_chart_tag() {
git tag --sort=-v:refname | grep '^chart-' | head -1 | sed 's/^chart-//'
}
chart_version() {
grep '^version:' "$CHART_FILE" | awk '{print $2}'
}
chart_app_version() {
grep '^appVersion:' "$CHART_FILE" | awk '{print $2}' | tr -d '"'
}
bump() {
local version="$1" part="$2"
local major minor patch
IFS='.' read -r major minor patch <<< "$version"
case "$part" in
major) echo "$((major + 1)).0.0" ;;
minor) echo "${major}.$((minor + 1)).0" ;;
patch) echo "${major}.${minor}.$((patch + 1))" ;;
esac
}
PICKED_VERSION=""
pick_version() {
local current="$1" label="$2"
local v_patch v_minor v_major
v_patch=$(bump "$current" patch)
v_minor=$(bump "$current" minor)
v_major=$(bump "$current" major)
echo "" > /dev/tty
echo "$label (current: $current):" > /dev/tty
echo " 1) patch -> $v_patch" > /dev/tty
echo " 2) minor -> $v_minor" > /dev/tty
echo " 3) major -> $v_major" > /dev/tty
printf "Choose [1/2/3]: " > /dev/tty
read -r choice < /dev/tty
case "$choice" in
1) PICKED_VERSION="$v_patch" ;;
2) PICKED_VERSION="$v_minor" ;;
3) PICKED_VERSION="$v_major" ;;
*) echo "Invalid choice" > /dev/tty; exit 1 ;;
esac
}
confirm() {
printf "%s [y/N] " "$1" > /dev/tty
read -r ans < /dev/tty
[[ "$ans" =~ ^[Yy]$ ]] || exit 0
}
status() {
echo "App:"
echo " latest tag: $(current_app_tag)"
echo "Chart:"
echo " latest tag: chart-$(current_chart_tag)"
echo " Chart.yaml version: $(chart_version)"
echo " Chart.yaml appVersion: $(chart_app_version)"
}
release_app() {
pick_version "$(current_app_tag)" "App version"
local version="$PICKED_VERSION"
if git tag -l "$version" | grep -q .; then
echo "Error: tag $version already exists"
exit 1
fi
echo ""
echo "Commits since $(current_app_tag):"
git log --oneline "$(current_app_tag)..HEAD"
echo ""
confirm "Create tag $version?"
git tag "$version"
git push origin main
git push origin "$version"
echo "Pushed tag: $version"
}
release_chart() {
pick_version "$(current_chart_tag)" "Chart version"
local version="$PICKED_VERSION"
local tag="chart-${version}"
if git tag -l "$tag" | grep -q .; then
echo "Error: tag $tag already exists"
exit 1
fi
local old_version
old_version=$(chart_version)
echo ""
echo "Will update Chart.yaml: version $old_version -> $version"
confirm "Proceed?"
sed -i '' "s/^version: .*/version: ${version}/" "$CHART_FILE"
git add "$CHART_FILE"
git commit -m "chart version bump"
git tag "$tag"
git push origin main
git push origin "$tag"
echo "Pushed tag: $tag"
}
release_both() {
pick_version "$(current_app_tag)" "App version"
local app_version="$PICKED_VERSION"
pick_version "$(current_chart_tag)" "Chart version"
local chart_ver="$PICKED_VERSION"
local chart_tag="chart-${chart_ver}"
if git tag -l "$app_version" | grep -q .; then
echo "Error: tag $app_version already exists"
exit 1
fi
if git tag -l "$chart_tag" | grep -q .; then
echo "Error: tag $chart_tag already exists"
exit 1
fi
local old_chart_version
old_chart_version=$(chart_version)
echo ""
echo "Plan:"
echo " 1. Tag app: $app_version"
echo " 2. Update Chart.yaml: version $old_chart_version -> $chart_ver, appVersion -> $app_version"
echo " 3. Tag chart: $chart_tag"
echo ""
echo "Commits since $(current_app_tag):"
git log --oneline "$(current_app_tag)..HEAD"
echo ""
confirm "Proceed?"
git tag "$app_version"
sed -i '' "s/^version: .*/version: ${chart_ver}/" "$CHART_FILE"
sed -i '' "s/^appVersion: .*/appVersion: \"${app_version}\"/" "$CHART_FILE"
git add "$CHART_FILE"
git commit -m "chart version bump"
git tag "$chart_tag"
git push origin main
git push origin "$app_version"
git push origin "$chart_tag"
echo "Pushed tags: $app_version, $chart_tag"
}
case "${1:-}" in
app) release_app ;;
chart) release_chart ;;
both) release_both ;;
status) status ;;
*) usage ;;
esac