]> git.proxmox.com Git - debcargo-conf.git/blame - release.sh
libc: New upstream release
[debcargo-conf.git] / release.sh
CommitLineData
ea4bf6cd 1#!/bin/bash
5e18ef4f
XL
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.
931eabc0
XL
25
26. ./vars.sh.frag
27
2c47a4e5
SL
28RED=`echo -e "\033[1;31m"`
29NC=`echo -e "\033[0m"`
30
e19e9e08
SL
31if test ! -d $PKGDIR_REL; then
32 abort 1 "Cannot find $PKGDIR_REL. Did you run ./new-package.sh before?"
33fi
34
c1621660
XL
35if test ! -f "$PKGDIR_REL/debian/changelog"; then
36 abort 1 "Cannot find $PKGDIR_REL/debian/changelog. Did you run ./new-package.sh before?"
37fi
38
e5b8ae94 39if git grep --quiet FIXME -- "$PKGDIR_REL" :^"$PKGDIR_REL/debian/*.debcargo.hint" :^"$PKGDIR_REL/debian/changelog" :^"$PKGDIR_REL/debian/patches/*"; then
89c70e95
XL
40 abort 1 "FIXMEs remain in $PKGDIR_REL, fix and commit those first."
41fi
42
1230b71f
XL
43git diff --quiet --cached || \
44abort 1 "You have other pending changes to git, please complete it or stash it away and re-run this script."
45
46git diff --quiet -- "$PKGDIR_REL" || \
931eabc0
XL
47abort 1 "Please git-add your changes to $PKGDIR_REL before running"
48
1057693c
XL
49type dch >/dev/null || \
50abort 1 "Install devscripts, we need to run dch."
51
b6a1d240
XL
52RELBRANCH="pending-$PKGNAME"
53git fetch origin --prune
2de6944f 54
c75ca09f 55git merge-base --is-ancestor origin/master HEAD || \
90f3bab9 56abort 1 "You are not synced with origin/master, please do so before running this script."
1c8790a3 57
baae6f7c
XL
58if [ "$RERELEASE" = 1 -o "$NOUPDATE" = 1 ]; then
59 REALVER="$(get_existing_version "$PKGDIR")"
60fi
61
2de6944f 62if head -n1 "$PKGDIR/debian/changelog" | grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then
baae6f7c
XL
63 if [ "$RERELEASE" = 1 ]; then
64 run_debcargo
65 ( cd "$PKGDIR" && dch -a "No-op source-only re-upload for Debian Testing Migration." )
30bf7f25 66 export REUSE_EXISTING_ORIG_TARBALL=1
baae6f7c
XL
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
2de6944f
XL
72fi
73
e1a9d897
XL
74if [ -e "$PKGDIR/debian/BLOCK" ]; then
75 abort 1 "TODO items remain in $PKGDIR/debian/BLOCK, please deal with those"
76fi
77
32c1fb5b
XL
78PREVBRANCH="$(git rev-parse --abbrev-ref HEAD)"
79case "$PREVBRANCH" in
b6a1d240
XL
80pending-$PKGNAME) true;;
81pending-*) 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;;
88esac
89
90if head -n1 "$PKGDIR/debian/changelog" | grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then
32c1fb5b 91 git checkout "$PREVBRANCH"
c6709bfe
XL
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"
b6a1d240 96fi
1230b71f 97
06485659
IJ
98CHANGEDBY=$(dpkg-parsechangelog -l $PKGDIR/debian/changelog -SMaintainer)
99if [ "$CHANGEDBY" != "$UPLOADER" ]; then
100 cat <<eof
101Changes by $CHANGEDBY to be sponsored by $UPLOADER.
102eof
103 if ! test -e $PKGDIR/debian/RFS; then
104 abort 1 "Sponsored upload, but $PKGDIR/debian/RFS does not exist"
105 fi
106fi
107
931eabc0
XL
108( cd "$PKGDIR"
109sed -i -e s/UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO/UNRELEASED/ debian/changelog
699de4ac
SL
110if test -z "$DISTRO"; then
111 # To upload to other distro like experimental
112 DISTRO=unstable
113fi
114dch -m -r -D $DISTRO ""
931eabc0 115git add debian/changelog
d30bb8e0 116git rm --ignore-unmatch debian/RFS
931eabc0
XL
117)
118
cc003c95 119revert_git_changes() {
8c0b9df4 120 git reset --merge
d30bb8e0
AS
121 git checkout -- "$PKGDIR/debian/changelog"
122 git checkout -q -- "$PKGDIR/debian/RFS" || true
e185876a
XL
123 git checkout "$PREVBRANCH"
124 git branch -d "$RELBRANCH"
cc003c95
XL
125}
126
127if ! run_debcargo --changelog-ready; then
128 revert_git_changes
129 abort 1 "Release attempt failed to run debcargo, probably the package needs updating (./update.sh $*)"
130fi
131
30bf7f25
XL
132# sometimes the copyright years need to be updated, try to do this automatically
133if git diff -- "$PKGDIR_REL/debian/copyright.debcargo.hint" | patch -r - --no-backup-if-mismatch "$PKGDIR_REL/debian/copyright"; then
134 git add "$PKGDIR_REL/debian/copyright.debcargo.hint" "$PKGDIR_REL/debian/copyright"
135else
136 git diff -- "$PKGDIR_REL/debian/copyright.debcargo.hint"
137 revert_git_changes
138 abort 1 \
139 "copyright file needs updating; apply the above diff to $PKGDIR_REL/debian/copyright" \
140 "then commit your changes, and run me again."
141fi
142
cc003c95
XL
143if ! git diff --exit-code -- "$PKGDIR_REL"; then
144 revert_git_changes
baae6f7c
XL
145 abort 1 \
146 "Release attempt resulted in git diffs to $PKGDIR_REL, probably you need to update the package (./update.sh $*)." \
147 "Alternatively, set NOUPDATE=1 to override this requirement, but please have a good reason."
e185876a 148fi
931eabc0 149
1057693c 150if ! ( cd build && SOURCEONLY=1 ./build.sh "$CRATE" $VER ); then
cc003c95 151 revert_git_changes
98cad301
XL
152 abort 1 "Release attempt failed (see messages above), possible reasons are: " \
153 "- build-dependencies not in Debian => release those first." \
154 "- packaged version is out-of-date => run \`./update.sh $*\`"
cc003c95
XL
155fi
156
999f9269 157git commit -m "Release package $PKGNAME"
931eabc0 158
1057693c
XL
159DEBVER=$(dpkg-parsechangelog -l $BUILDDIR/debian/changelog -SVersion)
160DEBSRC=$(dpkg-parsechangelog -l $BUILDDIR/debian/changelog -SSource)
550dd343 161DEB_HOST_ARCH=$(dpkg-architecture -q DEB_HOST_ARCH)
b6a1d240 162
baae6f7c 163if [ "$RERELEASE" = 1 ]; then
baae6f7c 164
508cd1b3
XL
165( cd build && dput "${DEBSRC}_${DEBVER}_source.changes" )
166git push origin "$RELBRANCH"
167git checkout master
baae6f7c 168
508cd1b3
XL
169cat <<eof
170Source-only re-release of $CRATE uploaded. You need to perform the following steps:
9550b9b4 171
baae6f7c 172eof
508cd1b3 173
baae6f7c 174else
508cd1b3 175
64c6d382
FG
176unstable_bin_packages="$(rmadison --noconf --suite unstable --source-and-binary "${DEBSRC}" | grep -v 'source$' | cut -d ' ' -f 1 | sort -u)"
177upload_bin_packages="$(grep '^Binary' "build/${DEBSRC}_${DEBVER}.dsc" | sed -e 's/^Binary: //' -e 's/, /,/g' | tr ',' '\n' | sort -u)"
178diff_bin_packages="$(diff -u0 <(echo "$unstable_bin_packages") <(echo "$upload_bin_packages") | tail -n-2)"
179new_bin_packages="$(echo "$diff_bin_packages" | grep '^+' | sed -e 's/^+//g')"
180rm_bin_packages="$(echo "$diff_bin_packages" | grep '^-' | sed -e 's/^-//g')"
181
6b1bd07a
XL
182show_build_notice() {
183cat <<eof
184The recommended way to build and upload is to run something like:
185
88a5e7d0 186 cd build && ./build.sh $CRATE $VER && dput ${DEBSRC}_${DEBVER}_${DEB_HOST_ARCH}.changes && git push origin $RELBRANCH && git checkout - && cd -
8178bcf7 187
6b1bd07a
XL
188eof
189}
190
baae6f7c 191cat <<eof
508cd1b3
XL
192Release of $CRATE ready as a source package in ${BUILDDIR#$PWD/}. You need to
193perform the following steps:
194
b6a1d240
XL
195Build the package if necessary, and upload
196==========================================
64c6d382
FG
197eof
198
199if [ -z "$unstable_bin_packages" ]; then
200cat <<eof
2c47a4e5 201${RED}
64c6d382
FG
202Since this is a NEW source package not already in the Debian archive, you will need to build a binary package out of it.
203
204For your reference, this source package builds $(echo "$upload_bin_packages" | wc -l) binary package(s):
205$upload_bin_packages
2c47a4e5 206${NC}
64c6d382 207eof
6b1bd07a 208show_build_notice
64c6d382 209
6b1bd07a 210elif [ -z "$new_bin_packages" ]; then
64c6d382
FG
211cat <<eof
212Since the source package is already in Debian and this version does not introduce
1230b71f
XL
213new binaries, then you can just go ahead and directly dput the source package.
214
ec606323 215 cd build && dput ${DEBSRC}_${DEBVER}_source.changes && git checkout - && git merge -
b6a1d240 216
57bef5f1
SL
217If you want to build and test it, run:
218
fb32ecd5 219 cd build && ./build.sh $CRATE && dput ${DEBSRC}_${DEBVER}_source.changes && git checkout - && git merge - && cd -
57bef5f1 220
64c6d382
FG
221For your reference, this source package builds $(echo "$upload_bin_packages" | wc -l) binary package(s):
222$upload_bin_packages
223eof
6b1bd07a 224# don't show build notice
f52ac044 225
64c6d382 226else
64c6d382 227cat <<eof
a4d317b5 228${RED}
64c6d382
FG
229ATTENTION: this upload introduces NEW binary packages not already in the Debian
230archive, you will need to build a binary package out of it.
231
232PLEASE THINK CAREFULLY BEFORE UPLOADING NEW VERSIONS WITH NEW BINARY PACKAGES,
233AS SUCH UPLOADS CAN AFFECT ONGOING TRANSITIONS AND DELAY THEM SIGNIFICANTLY.
234
235For your reference, this source package builds $(echo "$upload_bin_packages" | wc -l) binary package(s):
236$upload_bin_packages
237
238Of those, the following are NEW:
239$new_bin_packages
a4d317b5 240${NC}
64c6d382 241eof
6b1bd07a 242show_build_notice
64c6d382 243
6b1bd07a 244fi # end decision-making on show_build_notice
64c6d382
FG
245
246if [ -n "$rm_bin_packages" ]; then
247
248cat <<eof
249
250ATTENTION: The following binary packages which are currently available in
251Debian unstable are no longer built from ${DEBSRC}, please investigate whether
252this is intentional, and file RM requests where appropriate:
253
254$rm_bin_packages
255eof
256
257fi
258
259cat <<eof
c6709bfe
XL
260This assumes you followed the "Build environment" instructions in README.rst,
261for setting up a build environment for release.
1230b71f 262
db9d5fab
XL
263If the build fails e.g. due to missing Build-Dependencies you should revert
264what I did (see below) and package those missing Build-Dependencies first.
265
b6a1d240
XL
266Push this pending-release branch
267================================
268
269After you have uploaded the package with dput(1), you should push $RELBRANCH so
270that other people see it's been uploaded. Then, checkout another branch like
271master to continue development on other packages.
272
ea8e55fe 273 git push origin $RELBRANCH && git checkout master
b6a1d240 274
508cd1b3
XL
275eof
276
277fi
278
279cat >&2 <<eof
baae6f7c
XL
280Merge the pending-release branch if/when ACCEPTED
281=================================================
b6a1d240
XL
282
283When it's ACCEPTED by the Debian FTP masters, you may then merge this branch
284back into the master branch, delete it, and push these updates to origin.
285
ea8e55fe
XL
286 git checkout master && git merge $RELBRANCH && git branch -d $RELBRANCH
287 git push origin master :$RELBRANCH
b6a1d240 288
baae6f7c
XL
289Delete this branch without merging if/when REJECTED
290===================================================
b6a1d240 291
baae6f7c
XL
292If your upload is REJECTED, or if you cannot perform an upload in the first
293place e.g. because you are not a Debian Developer, you should revert what I
294just did. To do that, run:
b6a1d240 295
ea8e55fe 296 git checkout master && git branch -D $RELBRANCH
b6a1d240 297
baae6f7c
XL
298Then ask a Debian Developer to re-run me ($0 $*) on your behalf. Also, touch
299and commit ${PKGDIR_REL}/debian/RFS so we can track these easier.
1230b71f 300eof