]> git.proxmox.com Git - debcargo-conf.git/blob - release.sh
release.sh: always try to fix the copyright years
[debcargo-conf.git] / release.sh
1 #!/bin/bash
2
3 . ./vars.sh.frag
4
5 if test ! -d $PKGDIR_REL; then
6 abort 1 "Cannot find $PKGDIR_REL. Did you run ./new-package.sh before?"
7 fi
8
9 if test ! -f "$PKGDIR_REL/debian/changelog"; then
10 abort 1 "Cannot find $PKGDIR_REL/debian/changelog. Did you run ./new-package.sh before?"
11 fi
12
13 if git grep --quiet FIXME -- "$PKGDIR_REL" :^"$PKGDIR_REL/debian/*.debcargo.hint" :^"$PKGDIR_REL/debian/changelog"; then
14 abort 1 "FIXMEs remain in $PKGDIR_REL, fix and commit those first."
15 fi
16
17 git diff --quiet --cached || \
18 abort 1 "You have other pending changes to git, please complete it or stash it away and re-run this script."
19
20 git diff --quiet -- "$PKGDIR_REL" || \
21 abort 1 "Please git-add your changes to $PKGDIR_REL before running"
22
23 type dch >/dev/null || \
24 abort 1 "Install devscripts, we need to run dch."
25
26 RELBRANCH="pending-$PKGNAME"
27 git fetch origin --prune
28
29 git merge-base --is-ancestor origin/master HEAD || \
30 abort 1 "You are not synced with origin/master, please do so before running this script."
31
32 if [ "$RERELEASE" = 1 -o "$NOUPDATE" = 1 ]; then
33 REALVER="$(get_existing_version "$PKGDIR")"
34 fi
35
36 if head -n1 "$PKGDIR/debian/changelog" | grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then
37 if [ "$RERELEASE" = 1 ]; then
38 run_debcargo
39 ( cd "$PKGDIR" && dch -a "No-op source-only re-upload for Debian Testing Migration." )
40 export REUSE_EXISTING_ORIG_TARBALL=1
41 else
42 abort 0 \
43 "Package already released. If you want to do a source-only re-upload e.g. to" \
44 "hoop-jump through the Debian Testing migration requirements, set RERELEASE=1."
45 fi
46 fi
47
48 if [ -e "$PKGDIR/debian/BLOCK" ]; then
49 abort 1 "TODO items remain in $PKGDIR/debian/BLOCK, please deal with those"
50 fi
51
52 PREVBRANCH="$(git rev-parse --abbrev-ref HEAD)"
53 case "$PREVBRANCH" in
54 pending-$PKGNAME) true;;
55 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";;
56 *) if git rev-parse -q --verify "refs/heads/$RELBRANCH" >/dev/null || \
57 git rev-parse -q --verify "refs/remotes/origin/$RELBRANCH" >/dev/null; then
58 git checkout "$RELBRANCH"
59 else
60 git checkout -b "$RELBRANCH"
61 fi;;
62 esac
63
64 if head -n1 "$PKGDIR/debian/changelog" | grep -qv UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO; then
65 git checkout "$PREVBRANCH"
66 abort 0 "Package already released on branch $RELBRANCH. If that was a mistake then run:" \
67 " git branch -D $RELBRANCH" \
68 "And re-run this script ($0 $*). You might have to delete the remote branch too:" \
69 " git push --delete origin $RELBRANCH"
70 fi
71
72 ( cd "$PKGDIR"
73 sed -i -e s/UNRELEASED-FIXME-AUTOGENERATED-DEBCARGO/UNRELEASED/ debian/changelog
74 if test -z "$DISTRO"; then
75 # To upload to other distro like experimental
76 DISTRO=unstable
77 fi
78 dch -m -r -D $DISTRO ""
79 git add debian/changelog
80 git rm --ignore-unmatch debian/RFS
81 )
82
83 revert_git_changes() {
84 git reset --merge
85 git checkout -- "$PKGDIR/debian/changelog"
86 git checkout -q -- "$PKGDIR/debian/RFS" || true
87 git checkout "$PREVBRANCH"
88 git branch -d "$RELBRANCH"
89 }
90
91 if ! run_debcargo --changelog-ready; then
92 revert_git_changes
93 abort 1 "Release attempt failed to run debcargo, probably the package needs updating (./update.sh $*)"
94 fi
95
96 # sometimes the copyright years need to be updated, try to do this automatically
97 if git diff -- "$PKGDIR_REL/debian/copyright.debcargo.hint" | patch -r - --no-backup-if-mismatch "$PKGDIR_REL/debian/copyright"; then
98 git add "$PKGDIR_REL/debian/copyright.debcargo.hint" "$PKGDIR_REL/debian/copyright"
99 else
100 git diff -- "$PKGDIR_REL/debian/copyright.debcargo.hint"
101 revert_git_changes
102 abort 1 \
103 "copyright file needs updating; apply the above diff to $PKGDIR_REL/debian/copyright" \
104 "then commit your changes, and run me again."
105 fi
106
107 if ! git diff --exit-code -- "$PKGDIR_REL"; then
108 revert_git_changes
109 abort 1 \
110 "Release attempt resulted in git diffs to $PKGDIR_REL, probably you need to update the package (./update.sh $*)." \
111 "Alternatively, set NOUPDATE=1 to override this requirement, but please have a good reason."
112 fi
113
114 if ! ( cd build && SOURCEONLY=1 ./build.sh "$CRATE" $VER ); then
115 revert_git_changes
116 abort 1 "Release attempt failed (see messages above), possible reasons are: " \
117 "- build-dependencies not in Debian => release those first." \
118 "- packaged version is out-of-date => run \`./update.sh $*\`"
119 fi
120
121 git commit -m "Release package $PKGNAME"
122
123 DEBVER=$(dpkg-parsechangelog -l $BUILDDIR/debian/changelog -SVersion)
124 DEBSRC=$(dpkg-parsechangelog -l $BUILDDIR/debian/changelog -SSource)
125 DEB_HOST_ARCH=$(dpkg-architecture -q DEB_HOST_ARCH)
126
127 if [ "$RERELEASE" = 1 ]; then
128
129 ( cd build && dput "${DEBSRC}_${DEBVER}_source.changes" )
130 git push origin "$RELBRANCH"
131 git checkout master
132
133 cat <<eof
134 Source-only re-release of $CRATE uploaded. You need to perform the following steps:
135
136 eof
137
138 else
139
140 cat <<eof
141 Release of $CRATE ready as a source package in ${BUILDDIR#$PWD/}. You need to
142 perform the following steps:
143
144 Build the package if necessary, and upload
145 ==========================================
146
147 If the source package is already in Debian and this version does not introduce
148 new binaries, then you can just go ahead and directly dput the source package.
149
150 cd build && dput ${DEBSRC}_${DEBVER}_source.changes
151
152 For your reference, this source package builds $(grep ^Package build/${CRATE//_/-}/debian/control | wc -l) binary package(s):
153 $(sed -ne 's/^Package: //pg' build/hmac/debian/control | tr '\n' ',')
154
155 If this is a NEW source package or introduces NEW binary packages not already
156 in the Debian archive, you will need to build a binary package out of it. The
157 recommended way is to run something like:
158
159 cd build && ./build.sh $CRATE $VER && dput ${DEBSRC}_${DEBVER}_${DEB_HOST_ARCH}.changes
160
161 This assumes you followed the "Build environment" instructions in README.rst,
162 for setting up a build environment for release.
163
164 If the build fails e.g. due to missing Build-Dependencies you should revert
165 what I did (see below) and package those missing Build-Dependencies first.
166
167 Push this pending-release branch
168 ================================
169
170 After you have uploaded the package with dput(1), you should push $RELBRANCH so
171 that other people see it's been uploaded. Then, checkout another branch like
172 master to continue development on other packages.
173
174 git push origin $RELBRANCH && git checkout master
175
176 eof
177
178 fi
179
180 cat >&2 <<eof
181 Merge the pending-release branch if/when ACCEPTED
182 =================================================
183
184 When it's ACCEPTED by the Debian FTP masters, you may then merge this branch
185 back into the master branch, delete it, and push these updates to origin.
186
187 git checkout master && git merge $RELBRANCH && git branch -d $RELBRANCH
188 git push origin master :$RELBRANCH
189
190 Delete this branch without merging if/when REJECTED
191 ===================================================
192
193 If your upload is REJECTED, or if you cannot perform an upload in the first
194 place e.g. because you are not a Debian Developer, you should revert what I
195 just did. To do that, run:
196
197 git checkout master && git branch -D $RELBRANCH
198
199 Then ask a Debian Developer to re-run me ($0 $*) on your behalf. Also, touch
200 and commit ${PKGDIR_REL}/debian/RFS so we can track these easier.
201 eof