Skip to content

Commit c8a681f

Browse files
gnpricechrisbobbe
authored andcommitted
tools: Add bump-version, simplifying a release step
This is adapted from the tools/bump-version in zulip-mobile.
1 parent cfd2a17 commit c8a681f

File tree

2 files changed

+71
-15
lines changed

2 files changed

+71
-15
lines changed

docs/release.md

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,11 @@
66
Flutter and packages dependencies, do that first.
77
For details of how, see our README.
88

9-
* Write an entry in `docs/changelog.md`, as "Unreleased".
9+
* Write an entry in `docs/changelog.md`, under "Unreleased".
1010
Commit that change.
1111

12-
* Increment the version number in `pubspec.yaml`:
13-
14-
Take the line near the top that looks like `version: 0.0.42+42`,
15-
and increment both of the last two numbers.
16-
They should remain equal to each other.
17-
18-
Edit the "Unreleased" heading in `docs/changelog.md` to the
19-
new version number.
20-
21-
* Commit the version-number changes, and tag:
22-
`git commit pubspec.yaml docs/changelog.md -m 'version: Bump version to 0.0.NNN'
23-
&& git tag v0.0.NNN`
24-
25-
* Push the tag to our central repo: `git push origin main v0.0.NNN`
12+
* Run `tools/bump-version` to update the version number.
13+
Inspect the resulting commit and tag, and push.
2614

2715

2816
## Build and upload alpha: Android

tools/bump-version

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
usage () {
5+
cat <<EOF >&2
6+
usage: bump-version
7+
8+
Increments the version number in our pubspec and changelog.
9+
EOF
10+
exit 2
11+
}
12+
13+
shift && usage;
14+
15+
date="$(date --iso)"
16+
17+
old_version_int="$(perl -lne '
18+
print $1 if (/^version: 0\.0\.(\d+)\+\1$/);
19+
' pubspec.yaml)"
20+
version_int=$(( old_version_int + 1 ))
21+
version_name="0.0.${version_int}"
22+
tag_name=v"${version_name}"
23+
24+
had_uncommitted=
25+
if ! git diff-index --quiet HEAD; then
26+
had_uncommitted=1
27+
fi
28+
29+
perl -i -0pe '
30+
s<^version: \K0\.0\.(\d+)\+\1$>
31+
<0.0.'"${version_int}"'+'"${version_int}"'>m;
32+
' pubspec.yaml
33+
34+
perl -i -0pe '
35+
s/^\#\#\ Unreleased\n\K
36+
/
37+
38+
## '"${version_name}"' ('"${date}"')
39+
/xms
40+
' docs/changelog.md
41+
42+
msg="version: Bump version to $version_name"
43+
44+
if [ -n "$had_uncommitted" ]; then
45+
{
46+
echo "There were uncommitted changes. To commit:"
47+
echo " git commit -am ${msg@Q}"
48+
# NB if tempted to use the ${...@Q} feature: it's new in bash 4.4,
49+
# released 2016-09, found in stretch and bionic but not xenial.
50+
echo
51+
echo "Then tag the commit:"
52+
echo " git tag ${tag_name}"
53+
echo "inspect the result, and push:"
54+
echo " git push origin main ${tag_name}"
55+
} >&2
56+
exit 1
57+
fi
58+
59+
git commit -am "$msg"
60+
61+
git tag "${tag_name}"
62+
63+
{
64+
echo
65+
echo "Committed and tagged."
66+
echo "Inspect the result, then push; for example:"
67+
echo " git push origin main ${tag_name}"
68+
} >&2

0 commit comments

Comments
 (0)