This repository has been archived by the owner on Jun 7, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
release.sh
executable file
·195 lines (165 loc) · 4.62 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
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/bin/sh
LAST_TAG=`git describe --tags --abbrev=0`
COMMITS=`git log $LAST_TAG..HEAD --pretty=oneline --abbrev-commit`
if [ "$COMMITS" = "" ]; then
echo "Release aborted: I see no work."
exit 1
fi
grep '^\s*"lint":' package.json > /dev/null 2>&1
if [ $? -eq 0 ]; then
npm run lint
if [ $? -ne 0 ]; then
echo "Release aborted: Lint failed."
exit 1
fi
fi
grep '^\s*"test":' package.json > /dev/null 2>&1
if [ $? -eq 0 ]; then
npm t
if [ $? -ne 0 ]; then
echo "Release aborted: Tests failed."
exit 1
fi
fi
grep '^\s*"minify":' package.json > /dev/null 2>&1
if [ $? -eq 0 ]; then
npm run minify
if [ $? -ne 0 ]; then
echo "Release aborted: Minification failed."
exit 1
fi
fi
while read -r COMMIT; do
HASH=`echo "$COMMIT" | cut -d ' ' -f 1`
MESSAGE=`echo "$COMMIT" | cut -d ':' -f 2- | awk '{$1=$1};1'`
TYPE=`echo "$COMMIT" | cut -d ' ' -f 2 | awk '{$1=$1};1' | cut -d ':' -f 1 | cut -d '(' -f 1 | awk '{$1=$1};1'`
AREA=`echo "$COMMIT" | cut -d '(' -f 2 | cut -d ')' -f 1 | awk '{$1=$1};1'`
if [ "$AREA" = "$COMMIT" ]; then
AREA=""
fi
if [ "$AREA" != "" ]; then
AREA="$AREA: "
fi
case $TYPE in
"break"|"breaking")
BUILD_TYPE="Major"
if [ "$BREAK_SUMMARY" = "" ]; then
BREAK_SUMMARY="### Breaking changes\n"
fi
BREAK_SUMMARY="$BREAK_SUMMARY\n* $AREA$MESSAGE ($HASH)"
;;
"feat"|"feature")
if [ "$BUILD_TYPE" != "Major" ]; then
BUILD_TYPE="Minor"
fi
if [ "$FEAT_SUMMARY" = "" ]; then
FEAT_SUMMARY="### New features\n"
fi
FEAT_SUMMARY="$FEAT_SUMMARY\n* $AREA$MESSAGE ($HASH)"
;;
"fix")
if [ "$FIX_SUMMARY" = "" ]; then
FIX_SUMMARY="### Bug fixes\n"
fi
FIX_SUMMARY="$FIX_SUMMARY\n* $AREA$MESSAGE ($HASH)"
;;
"perf"|"performance")
if [ "$PERF_SUMMARY" = "" ]; then
PERF_SUMMARY="### Performance improvements\n"
fi
PERF_SUMMARY="$PERF_SUMMARY\n* $AREA$MESSAGE ($HASH)"
;;
"refactor")
if [ "$REFACTOR_SUMMARY" = "" ]; then
REFACTOR_SUMMARY="### Refactorings\n"
fi
REFACTOR_SUMMARY="$REFACTOR_SUMMARY\n* $AREA$MESSAGE ($HASH)"
;;
*)
if [ "$OTHER_SUMMARY" = "" ]; then
OTHER_SUMMARY="### Other changes\n"
fi
OTHER_SUMMARY="$OTHER_SUMMARY\n* $AREA$MESSAGE ($HASH)"
;;
esac
done <<< "$COMMITS"
if [ "$BUILD_TYPE" != "Major" -a "$BUILD_TYPE" != "Minor" ]; then
BUILD_TYPE="Patch"
fi
if [ "$BREAK_SUMMARY" != "" ]; then
BREAK_SUMMARY="$BREAK_SUMMARY\n\n"
fi
if [ "$FEAT_SUMMARY" != "" ]; then
FEAT_SUMMARY="$FEAT_SUMMARY\n\n"
fi
if [ "$FIX_SUMMARY" != "" ]; then
FIX_SUMMARY="$FIX_SUMMARY\n\n"
fi
if [ "$PERF_SUMMARY" != "" ]; then
PERF_SUMMARY="$PERF_SUMMARY\n\n"
fi
if [ "$REFACTOR_SUMMARY" != "" ]; then
REFACTOR_SUMMARY="$REFACTOR_SUMMARY\n\n"
fi
if [ "$OTHER_SUMMARY" != "" ]; then
OTHER_SUMMARY="$OTHER_SUMMARY\n\n"
fi
SUMMARY="$BREAK_SUMMARY$FEAT_SUMMARY$FIX_SUMMARY$PERF_SUMMARY$REFACTOR_SUMMARY$OTHER_SUMMARY"
MAJOR=`echo "$LAST_TAG" | cut -d '.' -f 1`
MINOR=`echo "$LAST_TAG" | cut -d '.' -f 2`
PATCH=`echo "$LAST_TAG" | cut -d '.' -f 3`
SED_FRIENDLY_LAST_TAG="$MAJOR\\.$MINOR\\.$PATCH"
case $BUILD_TYPE in
"Major")
MAJOR=`expr $MAJOR + 1`
MINOR=0
PATCH=0
;;
"Minor")
MINOR=`expr $MINOR + 1`
PATCH=0
;;
"Patch")
PATCH=`expr $PATCH + 1`
;;
esac
NEW_TAG="$MAJOR.$MINOR.$PATCH"
if [ -f bower.json ]; then
sed -i '' "s/\"version\": \"$LAST_TAG\"/\"version\": \"$NEW_TAG\"/" bower.json
fi
if [ -f component.json ]; then
sed -i '' "s/\"version\": \"$LAST_TAG\"/\"version\": \"$NEW_TAG\"/" component.json
fi
if [ -f package.json ]; then
sed -i '' "s/\"version\": \"$LAST_TAG\"/\"version\": \"$NEW_TAG\"/" package.json
fi
if [ -f setup.py ]; then
sed -i '' "s/$SED_FRIENDLY_LAST_TAG/$NEW_TAG/g" setup.py
fi
if [ -f CHANGELOG.md ]; then
LOG="CHANGELOG.md"
elif [ -f CHANGES.md ]; then
LOG="CHANGES.md"
elif [ -f HISTORY.md ]; then
LOG="HISTORY.md"
elif [ -f CHANGELOG.txt ]; then
LOG="CHANGELOG.txt"
elif [ -f CHANGES.txt ]; then
LOG="CHANGES.txt"
elif [ -f HISTORY.txt ]; then
LOG="HISTORY.txt"
elif [ -f CHANGELOG ]; then
LOG="CHANGELOG"
elif [ -f CHANGES ]; then
LOG="CHANGES"
elif [ -f HISTORY ]; then
LOG="HISTORY"
fi
if [ "$LOG" != "" ]; then
TEMP="__please_release_me_$LOG.$NEW_TAG.tmp"
awk "{ gsub(/^## $LAST_TAG$/, \"## $NEW_TAG\n\n$SUMMARY## $LAST_TAG\") }; { print }" "$LOG" > "$TEMP"
mv "$TEMP" "$LOG"
fi
GIT_FRIENDLY_SUMMARY=`echo "$SUMMARY" | sed "s/#//g" | sed "s/^ //"`
git commit -a -m "release: $NEW_TAG"
git tag -a "$NEW_TAG" -m "`echo \"$BUILD_TYPE release $NEW_TAG\\n\\n$GIT_FRIENDLY_SUMMARY\"`"