forked from etlegacy/etlegacy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
release.sh
executable file
·130 lines (112 loc) · 2.81 KB
/
release.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
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
#!/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 symbolic-ref HEAD | sed -e 's,.*/\(.*\),\1,')
# Require master
if [ ! "$branch" = "master" ]; then
echo "Not in master exiting"
exit 1
fi
# Require the current working directory to be clean
if [ ! -z "$(git status --porcelain)" ]; then
echo "Git repository is not clean 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
;;
-?*) die "Unknown option: $1" ;;
*) break ;;
esac
shift
done
args=("$@")
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 [ $(git tag -l "v$major.$minor.$patch") ]; then
echo "Tag 'v$major.$minor.$patch' was taken"
exit 1
fi
if [ $patch = 0 ] && [ $(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 [ -z $gpg_sign ]; then
# no signing
# Create the release commit
git commit -am "Incrementing version number to $major.$minor.$patch"
# Tag it like a champ!
git tag -a "v$major.$minor.$patch" -m "$version_message"
else
# Create the release commit
git commit -a -S -m "Incrementing version number to $major.$minor.$patch"
# sign the tag
git tag -s "v$major.$minor.$patch" -m "$version_message"
fi
echo "Committed and tagged a new release"
read -p "Push commit and tag to remote? [Y/N]: " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]
then
git push origin master
git push origin "v$major.$minor.$patch"
echo "Pushed data to remote. Congrats!"
else
echo "You need to 'git push origin master' and 'git push origin --tags' manually."
fi
else
echo "Chicken!"
fi