forked from rickyah/ini-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bump-version
executable file
·83 lines (63 loc) · 1.76 KB
/
bump-version
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
function print_help_and_quit {
echo "Usage: $0 --update <new_version> [<AssemblyInfo file path>]"
echo "Usage: $0 --list [<AssemblyInfo file path>]"
exit -1
}
if [ $# -eq 0 ]
then
print_help_and_quit
fi
while [[ $# > 0 ]]
do
key="$1"
case $key in
--list)
COMMAND="list"
FILE_PATH=$2
shift;
;;
--update)
COMMAND="update"
NEW_VERSION=$2
FILE_PATH=$3
;;
esac
shift # past argument or value
done
LIST_CMD='grep -E "\[assembly: AssemblyVersion(".*")\]" $FILE_PATH'
VERSION_REGEX1='\[assembly: AssemblyVersion\("(.*)"\)\]'
VERSION_REGEX2='\[assembly: AssemblyFileVersion\("(.*)"\)\]'
if [ -z "$COMMAND" ]
then
print_help_and_quit
fi
# set a default value for FILE_PATH if none passed as argument
case $COMMAND in
list)
if [ -z "$FILE_PATH" ]
then
FILE_PATH="./src/IniFileParser/Properties/AssemblyInfo.cs"
fi
eval $LIST_CMD
;;
update)
if [ -z "$NEW_VERSION" ] && [ -z "$FILE_PATH" ]
then
print_help_and_quit
fi
if [ -z "$FILE_PATH" ]
then
FILE_PATH="./src/IniFileParser/Properties/AssemblyInfo.cs"
fi
NEW_VERSION_REPLACE1='\[assembly: AssemblyVersion\("'$NEW_VERSION'"\)\]'
NEW_VERSION_REPLACE2='\[assembly: AssemblyFileVersion\("'$NEW_VERSION'"\)\]'
echo "Changing file $FILE_PATH to version $NEW_VERSION"
printf "Old value: "
eval $LIST_CMD
eval "sed -r --in-place 's/$VERSION_REGEX1/$NEW_VERSION_REPLACE1/g;' $FILE_PATH"
eval "sed -r --in-place 's/$VERSION_REGEX2/$NEW_VERSION_REPLACE2/g;' $FILE_PATH"
printf "New value: "
eval $LIST_CMD
;;
esac
exit 0