-
Notifications
You must be signed in to change notification settings - Fork 9
/
create-release
executable file
·258 lines (218 loc) · 6.55 KB
/
create-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
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/bin/bash
log()
{
echo " * $@"
}
log_info()
{
/bin/echo -e "\e[36m\e[1mI: $@\e[0m"
}
log_notice()
{
/bin/echo -e "\e[32m\e[1mN: $@\e[0m"
}
log_warn()
{
/bin/echo -e "\e[35m\e[1mW: $@\e[0m"
}
log_error()
{
/bin/echo -e "\e[31m\e[1mE: $@\e[0m"
exit 1
}
AUTO_INCREMENT=0
DCH_OPTIONS=""
NOPUSH=0
SKIP_CONFIRM=0
SKIP_EDIT=0
REMOTE=origin
usage()
{
echo "create-release"
echo
echo "Usage: $0 [OPTIONS] [VERSION]"
echo "Options:"
echo " -np|--no-push Do not push"
echo " --remote Remote (default: origin)"
echo " --skip-edit Skip changelog edit"
echo " --skip-confirm Skip confirm action"
echo " --auto-increment Auto increment version"
echo " --force-bad-version Force using bad version"
echo " -h|--help) Print help"
echo
exit 0
}
while true
do
case "$1" in
-np|--no-push) NOPUSH=1; shift 1;;
--remote) REMOTE=$2; shift 2;;
--skip-edit) SKIP_EDIT=1; shift 1;;
--skip-confirm) SKIP_CONFIRM=1; shift 1;;
--auto-increment) AUTO_INCREMENT=1; shift 1;;
--force-bad-version) DCH_OPTIONS="${DCH_OPTIONS} --force-bad-version"; shift;;
-h|--help) usage;;
*) break;;
esac
done
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
log_error "you have to run this script in a git repository"
fi
cd "$(git rev-parse --show-toplevel)"
if ! git diff-files > /dev/null || ! git diff-index --cached HEAD > /dev/null; then
log_error "you have uncommitted changes, please commit or stash them."
fi
export DEBFULLNAME=`git config user.name`
export DEBEMAIL=`git config user.email`
if [ -z "$DEBFULLNAME" -o -z "$DEBEMAIL" ]; then
log_error "please configure git user.name and user.email"
fi
if [ -f debian/control ]; then
package_name=`grep ^Source: debian/control | cut -d' ' -f2`
else
log_error "debian/control not found"
fi
if [ -d .create-release/pre-release.d ]; then
log_info "Running pre-release scripts"
run-parts .create-release/pre-release.d
if [ $? -ne 0 ]; then
/bin/echo -e "\e[31m\e[1mE: Error running pre-release scripts"
echo -n -e "\e[33m\e[1mQ: Press Enter to continue, Ctrl-C to abort ... \e[0m"
read x
fi
fi
create_changelog=1
previous_version=""
if [ -f debian/changelog ]; then
previous_version=`dpkg-parsechangelog --show-field Version 2>/dev/null`
distribution=`dpkg-parsechangelog --show-field Distribution 2>/dev/null`
create_changelog=0
fi
if [ -z "$distribution" ]; then
distribution="stable"
fi
if [ -z "$previous_version" ]; then
create_changelog=1
fi
errlog=`mktemp /tmp/create-release-XXXXX`
finish()
{
if [ -f $errlog ]; then
cat $errlog
rm -f $errlog
fi
}
trap finish EXIT
set -e
log_info "Preparing release of $package_name"
next_version=""
if [ -n "$previous_version" ]; then
log "fetching tags from remote $REMOTE ..."
git fetch $REMOTE --tags >$errlog 2>&1
log_info "Previous version: $previous_version"
cp debian/changelog debian/changelog.tmp
while true
do
dch -i --vendor molior -c debian/changelog.tmp dummy
next_version=`dpkg-parsechangelog -S version -l debian/changelog.tmp`
git_version=v$(echo "$next_version" | tr '~' '-')
if ! git tag | grep -q --fixed-strings --line-regex "$git_version"; then
break
else
log "git tag $git_version already exists"
fi
done
rm -f debian/changelog.tmp
fi
version=$1
while [ -z "$version" ]; do
if [ $AUTO_INCREMENT -eq 0 ]; then
echo -n -e "\e[33m\e[1mQ: Please enter version to be released [$next_version]: \e[0m"
read version
fi
if [ -z "$version" ]; then
version=$next_version
fi
if [ -f debian/source/format ]; then
if grep -q native debian/source/format; then
if echo "$version" | grep -q -- -; then
log_warn "debian/source/format is set to native: version may not contain '-'"
version=""
continue
fi
fi
fi
if ! echo "$version" | grep -q '^\([0-9]\+:\)\?[0-9]\+[0-9a-z.]*\([\~-][0-9a-z.\~-]*\)\?$' ; then
log_warn "Invalid Debian version specified"
echo -n -e "\e[33m\e[1mQ: Press i to ignore and continue, press Enter to change the version ... \e[0m"
read resp
if [ "$resp" = "i" ]; then
break
fi
version=""
continue
fi
git_version=v$(echo "$version" | tr '~' '-')
if ! git tag | grep -q --fixed-strings --line-regex "$git_version"; then
break
else
log "git tag $git_version already exists on $REMOTE"
version=""
fi
done
log "Updating debian/changelog "
# COMMIT_FILTER="--grep Signed-off-by"
COMMIT_FILTER=""
COMMITS=""
if [ -n "$previous_version" ]; then
COMMITS=`git log v"$(echo "$previous_version" | tr '~' '-')"..HEAD $COMMIT_FILTER --oneline 2>/dev/null || true`
fi
if [ -z "$COMMITS" ]; then
COMMITS="XXXXXXX bump version $version"
fi
echo "$COMMITS" | (
count=1
while read x
do
if [ $count -eq 1 ]; then
DCH_CREATE=""
if [ "$create_changelog" -eq 1 ]; then
DCH_CREATE="--create --package $package_name"
fi
eval dch $DCH_CREATE --force-distribution ${DCH_OPTIONS} --distribution "$distribution" --urgency=medium --newversion=$version \"$(echo "$x" | cut -d' ' -f 2-)\" >$errlog 2>&1
else
dch --append "$(echo "$x" | cut -d' ' -f 2-)" >$errlog 2>&1
fi
count=$((count + 1))
if [ $count -eq 20 ]; then
dch --append ... >$errlog 2>&1
break
fi
done
)
test "$SKIP_EDIT" -eq 1 || dch -e 2>/dev/null
# git tags cannot contain ~, also remove debian epoch versions
gittag=v$(echo "$version" | tr '~' '-' | sed 's/^[0-9]\+://')
log_info "A new git tag $gittag will be created and pushed to $REMOTE"
log_info "The resulting packages will be published in the following project versions:"
echo -n -e "\e[35m\e[1m"
molior-parseconfig target list | sed 's/^/ * /'
echo -n -e "\e[0m"
if [ $SKIP_CONFIRM -eq 0 ]
then
log_notice "Ready to release $package_name ($version) ?"
echo -n -e "\e[33m\e[1mQ: Press Enter to continue, Ctrl-C to abort ... \e[0m"
read x
fi
log "Committing debian/changelog"
git add -f debian/changelog >/dev/null 2>&1
git commit debian/changelog -m "$package_name: release $version" >$errlog 2>&1
git tag -a "$gittag" -m "$package_name: release $version" >$errlog 2>&1
log "Pushing changes to remote $REMOTE"
if [ "$NOPUSH" -eq 0 ]; then
git push $REMOTE `git rev-parse --abbrev-ref HEAD` "$gittag" >$errlog
log_info "Release $package_name ($version) tagged and pushed"
else
log_info "Release $package_name ($version) tagged, please git push $REMOTE `git rev-parse --abbrev-ref HEAD` \"$gittag\""
fi
rm -f $errlog