-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.sh
executable file
·85 lines (79 loc) · 2.64 KB
/
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
#!/bin/bash
versionFile="./VERSION"
packageFile="./browser-lib/package.json"
packageFile2="./npm-lib/package.json"
dartFile="./dart/mag_fabrics/pubspec.yaml"
versionRegex="([0-9]+).([0-9]+).([0-9]+)"
packageRegex="\"version\": \"([0-9]+).([0-9]+).([0-9]+)\""
dartRegex="version: ([0-9]+).([0-9]+).([0-9]+)"
version=""
major=""
minor=""
patch=""
# HELP
help()
{
echo "Usage: setVersion.sh [-h] [-v] [-p] [-m] [-M]"
echo "--help: Display this help message"
echo "--version: See the version number"
echo "--bump-patch: bump the minor version"
echo "--bump-minor: bump the minor version"
echo "--bump-major: bump the major version"
}
# MAIN
while IFS='' read -r line || [[ -n "$line" ]]; do
if [[ $line =~ $versionRegex ]]; then
version=$line
major=${BASH_REMATCH[1]}
minor=${BASH_REMATCH[2]}
patch=${BASH_REMATCH[3]}
fi
done < "$versionFile"
while getopts ":hvpmM" option; do
case $option in
h) # display Help
help
exit;;
v) # see version
echo $version
exit;;
p) # bump patch
patch=$((patch+1))
replacement="$major.$minor.$patch"
packageReplacement="\"version\": \"$replacement\""
dartReplacement="version: $replacement"
sed -i.bak -E "s/$versionRegex/$replacement/" $versionFile
sed -i.bak -E "s/$packageRegex/$packageReplacement/" $packageFile
sed -i.bak -E "s/$packageRegex/$packageReplacement/" $packageFile2
sed -i.bak -E "s/$dartRegex/$dartReplacement/" $dartFile
exit;;
m) # bump minor
minor=$((minor+1))
patch=0
replacement="$major.$minor.$patch"
packageReplacement="\"version\": \"$replacement\""
dartReplacement="version: $replacement"
sed -i.bak -E "s/$versionRegex/$replacement/" $versionFile
sed -i.bak -E "s/$packageRegex/$packageReplacement/" $packageFile
sed -i.bak -E "s/$packageRegex/$packageReplacement/" $packageFile2
sed -i.bak -E "s/$dartRegex/$dartReplacement/" $dartFile
exit;;
M) # bump major
major=$((major+1))
minor=0
patch=0
replacement="$major.$minor.$patch"
packageReplacement="\"version\": \"$replacement\""
dartReplacement="version: $replacement"
sed -i.bak -E "s/$versionRegex/$replacement/" $versionFile
sed -i.bak -E "s/$packageRegex/$packageReplacement/" $packageFile
sed -i.bak -E "s/$packageRegex/$packageReplacement/" $packageFile2
sed -i.bak -E "s/$dartRegex/$dartReplacement/" $dartFile
exit;;
\?) # invalid option
echo "Invalid option"
help
exit;;
esac
done
exit 0