Skip to content

Commit a42dd63

Browse files
committed
tools/bump-version: Better centralize version format; handle mismatch
This is NFC except in its handling of errors. I haven't been using this script since the app launched (and have instead done its work manually), because it assumes the version numbers are 0.0.N+N. After this commit, it's a small local change to make the script handle the new 30.0.N+N version numbers, and the script will also fail cleanly if we ever change the format again.
1 parent fc74293 commit a42dd63

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

tools/bump-version

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env bash
2-
set -e
2+
set -eu
33

44
usage () {
55
cat <<EOF >&2
@@ -12,13 +12,23 @@ EOF
1212

1313
shift && usage;
1414

15+
major_version=0
16+
minor_version=0
17+
pub_version_regexp="${major_version}\.${minor_version}\.(\d+)\+\1"
18+
1519
date="$(date --iso)"
1620

1721
old_version_int="$(perl -lne '
18-
print $1 if (/^version: 0\.0\.(\d+)\+\1$/);
22+
print $1 if (/^version: '"${pub_version_regexp}"'$/);
1923
' pubspec.yaml)"
24+
if [ -z "${old_version_int}" ]; then
25+
echo >&2 "error: failed to parse current version in pubspec.yaml"
26+
exit 1
27+
fi
28+
2029
version_int=$(( old_version_int + 1 ))
21-
version_name="0.0.${version_int}"
30+
version_name="${major_version}.${minor_version}.${version_int}"
31+
pub_version="${version_name}+${version_int}"
2232
tag_name=v"${version_name}"
2333

2434
had_uncommitted=
@@ -27,8 +37,8 @@ if ! git diff-index --quiet HEAD; then
2737
fi
2838

2939
perl -i -0pe '
30-
s<^version: \K0\.0\.(\d+)\+\1$>
31-
<0.0.'"${version_int}"'+'"${version_int}"'>m;
40+
s<^version: \K'"${pub_version_regexp}"'$>
41+
<'"${pub_version}"'>m;
3242
' pubspec.yaml
3343

3444
perl -i -0pe '

0 commit comments

Comments
 (0)