-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.sh
executable file
·202 lines (171 loc) · 5.68 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
195
196
197
198
199
200
201
202
#!/bin/bash
VERSION=`node -e "console.log(require('./package').version);"`
IFS=. read MAJOR MINOR PATCH <<< "${VERSION}"
OPTION_NO_ACT=false
OPTION_REMOTE_REPO='adminion'
OPTION_RELEASE_SUFFIX=
OPTION_VERBOSE=false
CURRENT_BRANCH_PATTERN='^\* .+$'
MAJOR_BRANCH_PATTERN='v[0-9].x'
SCRATCH_FILE='./.git-branch-output'
CURRENT_BRANCH=`git branch | egrep "${CURRENT_BRANCH_PATTERN}" | sed s/\*\ // -`
releaseType='patch'
usage() {
echo "Usage: release-helper [ [ --option-1 [...]] ] [ major | minor | (patch) ] "
echo
echo "Options: "
echo " -h, --help Display this help message "
echo " -m, --meta SUFFIX Alias of -s, --suffix "
echo " -n, --no-act Don't actually do anything, just output what "
echo " would be done without this flag. "
echo " -o, --output-only Alias of -n, --no-act "
echo " -p, --push-to-remote REMOTE Push the new release to REMOTE "
echo " -r, --remote REMOTE Alias of -p, --push-to-remote "
echo " -s, --suffix SUFFIX Append SUFFIX to the release name (i.e. -alpha1)"
echo " -v, --verbose Enable verbose output "
echo
}
major_release() {
RELEASE="v${VERSION}"
BRANCH="v${MAJOR}.x"
WORKING_ON="v`expr ${MAJOR} + 1`.0.0"
echo "Building release ${RELEASE}..."
if $OPTION_VERBOSE
then
echo "RELEASE: ${RELEASE}"
echo "BRANCH: ${BRANCH}"
echo "'WORKING_ON': ${WORKING_ON}"
fi
git checkout -b release-$RELEASE
sed -i "4i # ${BRANCH}\n\n## ${RELEASE}\n`changelog-maker`\n" CHANGES.md
npm update
# npm test
# npm run coverage
# npm run docs
git commit -a -m "release ${RELEASE}"
git checkout master
git merge release-$RELEASE
git branch -d release-$RELEASE
git tag $RELEASE
git branch $BRANCH
git push $OPTION_REMOTE_REPO $RELEASE $BRANCH
# npm publish
npm --no-git-tag-version version major
git commit -a -m "working on ${WORKING_ON}"
}
minor_release() {
RELEASE="v$MAJOR.`expr $MINOR + 1`.0"
BRANCH="v${MAJOR}.x"
WORKING_ON="v$MAJOR.`expr $MINOR + 1`.1"
echo "Building release ${RELEASE}..."
if $OPTION_VERBOSE
then
echo "RELEASE: ${RELEASE}"
echo "BRANCH: ${BRANCH}"
echo "'WORKING_ON': ${WORKING_ON}"
fi
git checkout -b release-$RELEASE
npm --no-git-tag-version version minor
sed -i "6i ## ${RELEASE}\n`changelog-maker`\n" CHANGES.md
# npm update
# npm test
# npm run coverage
# npm run docs
git commit -a -m "release ${RELEASE}"
git checkout $BRANCH
git merge release-$RELEASE
git branch -d release-$RELEASE
git tag $RELEASE
git push $OPTION_REMOTE_REPO $RELEASE $BRANCH
# npm publish
npm --no-git-tag-version version patch
git commit -a -m "working on ${WORKING_ON}"
}
patch_release() {
RELEASE="v$VERSION"
BRANCH="v${MAJOR}.x"
WORKING_ON="v${MAJOR}.${MINOR}.`expr ${PATCH} + 1`"
echo "Building release ${RELEASE}..."
if $OPTION_VERBOSE
then
echo "RELEASE: ${RELEASE}"
echo "BRANCH: ${BRANCH}"
echo "'WORKING_ON': ${WORKING_ON}"
fi
git checkout -b release-$RELEASE
sed -i "6i ## ${RELEASE}\n`changelog-maker`\n" CHANGES.md
# npm update
# npm test
# npm run coverage
# npm run docs
git commit -a -m "release ${RELEASE}"
git checkout $BRANCH
git merge release-$RELEASE
git branch -d release-$RELEASE
git tag $RELEASE
git push $OPTION_REMOTE_REPO $RELEASE $BRANCH
# npm publish
npm --no-git-tag-version version patch
git commit -a -m "working on ${WORKING_ON}"
}
################
# Loop until all parameters are used up
while [ "$1" != "" ]; do
case $1 in
-n | --no-act | \
-o | --output-only ) OPTION_NO_ACT=1
;;
-r | --remote | \
-p | --push-to-remote ) shift
OPTION_REMOTE_REPO=$1
;;
-m | --meta | \
-s | --suffix ) shift
OPTION_SUFFIX=$1
;;
-v | --verbose ) OPTION_VERBOSE=true
;;
-h | --help ) usage
exit
;;
major ) releaseType="major"
;;
minor ) releaseType="minor"
;;
patch ) releaseType="patch"
;;
* ) usage
exit 1
esac
# Shift all the parameters down by one
shift
done
if $OPTION_VERBOSE
then
echo "REMOTE_REPO: $OPTION_REMOTE_REPO"
echo "VERSION: $VERSION"
echo "CURRENT_BRANCH: $CURRENT_BRANCH"
fi
case "$releaseType" in
major ) if [ $CURRENT_BRANCH == "master" ]
then major_release
else
echo 'Major releases must be cut from master!'
exit 1
fi
;;
minor ) if `echo ${CURRENT_BRANCH} | egrep "${MAJOR_BRANCH_PATTERN}" 1>/dev/null 2>&1`
then minor_release
else
echo 'Minor releases must be cut from a major branch (i.e. v0.x)'
exit 1
fi
;;
patch ) if `echo ${CURRENT_BRANCH} | egrep "${MAJOR_BRANCH_PATTERN}" 1>/dev/null 2>&1`
then patch_release
else
echo 'Patch releases must be cut from a major branch (i.e. v0.x)'
exit 1
fi
;;
esac