-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
bump-version.sh
executable file
·96 lines (87 loc) · 2.62 KB
/
bump-version.sh
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/bin/sh
set -efu
# the list of files that need to have the version updated in them
#
# limitations:
# * no newlines in names
# * no ' char in names
files="
README.md
kotlinx-coroutines-core/README.md
kotlinx-coroutines-debug/README.md
kotlinx-coroutines-test/README.md
ui/coroutines-guide-ui.md
gradle.properties
integration-testing/gradle.properties
"
# read gradle.properties to get the old version
set +e
old_version="$(git grep -hoP '(?<=^version=).*(?=-SNAPSHOT$)' gradle.properties)"
set -e
if [ "$?" -ne 0 ]
then
echo "Could not read the old version from gradle.properties." >&2
if [ "$#" -ne 2 ]
then
echo "Please use this form instead: ./bump-version.sh old_version new_version"
exit 1
fi
fi
# check the command-line arguments for mentions of the version
if [ "$#" -eq 2 ]
then
echo "If you want to infer the version automatically, use the form: ./bump-version.sh new_version" >&2
if [ -n "$old_version" -a "$1" != "$old_version" ]
then
echo "The provided old version ($1) is different from the one in gradle.properties ($old_version)." >&2
echo "Proceeding anyway with the provided old version." >&2
fi
old_version=$1
new_version=$2
elif [ "$#" -eq 1 ]
then
new_version=$1
else
echo "Use: ./bump-version.sh new_version" >&2
exit 1
fi
# Escape dots, e.g. 1.0.0 -> 1\.0\.0
escaped_old_version="$(printf "%s\n" "$old_version" | sed 's/[.]/\\./g')"
update_version() {
file=$1
to_undo=$2
echo "Updating version from '$old_version' to '$new_version' in $1" >&2
if [ -n "$(git diff --name-status -- "$file")" ]
then
printf "There are unstaged changes in '$file'. Refusing to proceed.\n" >&2
[ -z "$to_undo" ] || eval "git checkout$to_undo"
exit 1
fi
sed -i.bak "s/$escaped_old_version/$new_version/g" "$file"
rm -f "$1.bak"
}
to_undo=$(printf "%s" "$files" | while read -r file; do
if [ -n "$file" ]
then
update_version "$file" "${to_undo:-}"
to_undo="${to_undo:-} '$file'"
echo -n " '$file'"
fi
done)
set +e
version_mentions=$(
find . -type f \( -iname '*.properties' -o -iname '*.md' \) \
-not -iname CHANGES.md -not -iname CHANGES_UP_TO_1.7.md \
-not -path ./integration/kotlinx-coroutines-jdk8/README.md \
-exec git grep --fixed-strings --word "$old_version" {} +
)
set -e
if [ -z "$version_mentions" ]
then
echo "Done. To undo, run this command:" >&2
printf "git checkout%s\n" "$to_undo" >&2
else
echo "ERROR: Previous version is present in the project: $version_mentions"
[ -z "$to_undo" ] || eval "git checkout$to_undo"
exit 1
fi