forked from onflow/cadence
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bump-version.sh
executable file
·46 lines (36 loc) · 987 Bytes
/
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
#!/bin/bash
# Read the version to be replaced from the `version.go` file.
v=$(sed -En 's/const Version = "v(.*)"/\1/p' version.go)
case "$1" in
major)
v2=$(echo "$v" | awk -F. '{print $1 + 1 ".0.0"}')
;;
minor)
v2=$(echo "$v" | awk -F. '{print $1 "." $2 + 1 ".0"}')
;;
patch)
v2=$(echo "$v" | awk -F. '{print $1 "." $2 "." $3 + 1}')
;;
*)
# Trim off preceding `v` if any.
# This is to support both input version formats: `0.1.0` and `v0.1.0`.
v2=$(echo "$1" | sed -Ee 's/^v//')
;;
esac
echo "$v => $v2"
for f in $VERSIONED_FILES; do \
prevCount=$(grep -c -i "$v2" "$f")
# Replace the version.
echo "- $f"; \
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' "s/$v/$v2/g" "$f"; \
else
sed -i "s/$v/$v2/g" "$f"; \
fi
# Check if the version has being properly replaced.
newCount=$(grep -c -i "$v2" "$f")
if [[ $newCount -le $prevCount ]]; then
echo "fail to update version in '$f'"
exit 1
fi
done