-
Notifications
You must be signed in to change notification settings - Fork 0
/
push.sh
75 lines (61 loc) · 1.54 KB
/
push.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
#!/bin/bash
#
# CONFIG VARS
#
# The path (relative to this script) to the version file this script will update before pushing
VERSIONFILE='package.json'
# The git branch name where this script will push
BRANCH='main'
#
# BEGIN
#
# Go to push.sh dir
currentDir=$(pwd)
cd $(dirname $0)
# Retrieving current version
currentVersion=$(cat $VERSIONFILE | grep version | tr -d \"\':,[:space:][:alpha:])
if [[ -z $currentVersion ]]
then
echo Error : cannot retrieve the version number.
exit -1
fi
currMaj=$(echo $currentVersion | cut -d"." -f1)
currMin=$(echo $currentVersion | cut -d"." -f2)
currPatch=$(echo $currentVersion | cut -d"." -f3)
# Asking user for kind of update
echo Current version : $currentVersion
echo ---
echo Which type of new version to push ?
echo Major [M] ? Minor [m] ? Patch [Anything else] ?
echo Type [A] to abort push.
read userInput
if [[ -n $userInput ]] && ([[ $userInput = "A" ]] || [[ $userInput = "a" ]])
then
echo Push aborted by user.
exit 0
fi
# Updating version number in $VERSIONFILE
if [[ -n $userInput ]] && [[ $userInput = "M" ]]
then
currMaj=$((currMaj+1))
currMin=0
currPatch=0
elif [[ -n $userInput ]] && [[ $userInput = "m" ]]
then
currMin=$((currMin+1))
currPatch=0
else
currPatch=$((currPatch+1))
fi
nextVersion="$currMaj.$currMin.$currPatch"
sed -i "s/$currentVersion/$nextVersion/g" $VERSIONFILE
# Push to git repo
echo Pushing version $nextVersion
git add .
git commit -a -m "Pushing version $nextVersion"
git push origin $BRANCH
echo Version $nextVersion successfuly pushed!
cd $currentDir
#
# END
#