-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbump_version.sh
More file actions
71 lines (58 loc) · 1.64 KB
/
bump_version.sh
File metadata and controls
71 lines (58 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
cargo_file="Cargo.toml"
function validate_semversion() {
version=$1
if [[ "${version}" =~ ^v.+$ ]]; then
version="${version:1}"
else
echo "bad version: ${version}"
exit 1
fi
if [[ "${version}" =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$ ]]; then
echo "${version}"
else
echo "bad version: ${version}"
exit 1
fi
}
function bump_version_usage() {
echo
echo "Usage: bump_version.sh [OPTIONS] VERSION_OLD VERSION_NEW"
echo
echo "bump the cargo version through the package."
echo
echo "Options:"
echo " -v Verbose output, prints errors and echos the raw version on success"
echo " -t Run tests for this script"
echo " -h Print usage"
echo
echo "Run like: bump_version.sh -v v0.5.5 v0.5.6"
echo
echo
}
function bump_version() {
test=0
verbose=0
while getopts ":vt" opt; do
case $opt in
t) test=1
;;
v) verbose=1
;;
\?) echo "Invalid option -$OPTARG" >&2; echo; bump_version_usage; exit 1
;;
esac
done
shift $(($OPTIND - 1))
version_old=$1
version_new=$2
semver_old=$(validate_semversion "${version_old}")
semver_new=$(validate_semversion "${version_new}")
line_old="version = \"${semver_old}\""
line_new="version = \"${semver_new}\""
find . -type f -name "${cargo_file}" -exec perl -pi \
-e "s|${line_old}|${line_new}|g;" \
{} +
echo "bump version from ${semver_old} to ${semver_new} ..."
}
bump_version "$@"