blob: 4ce3e9d7e3d1c53d3d8dbfc1e496f5966363c67b (
plain) (
blame)
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
|
#!/usr/bin/env bash
set -eou pipefail
source "$(dirname "${BASH_SOURCE[0]}")/lib/log.sh"
source "$(dirname "${BASH_SOURCE[0]}")/lib/path.sh"
readonly VERSION_FILE="$PATH_PROJECT_DIR/internal/commands/version.go"
readonly CHANGELOG_FILE="$PATH_PROJECT_DIR/CHANGELOG.md"
readonly README_FILE="$PATH_PROJECT_DIR/README.md"
readonly DOCS_INDEX_FILE="$PATH_PROJECT_DIR/docs/index.md"
usage() {
echo "Usage: $0 <version>"
echo ""
echo "Create a new release by:"
echo " - Bumping version in all relevant files"
echo " - Updating CHANGELOG.md with new version and today's date"
echo " - Creating a release commit"
echo " - Tagging the commit with the new version"
echo ""
echo "Arguments:"
echo " version The new version (e.g., 0.11.0)"
echo ""
echo "Examples:"
echo " $0 0.11.0"
}
main() {
local new_version="${1:-}"
if [[ -z "$new_version" || "$new_version" == "-h" || "$new_version" == "--help" ]]; then
usage
exit 0
fi
log_header "Creating Release v$new_version"
validate_version_format "$new_version"
check_git_status
check_branch
local current_version
current_version=$(get_current_version)
log_info "Current version: $current_version"
log_info "New version: $new_version"
log_newline
check_version_tag "$new_version"
update_version_file "$current_version" "$new_version"
update_readme "$current_version" "$new_version"
update_docs_index "$current_version" "$new_version"
update_changelog "$new_version"
show_changes
confirm_release "$new_version"
create_release_commit "$new_version"
create_release_tag "$new_version"
show_next_steps "$new_version"
}
validate_version_format() {
local version="$1"
if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
log_error "Invalid version format: $version"
log_info "Expected format: X.Y.Z (e.g., 0.11.0)"
exit 1
fi
}
check_git_status() {
if ! git rev-parse --git-dir >/dev/null 2>&1; then
log_error "Not in a git repository"
exit 1
fi
if ! git diff-index --quiet HEAD --; then
log_error "Working directory is not clean"
log_info "Please commit or stash your changes first"
exit 1
fi
}
check_branch() {
local current_branch
current_branch=$(git branch --show-current)
if [[ "$current_branch" != "main" ]]; then
log_warn "You are on branch '$current_branch', not 'main'"
read -p "Continue anyway? (y/N) " -r -n 1
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
log_info "Release aborted"
exit 0
fi
fi
}
get_current_version() {
local current_version
current_version=$(grep -o 'bolt v[0-9]\+\.[0-9]\+\.[0-9]\+' "$VERSION_FILE" | sed 's/bolt v//')
if [[ -z "$current_version" ]]; then
log_error "Could not extract current version from $VERSION_FILE"
exit 1
fi
echo "$current_version"
}
check_version_tag() {
local version="$1"
if git rev-parse "v$version" >/dev/null 2>&1; then
log_error "Version v$version is already tagged"
exit 1
fi
}
update_version_file() {
local old_version="$1"
local new_version="$2"
log_step "Updating version in $VERSION_FILE"
sed -i.bak "s/bolt v$old_version/bolt v$new_version/g" "$VERSION_FILE"
rm -f "$VERSION_FILE.bak"
}
update_readme() {
local old_version="$1"
local new_version="$2"
log_step "Updating version in $README_FILE"
sed -i.bak "s/version-$old_version-blue/version-$new_version-blue/g" "$README_FILE"
rm -f "$README_FILE.bak"
}
update_docs_index() {
local old_version="$1"
local new_version="$2"
log_step "Updating version in $DOCS_INDEX_FILE"
sed -i.bak "s/version-$old_version-blue/version-$new_version-blue/g" "$DOCS_INDEX_FILE"
rm -f "$DOCS_INDEX_FILE.bak"
}
update_changelog() {
local new_version="$1"
local today
today=$(date +%Y-%m-%d)
log_step "Updating $CHANGELOG_FILE"
if ! grep -q "## \[Unreleased\]" "$CHANGELOG_FILE"; then
log_error "No [Unreleased] section found in $CHANGELOG_FILE"
exit 1
fi
# Replace [Unreleased] with the new version and date, and add a new [Unreleased] section
awk -v version="$new_version" -v date="$today" '
/^## \[Unreleased\]/ {
print $0
print ""
print "## [" version "] - " date
next
}
{ print }
' "$CHANGELOG_FILE" >"$CHANGELOG_FILE.tmp"
mv "$CHANGELOG_FILE.tmp" "$CHANGELOG_FILE"
}
show_changes() {
log_newline
log_step "Changes to be committed:"
git diff "$VERSION_FILE" "$README_FILE" "$DOCS_INDEX_FILE" "$CHANGELOG_FILE"
}
confirm_release() {
local version="$1"
log_newline
read -p "Create release commit and tag for v$version? (y/N) " -r -n 1
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
log_info "Release aborted. Changes have been made but not committed."
exit 0
fi
}
create_release_commit() {
local version="$1"
log_step "Creating release commit"
git add "$VERSION_FILE" "$README_FILE" "$DOCS_INDEX_FILE" "$CHANGELOG_FILE"
git commit -m "Release v$version"
}
create_release_tag() {
local version="$1"
log_step "Creating git tag v$version"
git tag -a "v$version" -m "Release v$version"
}
show_next_steps() {
local version="$1"
local current_branch
current_branch=$(git branch --show-current)
log_newline
log_success "Release v$version created successfully!"
log_newline
log_info "Next steps:"
log_substep "Review the commit and tag:"
log_substep " git show v$version"
log_substep "Push the commit and tag:"
log_substep " git push origin $current_branch"
log_substep " git push origin v$version"
log_substep "Or push both at once:"
log_substep " git push origin $current_branch --follow-tags"
}
main "$@"
|