-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreate-tag.sh
executable file
·74 lines (52 loc) · 1.58 KB
/
create-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
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/sh
set -e
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
NC='\033[0m'
# This script creates an annotated tag in the git repository
# Check if the user is in the osrd-ui folder
if [[ "$(pwd)" != *"/osrd-ui" ]]; then
echo -e "❌ ${YELLOW}You need to be in the osrd-ui folder to launch this script${NC}"
exit 1
fi
# Check if the tag name is provided
if [ -z "$1" ]; then
echo -e "${GREEN}Please provide the tag name${NC}"
exit 1
fi
# Check if the tag name is in the format 1.0.0
if ! echo "$1" | grep -q "^[0-9]\+\.[0-9]\+\.[0-9]\+$"; then
echo -e "❌ ${YELLOW}Tag name should be in the format 1.0.0${NC}"
exit 1
fi
# Fetch only tags
git fetch origin 'refs/tags/*:refs/tags/*'
# Check if the tag already exists
if git tag --list | grep -q "^$1$"; then
echo -e "❌ ${YELLOW}Tag $1 already exists${NC}"
exit 1
fi
echo "${GREEN}Creating tag $1 ${NC}"
# Create the tag
git tag -a "$1" -m "v$1"
# check if the tag is created
if [ "$?" -eq 0 ]; then
echo -e "✅ ${GREEN}Tag $1 created successfully${NC}"
else
echo -e "❌ ${YELLOW}Failed to create tag $1 ${NC}"
exit 1
fi
# prompt the user to push the tag to the remote repository
read -p "Your tag $1 has been created. Do you want to push it to the remote repository? (y/n) " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
git push origin "$1"
if [ "$?" -eq 0 ]; then
echo -e "✅ ${GREEN}Tag $1 pushed to the remote repository${NC}"
else
echo -e "❌ ${YELLOW}Failed to push tag $1 to the remote repository${NC}"
exit 1
fi
else
echo -e "${GREEN}You can push the tag later by running git push origin $1${NC}"
fi