-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathrelease.sh
More file actions
executable file
·143 lines (120 loc) · 3.57 KB
/
Copy pathrelease.sh
File metadata and controls
executable file
·143 lines (120 loc) · 3.57 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env bash
# encoding: utf-8
# Handle release process
# Updates the VERSION.txt file and creates the tag
set -Eeuo pipefail
# Current Git branch
branch=$(git branch --show-current)
# Require master
if [[ "$branch" != "master" ]]; then
echo "Not in master exiting"
exit 1
fi
# Require the current working directory to be clean
if [[ -n "$(git status --porcelain)" ]]; then
echo "Git repository is not clean exiting"
exit 1
fi
# Require the version file
if [[ ! -f "VERSION.txt" ]]; then
echo "VERSION.txt file not found exiting"
exit 1
fi
# Parse the version file
major=$(grep "VERSION_MAJOR" VERSION.txt | cut -d" " -f2)
minor=$(grep "VERSION_MINOR" VERSION.txt | cut -d" " -f2)
patch=$(grep "VERSION_PATCH" VERSION.txt | cut -d" " -f2)
version_changed=
version_message=
gpg_sign=
parse_params() {
while :; do
case "${1-}" in
-v | --verbose) set -x ;;
--major)
major=$((major + 1))
minor=0
patch=0
version_changed=true
;;
--minor)
minor=$((minor + 1))
patch=0
version_changed=true
;;
--patch)
patch=$((patch + 1))
version_changed=true
;;
--sign)
gpg_sign=true
;;
-m | --message)
version_message="${2-}"
shift
;;
-?*)
echo "Unknown option: $1"
exit 1
;;
*) break ;;
esac
shift
done
return 0
}
parse_params "$@"
# If nothing has changed then just exit
if [[ -z $version_changed ]]; then
echo "Nothing to do"
exit 0
fi
# Sorry tag is already taken.
if [[ -n "$(git tag -l "v$major.$minor.$patch")" ]]; then
echo "Tag 'v$major.$minor.$patch' was taken"
exit 1
fi
if [[ "$patch" = 0 ]] && [[ -n "$(git tag -l "v$major.$minor")" ]]; then
echo "Tag 'v$major.$minor' was taken"
exit 1
fi
if [[ -z "$version_message" ]]; then
version_message="Version $major.$minor.$patch"
fi
echo "Ready to commit and tag a new version: $major.$minor.$patch"
echo "Version message will be: $version_message"
read -p "Ready to commit? [Y/N]: " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
# Update the version file.
perl -pi -e "s/(VERSION_MAJOR)\s+[0-9]+/\1 $major/g" VERSION.txt
perl -pi -e "s/(VERSION_MINOR)\s+[0-9]+/\1 $minor/g" VERSION.txt
perl -pi -e "s/(VERSION_PATCH)\s+[0-9]+/\1 $patch/g" VERSION.txt
if [[ -n "$gpg_sign" ]]; then
echo "Create a SIGNED release"
# Create a SIGNED release commit
git commit -a -S -m "Incrementing version number to $major.$minor.$patch"
# Tag it like a champ!
git tag -s "v$major.$minor.$patch" -m "$version_message"
else
echo "Create an UNSIGNED release"
# Create an UNSIGNED release commit
git commit -am "Incrementing version number to $major.$minor.$patch"
# Create an UNSIGNED tag
git tag -a "v$major.$minor.$patch" -m "$version_message"
fi
echo "Committed and tagged a new release"
read -p "Enter the name of the upstream remote (default: origin): " upstream -r
upstream=${upstream:-origin}
read -p "Push commit and tag to remote '$upstream'? [Y/N]: " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
git push "$upstream" HEAD
git push "$upstream" "$major.$minor.$patch"
echo "Pushed data to remote '$upstream'. Congrats!"
else
echo "You need to 'git push $upstream HEAD' and 'git push $upstream --tags' manually."
fi
else
echo "Chicken!"
fi