55 $( basename " $0 " ) [FLAGS] <CRATE> <VERSION>
66
77FLAGS:
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."
1112
1213set -euo pipefail
1314
@@ -71,6 +72,17 @@ update_version() {
7172 # check the current version of the crate
7273 local curr_version
7374 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+
7486 if [[ " $curr_version " == " $version " ]]; then
7587 err " crate $crate is already at version $version !"
7688 if ! confirm " are you sure you want to release $version ?" ; then
@@ -79,9 +91,49 @@ update_version() {
7991 fi
8092 else
8193 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[@]} "
85137 fi
86138}
87139
@@ -98,11 +150,19 @@ publish() {
98150
99151 if [[ " $dry_run " ]]; then
100152 cargo_publish+=(" $dry_run " )
153+ elif [[ " $publish_dry_run " ]]; then
154+ cargo_publish+=(" $publish_dry_run " )
101155 fi
102156
103157 " ${cargo_package[@]} "
104158 " ${cargo_publish[@]} "
105159
160+ cd " $rootdir "
161+
162+ status " Adding" " Cargo.lock after publish"
163+ git add " Cargo.lock"
164+ commit --amend
165+
106166 status " Tagging" " $tag "
107167 local git_tag=(git tag " $tag " )
108168 local git_push_tags=(git push --tags)
@@ -111,7 +171,20 @@ publish() {
111171 echo " # " " ${git_push_tags[@]} "
112172 else
113173 " ${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[@]} "
115188 fi
116189}
117190
@@ -129,6 +202,7 @@ update_changelog() {
129202
130203verbose=' '
131204dry_run=' '
205+ publish_dry_run=' '
132206
133207for arg in " $@ "
134208do
143217 -d|--dry-run)
144218 dry_run=" --dry-run"
145219 ;;
220+ --publish-dry-run)
221+ publish_dry_run=" --dry-run"
222+ ;;
146223 -* )
147224 err " unknown flag $arg "
148225 echo " $usage "
@@ -178,6 +255,21 @@ else
178255 errexit=1
179256fi
180257
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+
181273if [[ " ${errexit+errexit} " ]]; then
182274 echo " $usage "
183275 exit 1
226318
227319echo " "
228320
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
240324else
241325 echo " okay, exiting"
242326 exit 1
243327fi
244328
245329if confirm " publish the crate?" ; then
246-
247330 echo " "
248331 publish
249332else
250333 echo " okay, exiting"
251334 exit 1
252335fi
253336
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
259338 echo " "
260- echo " # git add Cargo.lock"
261- echo " # " " ${git_amend[@]} "
262- echo " # " " ${git_push[@]} "
339+ push
263340else
264- " ${git_amend[@]} "
265- " ${git_push[@]} "
266- fi
341+ echo " okay, exiting "
342+ exit 1
343+ fi
0 commit comments