-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtagrelease
More file actions
executable file
·88 lines (76 loc) · 2.36 KB
/
tagrelease
File metadata and controls
executable file
·88 lines (76 loc) · 2.36 KB
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
#!/bin/bash
###############################################################################
#
# An utility script to create git tags for versioning releases.
#
# This script creates an annotated git tag for versioning releases. Version
# argument must follow semver-alike format ('1.2.3' or '1.2.3-suffix'). Tag
# name will add a 'v' prefix by default, unless --no-tag-prefix is specified.
#
# Usage: tagrelease [OPTIONS] <version>
#
# Example: tagrelease 1.2.3
# Which creates tag 'v1.2.3' with message 'Release 1.2.3'.
#
# Example: tagrelease --no-tag-prefix 1.2.3
# Which creates tag '1.2.3' with message 'Release 1.2.3'.
#
# On success, the script prints:
# info: successfully created annotated tag '<tag_name>', with message '<tag_message>'
#
###############################################################################
info() {
echo "info: $*" >&2
}
fatal() {
echo "fatal: $*" >&2
}
if [ "$1" = "--help" ] || [ "$1" = "-h" ]; then
echo "Usage: $0 [OPTIONS] <version>"
echo ""
echo "Create a git tag with version number."
echo ""
echo "Arguments:"
echo " version Version number in format: 1.2.3 or 1.2.3-suffix"
echo ""
echo "Options:"
echo " -h, --help Show this help message"
echo " --no-tag-prefix Create tag without 'v' prefix ('1.2.3' instead of 'v1.2.3')"
echo ""
echo "Examples:"
echo " $0 1.2.3"
echo " $0 2.0.0-beta"
echo " $0 --no-tag-prefix 1.2.4"
echo ""
echo "This will create an annotated tag 'v<version>' with message 'Release <version>'."
exit 0
fi
no_tag_prefix=false
if [ "$1" = "--no-tag-prefix" ]; then
no_tag_prefix=true
shift
fi
if [ $# -ne 1 ]; then
fatal "exactly one argument required"
fatal "usage: $0 [OPTIONS] <version>"
fatal "version format: 1.2.3 or 1.2.3-suffix"
exit 1
fi
version="$1"
if ! [[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?$ ]]; then
fatal "invalid version format, provided: '$version', expected pattern: '1.2.3' or '1.2.3-suffix'"
exit 1
fi
if [ "$no_tag_prefix" = true ]; then
tag_name="${version}"
else
tag_name="v${version}"
fi
tag_message="Release ${version}"
git tag -a "$tag_name" -m "$tag_message"
if [ $? -eq 0 ]; then
info "successfully created annotated tag '$tag_name', with message '$tag_message'"
else
fatal "failed to create tag"
exit 1
fi