-
Notifications
You must be signed in to change notification settings - Fork 1
/
bumpversion.sh
executable file
·88 lines (69 loc) · 3.13 KB
/
bumpversion.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
#!/bin/bash
# #
# ____ ____ ___ __ #
# / __ \____ ___ ____ / __ \/ (_) /_____ _____ #
# / / / / __ \/ _ \/ __ \/ / / / / / __/ __ \/ ___/ OpenOlitor #
# / /_/ / /_/ / __/ / / / /_/ / / / /_/ /_/ / / contributed by tegonal #
# \____/ .___/\___/_/ /_/\____/_/_/\__/\____/_/ http://openolitor.ch #
# /_/ #
# #
# This program is free software: you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by #
# the Free Software Foundation, either version 3 of the License, #
# or (at your option) any later version. #
# #
# This program is distributed in the hope that it will be useful, but #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY #
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program. If not, see http://www.gnu.org/licenses/ #
# #
# #
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-v|--version)
VERSION="$2"
shift
;;
-c|--commit)
COMMIT=true
shift
;;
*)
;;
esac
shift
done
VERSION_REGEX="version.*?\K(\d+)\.(\d+)\.(\d+)(-SNAPSHOT)?"
CURRENT_VERSION="$(grep -Po $VERSION_REGEX package.json)"
echo "Current version is: "$CURRENT_VERSION
IFS='.-' read V1 V2 V3 SNAPSHOT <<< $CURRENT_VERSION
if [ -n "$SNAPSHOT" ]
then
SNAPSHOT="-$SNAPSHOT"
fi
NEXT_VERSION="$V1.$V2."$(($V3 + 1))$SNAPSHOT
VERSION=${VERSION:-$NEXT_VERSION}
COMMIT=${COMMIT:-false}
PACKAGE_JSON=$(cat package.json | perl -pe 's/'$VERSION_REGEX'/'$VERSION'/g')
BOWER_JSON=$(cat bower.json | perl -pe 's/'$VERSION_REGEX'/'$VERSION'/g')
CONFIG_JSON=$(cat app/environments/config.json | perl -pe 's/'$VERSION_REGEX'/'$VERSION'/g')
echo "$PACKAGE_JSON" > package.json
echo "$BOWER_JSON" > bower.json
echo "$CONFIG_JSON" > app/environments/config.json
echo "Updated the version to: $VERSION"
MESSAGE="bumped version to $VERSION"
echo $MESSAGE
if [[ $COMMIT == true ]]
then
( git commit -am "$MESSAGE" && git tag -a $VERSION -m "$MESSAGE" )
echo "You may now do 'git push && git push origin $VERSION'"
else
echo "The changes have been made"
echo "Commit your changes 'git commit -a -m \"$MESSAGE\" && git tag -a $VERSION -m \"$MESSAGE\"'"
echo "After that use 'git push && git push origin $VERSION' to push everything to origin"
fi