forked from FooSoft/yomichan
-
Notifications
You must be signed in to change notification settings - Fork 107
/
tag.sh
executable file
·61 lines (51 loc) · 1.59 KB
/
tag.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
#!/usr/bin/env bash
# bash script which tags the current commit with a calver version
# and pushes the tag to the remote repository
# Define color codes
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
if [[ $(git branch --show-current) != "master" ]]; then
echo -e "${RED}Please only tag commits on master branch.${NC}"
exit 1
fi
echo -e "${YELLOW}Checking if branch is up to date...${NC}"
changed=0
git remote update origin && git status -uno | grep -q 'Your branch is behind' && changed=1
if [ $changed = 1 ]; then
echo -e "${RED}Please git pull before tagging.${NC}"
exit 1
fi
# Ask user to confirm the commit and the tag name
echo -e "${YELLOW}Current HEAD of master branch:${NC}"
git log -1 --decorate
echo
# get the current date in the format YY.MM.DD
DATE=$(date +%y.%-m.%-d)
# Check if the tag already exists and increment if necessary
COUNTER=0
TAG=$DATE.$COUNTER
while git rev-parse "$TAG" >/dev/null 2>&1; do
# Increment the counter and recreate TAG with DATE
echo -e "${YELLOW}Tag $TAG already exists, incrementing.${NC}"
COUNTER=$((COUNTER + 1))
TAG="$DATE.$COUNTER"
done
echo
echo -e -n "${YELLOW}Tagging current HEAD of master with tag ${TAG}. Are you sure? (y/n): ${NC}"
read -p "" -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo -e "${RED}Tagging aborted.${NC}"
exit 1
fi
git tag $TAG
echo -e -n "${YELLOW}Do you want to push the tag ${TAG} to the remote repository (which will cause a pre-release to get created)? (y/n): ${NC}"
read -p "" -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo -e "${RED}Push aborted.${NC}"
exit 1
fi
git push origin $TAG