-
Notifications
You must be signed in to change notification settings - Fork 11
/
release
executable file
·161 lines (139 loc) · 3.84 KB
/
release
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/sh
# Verify 2 args, first is release version, second is next version
if [ "$#" -ne 2 ]; then
echo "Two parameters required, first is release version, second is next version" >&2
exit 1
fi
# Verify that release version and next version are not the same
if [ "$1" = "$2" ]; then
echo "Release version cannot be the same as next version" >&2
exit 1
fi
# Verify that release version is not already released
if [ "$(git tag 2>/dev/null | grep "$1")" = "$1" ]; then
echo "Release version $1 already released" >&2
exit 1
fi
# Verify that next version is not already released
if [ "$(git tag 2>/dev/null | grep "$2")" = "$2" ]; then
echo "Next version $2 already released" >&2
exit 1
fi
# Verify that there are no any local changes
git diff-index --quiet HEAD --
if [ $? -ne 0 ]; then
echo "Local branch must be clean, please stash, commit or revert local changes"
exit 1
fi
# Checkout 'dev' branch
echo "Checkout 'dev' branch"
git checkout dev >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Failed to checkout 'dev' branch" >&2
exit 1
fi
# Pull latest changes
echo "Pull latest changes from origin"
git pull >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Failed to pull latest changes from origin" >&2
exit 1
fi
# Run gradle clean build
echo "Run 'gradle clean build'"
./gradlew clean build >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "'gradle clean build' finished with error" >&2
exit 1
fi
# Set release version
echo "Set new version to gradle.properties to $1"
sed -i "1 s/^.*$/theVersion=$1/" gradle.properties >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Set new version to gradle.properties to $1 finished with error" >&2
exit 1
fi
# Add changes to git index
echo "Add release version changes to git index"
git add -u >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Failed to add release version changes to git index" >&2
exit 1
fi
# Commit changes to git
echo "Commit release version changes"
git commit -m "Released $1" >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Failed to commit release version" >&2
exit 1
fi
# Deploy new version to repository
echo "Run 'gradle publish'"
./gradlew publish >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "'gradlew publish' finished with error" >&2
exit 1
fi
# Tag version
echo "Tag version $1"
git tag "$1" >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Failed to tag version $1" >&2
exit 1
fi
# Set next version
echo "Set new version to gradle.properties to $2"
sed -i "1 s/^.*$/theVersion=$2/" gradle.properties >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Set new version to gradle.properties to $2 finished with error" >&2
exit 1
fi
# Add changes to git index
echo "Add release version changes to git index"
git add -u >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Failed to add release version changes to git index" >&2
exit 1
fi
# Commit changes to git
echo "Commit next version changes"
git commit -m "Set version to $2 for next iteration" >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Failed to commit next version" >&2
exit 1
fi
# Push 'dev' to origin
echo "Push 'dev' changes to origin"
git push origin dev >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Failed to push 'dev' changes to origin" >&2
exit 1
fi
# Checkout master branch
echo "Checkout 'master' branch"
git checkout master >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Failed to checkout master branch" >&2
exit 1
fi
# Merge 'dev' into 'master'
echo "Merge 'dev' branch into 'master'"
git merge dev >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Failed to merge 'dev' branch into 'master'" >&2
exit 1
fi
# Push changes to origin
echo "Push 'master' changes to origin"
git push origin master >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Failed to push 'master' changes to origin" >&2
exit 1
fi
# Push tags to origin
echo "Push tags to origin"
git push --tags >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "Failed to push tags to origin" >&2
exit 1
fi