-
Notifications
You must be signed in to change notification settings - Fork 27
/
publish.sh
38 lines (29 loc) · 956 Bytes
/
publish.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
#!/bin/bash
versionPattern="[0-9]+\.[0-9]+\.[0-9]+(\-beta)*"
tagName=""
while [[ ! $tagName =~ $versionPattern ]]; do
read -p "Tag name (version): " tagName
done
if ! grep -Fq "\"version\": \"$tagName\"," ./package.json; then
echo -e "$(tput setaf 1)WOW, wait! The provided tag does not match the packagon.json version$(tput sgr0)"
exit 1
fi
# REDEFINE THE TAG NAME (prefixed with 'v')
tagName=v$tagName
if GIT_DIR=./.git git rev-parse $tagName >/dev/null 2>&1
then
echo -e "$(tput setaf 1)ERROR: Tag $tagName already exists$(tput sgr0)"
fi
if git tag $tagName; then
echo -e "$(tput setaf 2)Tag created$(tput sgr0)"
else
echo -e "$(tput setaf 1)ERROR: Failed to create tag locally$(tput sgr0)"
exit 1
fi
if git push origin $tagName; then
echo -e "$(tput setaf 2)Tag pushed$(tput sgr0)"
else
echo -e "$(tput setaf 1)ERROR: Failed to push tag$(tput sgr0)"
exit 1
fi
echo -e "$(tput setaf 2)Everything went fine :)$(tput sgr0)"