Skip to content

Commit 4220023

Browse files
hdshawkw
authored andcommitted
chore: update release scripts (#466)
1 parent 94a5a51 commit 4220023

File tree

3 files changed

+131
-34
lines changed

3 files changed

+131
-34
lines changed

bin/release.sh

Lines changed: 107 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ USAGE:
55
$(basename "$0") [FLAGS] <CRATE> <VERSION>
66
77
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."
1112

1213
set -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

130203
verbose=''
131204
dry_run=''
205+
publish_dry_run=''
132206

133207
for arg in "$@"
134208
do
@@ -143,6 +217,9 @@ do
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
179256
fi
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+
181273
if [[ "${errexit+errexit}" ]]; then
182274
echo "$usage"
183275
exit 1
@@ -226,41 +318,26 @@ fi
226318

227319
echo ""
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
240324
else
241325
echo "okay, exiting"
242326
exit 1
243327
fi
244328

245329
if confirm "publish the crate?"; then
246-
247330
echo ""
248331
publish
249332
else
250333
echo "okay, exiting"
251334
exit 1
252335
fi
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
263340
else
264-
"${git_amend[@]}"
265-
"${git_push[@]}"
266-
fi
341+
echo "okay, exiting"
342+
exit 1
343+
fi

bin/update-changelog.sh

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ USAGE:
55
$(basename "$0") [FLAGS] <CRATE_PATH> <TAG>
66
77
FLAGS:
8-
-h, --help Show this help text and exit.
9-
-v, --verbose Enable verbose output."
8+
-h, --help Show this help text and exit.
9+
-v, --verbose Enable verbose output.
10+
-u, --unreleased Only add unreleased changes to changelog
11+
--changelog-path <FILE_PATH> Write the changelog to this path.
12+
default: <CRATE_PATH>/CHANGELOG.md"
1013

1114
set -euo pipefail
1215

@@ -19,9 +22,13 @@ rootdir=$( cd "$bindir"/.. && pwd )
1922
cd "$rootdir"
2023

2124
verbose=''
25+
unreleased=''
26+
changelog_path=''
2227

23-
for arg in "$@"
28+
while [[ $# -gt 0 ]]
2429
do
30+
arg=$1
31+
shift
2532
case "$arg" in
2633
-h|--help)
2734
echo "$usage"
@@ -30,6 +37,13 @@ do
3037
-v|--verbose)
3138
verbose="--verbose"
3239
;;
40+
-u|--unreleased)
41+
unreleased="--unreleased"
42+
;;
43+
--changelog-path)
44+
changelog_path="$1"
45+
shift
46+
;;
3347
-*)
3448
err "unknown flag $arg"
3549
echo "$usage"
@@ -74,7 +88,9 @@ if ! [[ -x "$(command -v git-cliff)" ]]; then
7488
fi
7589
fi
7690

77-
changelog_path="${path}/CHANGELOG.md"
91+
if [[ -z "$changelog_path" ]]; then
92+
changelog_path="${path}/CHANGELOG.md"
93+
fi
7894

7995
status "Updating" "$changelog_path for tag $tag"
8096

@@ -88,6 +104,9 @@ git_cliff=(
88104
if [[ "$verbose" ]]; then
89105
git_cliff+=("$verbose")
90106
fi
107+
if [[ "$unreleased" ]]; then
108+
git_cliff+=("$unreleased")
109+
fi
91110

92111
export GIT_CLIFF__GIT__TAG_PATTERN="${path}-v[0-9]*"
93112
"${git_cliff[@]}"

cliff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ filter_unconventional = true
6868
split_commits = false
6969
# regex for preprocessing the commit messages
7070
commit_preprocessors = [
71+
{ pattern = '^(feat|fix|doc|perf)\((api|subscriber|console)\) ', replace = '${1}(${2}): '}, # fix missing colon after commit type
7172
{ pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](https://github.com/tokio-rs/console/issues/${2}))"}, # replace issue numbers
7273
]
7374
# regex for parsing and grouping commits

0 commit comments

Comments
 (0)