-
Notifications
You must be signed in to change notification settings - Fork 13
/
addDevTag
executable file
·103 lines (89 loc) · 2.61 KB
/
addDevTag
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# check if we need to merge master into this branch------------
if [[ $(git log origin/master ^HEAD) ]]; then
echo "You need to merge master into this branch. Exiting"
exit 1
fi
# get version------------
version=`cat package.json | grep -e '"version":'`
while IFS='"' read -ra ADDR; do
counter=0
for i in "${ADDR[@]}"; do
if [ $counter == 3 ]
then
version=$i
fi
counter=$(($counter+1))
done
done <<< "$version"
versionLock=`head -n 3 package-lock.json | grep -e '"version":'`
while IFS='"' read -ra ADDR; do
counter=0
for i in "${ADDR[@]}"; do
if [ $counter == 3 ]
then
versionLock=$i
fi
counter=$(($counter+1))
done
done <<< "$versionLock"
# check if package and package-lock versions are similar.-----------
if ! [[ $version == $versionLock ]]
then
RED='\033[0;31m'
NC='\033[0m' # No Color
printf "${RED}Difference between package-lock and package version. Please run npm install. Stopping process${NC}\n"
exit 1
fi
# get current branch name
branch_name="$(git symbolic-ref HEAD 2>/dev/null)" ||
branch_name="(unnamed branch)" # detached HEAD
branch_name=${branch_name##refs/heads/}
# check if branch is correct based on the version-----------
if ! [[ $version == $branch_name* ]]
then
RED='\033[0;31m'
NC='\033[0m' # No Color
printf "${RED}Adding tag to wrong branch. Stopping process${NC}\n"
exit 1
fi
#Sync tags with remote
git fetch --prune --prune-tags
# GET Current Commit Hash -------
if [ $# -eq 0 ]
then
commit_hash=`git log --pretty=format:'%H' -n 1`
else
commit_hash=$1
fi
# check if current commit already has a tag or not------------
if [[ `git tag -l --points-at $commit_hash` == "" ]]
then
continue=1
else
RED='\033[0;31m'
NC='\033[0m'
printf "${RED}This commit already has a tag. Please remove that and re-run this script${NC}\n"
echo "git tag --delete <tagName>"
echo "git push --delete origin <tagName>"
exit 1
fi
# check if release version of this tag exists------------
if git rev-parse v$version >/dev/null 2>&1
then
RED='\033[0;31m'
NC='\033[0m'
printf "${RED}The released version of this tag already exists${NC}\n"
exit 1
fi
# add an empty commit if the user has not given a commit hash so that we are sure it's built------------
if [ $# -eq 0 ]
then
npm run build-pretty
npm run build-docs
git add --all
git commit --allow-empty -m"adding dev-v$version tag to this commit to ensure building"
git push
commit_hash=`git log --pretty=format:'%H' -n 1`
fi
git tag dev-v$version $commit_hash
git push --tags