5
5
$( basename " $0 " ) [FLAGS] <CRATE> <VERSION>
6
6
7
7
FLAGS:
8
- -h, --help Show this help text and exit.
9
- -v, --verbose Enable verbose output.
10
- -d, --dry-run Do not change any files or commit a git tag."
8
+ -h, --help Show this help text and exit.
9
+ -v, --verbose Enable verbose output.
10
+ -d, --dry-run Do not change any files or commit a git tag.
11
+ --publish-dry-run Perform a dry run on the publish step only."
11
12
12
13
set -euo pipefail
13
14
@@ -71,6 +72,17 @@ update_version() {
71
72
# check the current version of the crate
72
73
local curr_version
73
74
curr_version=$( cargo pkgid -p " $crate " | sed -n ' s/.*#\(.*\)/\1/p' )
75
+
76
+ if ! cargo --list | grep -q " set-version" ; then
77
+ err " missing cargo-set-version executable (from cargo-edit)"
78
+ if confirm " install it?" ; then
79
+ cargo install cargo-edit
80
+ else
81
+ echo " okay, exiting"
82
+ exit 1
83
+ fi
84
+ fi
85
+
74
86
if [[ " $curr_version " == " $version " ]]; then
75
87
err " crate $crate is already at version $version !"
76
88
if ! confirm " are you sure you want to release $version ?" ; then
@@ -79,9 +91,49 @@ update_version() {
79
91
fi
80
92
else
81
93
status " Updating" " $crate from $curr_version to $version "
82
- sed -i \
83
- " /\[package\]/,/\[.*dependencies\]/{s/^version = \" $curr_version \" /version = \" $version \" /}" \
84
- " $cargo_toml "
94
+ cargo set-version -p $crate $version
95
+ fi
96
+
97
+ # If we're releasing console-api, we need to update its version in
98
+ # the other crates in the workspace too.
99
+ if [[ " $crate " == " console-api" ]]; then
100
+ local cargo_upgrade=(cargo upgrade --offline -p console-api@$version )
101
+ if [[ " $verbose " ]]; then
102
+ cargo_upgrade+=(" $verbose " )
103
+ fi
104
+
105
+ " ${cargo_upgrade[@]} "
106
+ files+=($( ls Cargo.lock * /Cargo.toml) )
107
+ fi
108
+ }
109
+
110
+ commit () {
111
+ if ! [[ -z " ${1+1} " ]] && [[ " $1 " == " --amend" ]]; then
112
+ status " Amending" " release commit"
113
+ amend=" $1 "
114
+ else
115
+ status " Creating" " release commit"
116
+ amend=" "
117
+ fi
118
+
119
+ # Prepare a commit message including the changelog from just this release.
120
+ tmp_dir=$( mktemp -d 2> /dev/null || mktemp -d -t ' tokio-console-release' )
121
+ tmp_changelog_path=" $tmp_dir /tmp-changelog"
122
+ tmp_commit_msg_path=" $tmp_dir /tmp-commit-msg"
123
+ " $bindir /update-changelog.sh" --unreleased --changelog-path " $tmp_changelog_path " " $crate " " $crate -v$version "
124
+ (echo -e " chore($slug ): prepare to release $crate $version \n" && cat $tmp_changelog_path | grep -v " generated by git-cliff" ) > $tmp_commit_msg_path
125
+
126
+ git_commit=(git commit -sS -F $tmp_commit_msg_path )
127
+
128
+ if [[ " $amend " ]]; then
129
+ git_commit+=($amend )
130
+ fi
131
+
132
+ if [[ " $dry_run " ]]; then
133
+ echo " "
134
+ echo " # " " ${git_commit[@]} "
135
+ else
136
+ " ${git_commit[@]} "
85
137
fi
86
138
}
87
139
@@ -98,11 +150,19 @@ publish() {
98
150
99
151
if [[ " $dry_run " ]]; then
100
152
cargo_publish+=(" $dry_run " )
153
+ elif [[ " $publish_dry_run " ]]; then
154
+ cargo_publish+=(" $publish_dry_run " )
101
155
fi
102
156
103
157
" ${cargo_package[@]} "
104
158
" ${cargo_publish[@]} "
105
159
160
+ cd " $rootdir "
161
+
162
+ status " Adding" " Cargo.lock after publish"
163
+ git add " Cargo.lock"
164
+ commit --amend
165
+
106
166
status " Tagging" " $tag "
107
167
local git_tag=(git tag " $tag " )
108
168
local git_push_tags=(git push --tags)
@@ -111,7 +171,20 @@ publish() {
111
171
echo " # " " ${git_push_tags[@]} "
112
172
else
113
173
" ${git_tag[@]} "
114
- " ${git_push_tags[@]} "
174
+ fi
175
+ }
176
+
177
+ push () {
178
+ status " Pushing" " release commit and tag $tag "
179
+ local git_push=(git push -u origin)
180
+ local git_push_tag=(git push origin " $tag " )
181
+
182
+ if [[ " $dry_run " ]]; then
183
+ echo " # " " ${git_push[@]} "
184
+ echo " # " " ${git_push_tag[@]} "
185
+ else
186
+ " ${git_push[@]} "
187
+ " ${git_push_tag[@]} "
115
188
fi
116
189
}
117
190
@@ -129,6 +202,7 @@ update_changelog() {
129
202
130
203
verbose=' '
131
204
dry_run=' '
205
+ publish_dry_run=' '
132
206
133
207
for arg in " $@ "
134
208
do
143
217
-d|--dry-run)
144
218
dry_run=" --dry-run"
145
219
;;
220
+ --publish-dry-run)
221
+ publish_dry_run=" --dry-run"
222
+ ;;
146
223
-* )
147
224
err " unknown flag $arg "
148
225
echo " $usage "
@@ -178,6 +255,21 @@ else
178
255
errexit=1
179
256
fi
180
257
258
+ case " $crate " in
259
+ console-subscriber)
260
+ slug=" subscriber"
261
+ ;;
262
+ console-api)
263
+ slug=" api"
264
+ ;;
265
+ tokio-console)
266
+ slug=" console"
267
+ ;;
268
+ * )
269
+ slug=" $crate "
270
+ ;;
271
+ esac
272
+
181
273
if [[ " ${errexit+errexit} " ]]; then
182
274
echo " $usage "
183
275
exit 1
226
318
227
319
echo " "
228
320
229
- if confirm " commit and push?" ; then
230
- git_commit=(git commit -sS -m " chore($crate ): prepare to release $crate $version " )
231
-
232
- if [[ " $dry_run " ]]; then
233
-
234
- echo " "
235
- echo " # " " ${git_commit[@]} "
236
- echo " # " " ${git_push[@]} "
237
- else
238
- " ${git_commit[@]} "
239
- fi
321
+ if confirm " commit?" ; then
322
+ echo " "
323
+ commit
240
324
else
241
325
echo " okay, exiting"
242
326
exit 1
243
327
fi
244
328
245
329
if confirm " publish the crate?" ; then
246
-
247
330
echo " "
248
331
publish
249
332
else
250
333
echo " okay, exiting"
251
334
exit 1
252
335
fi
253
336
254
- cd " $rootdir "
255
- git add " Cargo.lock"
256
- git_push=(git push -u origin --force-with-lease)
257
- git_amend=(git commit --amend --reuse-message HEAD)
258
- if [[ " $dry_run " ]]; then
337
+ if confirm " push release commit and tag?" ; then
259
338
echo " "
260
- echo " # git add Cargo.lock"
261
- echo " # " " ${git_amend[@]} "
262
- echo " # " " ${git_push[@]} "
339
+ push
263
340
else
264
- " ${git_amend[@]} "
265
- " ${git_push[@]} "
266
- fi
341
+ echo " okay, exiting "
342
+ exit 1
343
+ fi
0 commit comments