-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_version.sh
More file actions
57 lines (45 loc) · 1.4 KB
/
update_version.sh
File metadata and controls
57 lines (45 loc) · 1.4 KB
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
#!/bin/sh
JQ=$(which jq)
# temporary file with current and next versions.
VERSION=./builder/.version
# temporary package.json file
NPJSON=./builder/up.json
# the package.json file.
PJSON="package.json"
CURRENT_BRANCH=`git branch | grep '^*' | awk '{ print $2 }'`
if [[ "$CURRENT_BRANCH" != "master" ]]; then
echo "Bail out. Current branch is not master."
echo "Curent branch: `git branch | grep '^*' | awk '{ print $2 }'`"
exit 1;
fi
case $1 in
--update)
if [[ -z "$JQ" ]]; then
echo "jq is missing."
fi
CURRENT_VERSION=`$JQ ".version" $PJSON | cut -d\" -f2`
echo "Current version: $CURRENT_VERSION"
read -p "New version: " NEW_VERSION
if [[ ! -z "$(git tag -l | grep ${NEW_VERSION})" ]]; then
echo "Tag $NEW_VERSION already exists."
exit 1
fi
echo "$CURRENT_VERSION $NEW_VERSION" > $VERSION
;;
--commit)
CURRENT_VERSION=`awk '{ print $1 }' $VERSION`
NEW_VERSION=`awk '{ print $2 }' $VERSION`
$JQ ".version = \"${NEW_VERSION}\"" $PJSON > $NPJSON
cat $NPJSON > $PJSON
;;
--clean)
rm $VERSION $NPJSON
;;
*)
echo "usage:"
echo " --update - to set the next version."
echo " --commit - write to all necessary files."
echo " --clean - remove all temporary files."
exit 1;
;;
esac