-
Notifications
You must be signed in to change notification settings - Fork 1
/
release_tag.sh
executable file
·101 lines (78 loc) · 1.85 KB
/
release_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
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
#!/bin/bash
# Script to simplify the release flow.
# 1) Fetch the current release version
# 2) Increase the version (major, minor, patch)
# 3) Add a new git tag
# 4) Push the tag
# Parse command line options.
while getopts ":Mmpd" Option
do
case $Option in
M ) major=true;;
m ) minor=true;;
p ) patch=true;;
d ) dry=true;;
esac
done
shift $(($OPTIND - 1))
# Display usage
if [ -z $major ] && [ -z $minor ] && [ -z $patch ];
then
echo "usage: $(basename $0) [Mmp] [message]"
echo ""
echo " -d Dry run"
echo " -M for a major release"
echo " -m for a minor release"
echo " -p for a patch release"
echo ""
echo " Example: release -p \"Some fix\""
echo " means create a patch release with the message \"Some fix\""
exit 1
fi
# 1) Fetch the current release version
echo "Fetch tags"
git fetch --prune --tags
version=$(git describe --abbrev=0 --tags)
version=${version:1} # Remove the v in the tag v0.37.10 for example
echo "Current version: $version"
# 2) Increase version number
# Build array from version string.
a=( ${version//./ } )
# Increment version numbers as requested.
if [ ! -z $major ]
then
((a[0]++))
a[1]=0
a[2]=0
fi
if [ ! -z $minor ]
then
((a[1]++))
a[2]=0
fi
if [ ! -z $patch ]
then
((a[2]++))
fi
next_version="${a[0]}.${a[1]}.${a[2]}"
username=$(git config user.name)
msg="$1"
# If its a dry run, just display the new release version number
if [ ! -z $dry ]
then
echo "Tag message: $msg"
echo "Next version: v$next_version"
else
# If a command fails, exit the script
set -e
# Push main
git push origin main
# If it's not a dry run, let's go!
# 3) Add git tag
echo "Add git tag v$next_version with message: $msg"
git tag -a "v$next_version" -m "$msg"
# 4) Push the new tag
echo "Push the tag"
git push --tags origin main
echo -e "\e[32mRelease done: $next_version\e[0m"
fi