]> git.proxmox.com Git - debcargo-conf.git/blob - release.sh
Fix concatenation of commands proposed by release.sh
[debcargo-conf.git] / release.sh
1 #!/bin/bash
2 # Release a packaged crate to Debian.
3 #
4 # Usage: [REALVER=<EXACTVER>] ./release.sh <CRATE> [<SEMVER>]
5 #
6 # Envvars:
7 # See also ./vars.sh.frag for its envvars, which we pass through.
8 # See also ./build.sh for its envvars, which we pass through.
9 # RERELEASE=1
10 # Bump the changelog for a source-only reupload, required for migration to
11 # Debian Testing, and automatically dput the tarball. You need this after a
12 # NEW upload. This is a dumb consequence of two independently-thought-out
13 # policies but nobody on either team has expressed interest in fixing it,
14 # claiming "not my department".
15 # NOUPDATE=1
16 # Tell debcargo not to attempt to update to the latest version, i.e.
17 # autodetect REALVER. Set this if you get unexpected diffs when releasing.
18 # We probably want to switch this on by default, please complain in our IRC
19 # channel if you agree.
20 # REUSE_EXISTING_ORIG_TARBALL=1
21 # Re-use the existing .orig tarball. This is needed if it was previously
22 # generated with an old version of debcargo, otherwise you'll get
23 # auto-REJECT from Debian FTP. TODO: we probably want to set this
24 # automatically on if the Debian version ends with -2 or above.
25
26 . ./vars.sh.frag
27
28 RED=`echo -e "\033[1;31m"`
29 NC=`echo -e "\033[0m"`
30
31 if test ! -d $PKGDIR_REL; then
32 abort 1 "Cannot find $PKGDIR_REL. Did you run ./new-package.sh before?"
33 fi
34
35 if test ! -f "$PKGDIR_REL/debian/changelog"; then
36 abort 1 "Cannot find $PKGDIR_REL/debian/changelog. Did you run ./new-package.sh before?"
37 fi
38
39 if git grep --quiet FIXME -- "$PKGDIR_REL" :^"$PKGDIR_REL/debian/*.debcargo.hint" :^"$PKGDIR_REL/debian/changelog" :^"$PKGDIR_REL/debian/patches/*"; then
40 abort 1 "FIXMEs remain in $PKGDIR_REL, fix and commit those first."
41 fi
42
43 git diff --quiet --cached || \
44 abort 1 "You have other pending changes to git, please complete it or stash it away and re-run this script."
45
46 git diff --quiet -- "$PKGDIR_REL" || \
47 abort 1 "Please git-add your changes to $PKGDIR_REL before running"
48
49 type dch >/dev/null || \
50 abort 1 "Install devscripts, we need to run dch."
51
52 RELBRANCH="pending-$PKGNAME"
53 git fetch origin --prune
54
55 git merge-base --is-ancestor origin/master HEAD || \
56 abort 1 "You are not synced with origin/master, please do so before running this script."
57
58 if [ "$RERELEASE" = 1 -o "$NOUPDATE" = 1 ]; then
59 REALVER="$(get_existing_version "$PKGDIR")"
60 fi
61
62 if head -n1 "$PKGDIR/debian/changelog" | grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then
63 if [ "$RERELEASE" = 1 ]; then
64 run_debcargo
65 ( cd "$PKGDIR" && dch -a "No-op source-only re-upload for Debian Testing Migration." )
66 export REUSE_EXISTING_ORIG_TARBALL=1
67 else
68 abort 0 \
69 "Package already released. If you want to do a source-only re-upload e.g. to" \
70 "hoop-jump through the Debian Testing migration requirements, set RERELEASE=1."
71 fi
72 fi
73
74 if [ -e "$PKGDIR/debian/BLOCK" ]; then
75 abort 1 "TODO items remain in $PKGDIR/debian/BLOCK, please deal with those"
76 fi
77
78 PREVBRANCH="$(git rev-parse --abbrev-ref HEAD)"
79 case "$PREVBRANCH" in
80 pending-$PKGNAME) true;;
81 pending-*) abort 1 "You are on a pending-release branch for a package other than $PKGNAME, $0 can only be run on another branch, like master";;
82 *) if git rev-parse -q --verify "refs/heads/$RELBRANCH" >/dev/null || \
83 git rev-parse -q --verify "refs/remotes/origin/$RELBRANCH" >/dev/null; then
84 git checkout "$RELBRANCH"
85 else
86 git checkout -b "$RELBRANCH"
87 fi;;
88 esac
89
90 if head -n1 "$PKGDIR/debian/changelog" | grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then
91 git checkout "$PREVBRANCH"
92 abort 0 "Package already released on branch $RELBRANCH. If that was a mistake then run:" \
93 " git branch -D $RELBRANCH" \
94 "And re-run this script ($0 $*). You might have to delete the remote branch too:" \
95 " git push --delete origin $RELBRANCH"
96 fi
97
98 ( cd "$PKGDIR"
99 sed -i -e s/UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO/UNRELEASED/ debian/changelog
100 if test -z "$DISTRO"; then
101 # To upload to other distro like experimental
102 DISTRO=unstable
103 fi
104 dch -m -r -D $DISTRO ""
105 git add debian/changelog
106 git rm --ignore-unmatch debian/RFS
107 )
108
109 revert_git_changes() {
110 git reset --merge
111 git checkout -- "$PKGDIR/debian/changelog"
112 git checkout -q -- "$PKGDIR/debian/RFS" || true
113 git checkout "$PREVBRANCH"
114 git branch -d "$RELBRANCH"
115 }
116
117 if ! run_debcargo --changelog-ready; then
118 revert_git_changes
119 abort 1 "Release attempt failed to run debcargo, probably the package needs updating (./update.sh $*)"
120 fi
121
122 # sometimes the copyright years need to be updated, try to do this automatically
123 if git diff -- "$PKGDIR_REL/debian/copyright.debcargo.hint" | patch -r - --no-backup-if-mismatch "$PKGDIR_REL/debian/copyright"; then
124 git add "$PKGDIR_REL/debian/copyright.debcargo.hint" "$PKGDIR_REL/debian/copyright"
125 else
126 git diff -- "$PKGDIR_REL/debian/copyright.debcargo.hint"
127 revert_git_changes
128 abort 1 \
129 "copyright file needs updating; apply the above diff to $PKGDIR_REL/debian/copyright" \
130 "then commit your changes, and run me again."
131 fi
132
133 if ! git diff --exit-code -- "$PKGDIR_REL"; then
134 revert_git_changes
135 abort 1 \
136 "Release attempt resulted in git diffs to $PKGDIR_REL, probably you need to update the package (./update.sh $*)." \
137 "Alternatively, set NOUPDATE=1 to override this requirement, but please have a good reason."
138 fi
139
140 if ! ( cd build && SOURCEONLY=1 ./build.sh "$CRATE" $VER ); then
141 revert_git_changes
142 abort 1 "Release attempt failed (see messages above), possible reasons are: " \
143 "- build-dependencies not in Debian => release those first." \
144 "- packaged version is out-of-date => run \`./update.sh $*\`"
145 fi
146
147 git commit -m "Release package $PKGNAME"
148
149 DEBVER=$(dpkg-parsechangelog -l $BUILDDIR/debian/changelog -SVersion)
150 DEBSRC=$(dpkg-parsechangelog -l $BUILDDIR/debian/changelog -SSource)
151 DEB_HOST_ARCH=$(dpkg-architecture -q DEB_HOST_ARCH)
152
153 if [ "$RERELEASE" = 1 ]; then
154
155 ( cd build && dput "${DEBSRC}_${DEBVER}_source.changes" )
156 git push origin "$RELBRANCH"
157 git checkout master
158
159 cat <<eof
160 Source-only re-release of $CRATE uploaded. You need to perform the following steps:
161
162 eof
163
164 else
165
166 unstable_bin_packages="$(rmadison --noconf --suite unstable --source-and-binary "${DEBSRC}" | grep -v 'source$' | cut -d ' ' -f 1 | sort -u)"
167 upload_bin_packages="$(grep '^Binary' "build/${DEBSRC}_${DEBVER}.dsc" | sed -e 's/^Binary: //' -e 's/, /,/g' | tr ',' '\n' | sort -u)"
168 diff_bin_packages="$(diff -u0 <(echo "$unstable_bin_packages") <(echo "$upload_bin_packages") | tail -n-2)"
169 new_bin_packages="$(echo "$diff_bin_packages" | grep '^+' | sed -e 's/^+//g')"
170 rm_bin_packages="$(echo "$diff_bin_packages" | grep '^-' | sed -e 's/^-//g')"
171
172 show_build_notice() {
173 CRATE_FORMAT=$(echo $CRATE|sed -e "s/_/-/g")
174 cat <<eof
175 The recommended way to build and upload is to run something like:
176
177 cd build && ./build.sh $CRATE $VER && dput ${DEBSRC}_${DEBVER}_${DEB_HOST_ARCH}.changes && git push origin pending-$CRATE_FORMAT && git checkout - && cd -
178
179 eof
180 }
181
182 cat <<eof
183 Release of $CRATE ready as a source package in ${BUILDDIR#$PWD/}. You need to
184 perform the following steps:
185
186 Build the package if necessary, and upload
187 ==========================================
188 eof
189
190 if [ -z "$unstable_bin_packages" ]; then
191 cat <<eof
192 ${RED}
193 Since this is a NEW source package not already in the Debian archive, you will need to build a binary package out of it.
194
195 For your reference, this source package builds $(echo "$upload_bin_packages" | wc -l) binary package(s):
196 $upload_bin_packages
197 ${NC}
198 eof
199 show_build_notice
200
201 elif [ -z "$new_bin_packages" ]; then
202 cat <<eof
203 Since the source package is already in Debian and this version does not introduce
204 new binaries, then you can just go ahead and directly dput the source package.
205
206 cd build && dput ${DEBSRC}_${DEBVER}_source.changes && git checkout - && git merge -
207
208 If you want to build and test it, run:
209
210 cd build && ./build.sh $CRATE && dput ${DEBSRC}_${DEBVER}_source.changes && git checkout - && git merge -
211
212 For your reference, this source package builds $(echo "$upload_bin_packages" | wc -l) binary package(s):
213 $upload_bin_packages
214 eof
215 # don't show build notice
216
217 else
218 cat <<eof
219 ${RED}
220 ATTENTION: this upload introduces NEW binary packages not already in the Debian
221 archive, you will need to build a binary package out of it.
222
223 PLEASE THINK CAREFULLY BEFORE UPLOADING NEW VERSIONS WITH NEW BINARY PACKAGES,
224 AS SUCH UPLOADS CAN AFFECT ONGOING TRANSITIONS AND DELAY THEM SIGNIFICANTLY.
225
226 For your reference, this source package builds $(echo "$upload_bin_packages" | wc -l) binary package(s):
227 $upload_bin_packages
228
229 Of those, the following are NEW:
230 $new_bin_packages
231 ${NC}
232 eof
233 show_build_notice
234
235 fi # end decision-making on show_build_notice
236
237 if [ -n "$rm_bin_packages" ]; then
238
239 cat <<eof
240
241 ATTENTION: The following binary packages which are currently available in
242 Debian unstable are no longer built from ${DEBSRC}, please investigate whether
243 this is intentional, and file RM requests where appropriate:
244
245 $rm_bin_packages
246 eof
247
248 fi
249
250 cat <<eof
251 This assumes you followed the "Build environment" instructions in README.rst,
252 for setting up a build environment for release.
253
254 If the build fails e.g. due to missing Build-Dependencies you should revert
255 what I did (see below) and package those missing Build-Dependencies first.
256
257 Push this pending-release branch
258 ================================
259
260 After you have uploaded the package with dput(1), you should push $RELBRANCH so
261 that other people see it's been uploaded. Then, checkout another branch like
262 master to continue development on other packages.
263
264 git push origin $RELBRANCH && git checkout master
265
266 eof
267
268 fi
269
270 cat >&2 <<eof
271 Merge the pending-release branch if/when ACCEPTED
272 =================================================
273
274 When it's ACCEPTED by the Debian FTP masters, you may then merge this branch
275 back into the master branch, delete it, and push these updates to origin.
276
277 git checkout master && git merge $RELBRANCH && git branch -d $RELBRANCH
278 git push origin master :$RELBRANCH
279
280 Delete this branch without merging if/when REJECTED
281 ===================================================
282
283 If your upload is REJECTED, or if you cannot perform an upload in the first
284 place e.g. because you are not a Debian Developer, you should revert what I
285 just did. To do that, run:
286
287 git checkout master && git branch -D $RELBRANCH
288
289 Then ask a Debian Developer to re-run me ($0 $*) on your behalf. Also, touch
290 and commit ${PKGDIR_REL}/debian/RFS so we can track these easier.
291 eof