| 1 |
#!/bin/sh |
| 2 |
# |
| 3 |
# gen-release |
| 4 |
# |
| 5 |
# Copyright © 2017-2024 Guillem Jover <[email protected]> |
| 6 |
# |
| 7 |
# This program is free software; you can redistribute it and/or modify |
| 8 |
# it under the terms of the GNU General Public License as published by |
| 9 |
# the Free Software Foundation; either version 2 of the License, or |
| 10 |
# (at your option) any later version. |
| 11 |
# |
| 12 |
# This program is distributed in the hope that it will be useful, |
| 13 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
# GNU General Public License for more details. |
| 16 |
# |
| 17 |
# You should have received a copy of the GNU General Public License |
| 18 |
# along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 19 |
# |
| 20 |
|
| 21 |
set -x |
| 22 |
set -e |
| 23 |
set -u |
| 24 |
|
| 25 |
# Pre-checks. |
| 26 |
|
| 27 |
# Currently requires packages: dpkg-dev, git, schroot and devscripts |
| 28 |
# (the latter should eventually be replaced by dpkg tools). |
| 29 |
for req in dpkg-parsechangelog git schroot dch debsign dscverify; do |
| 30 |
if ! command -v $req >/dev/null 2>&1; then |
| 31 |
echo "error: missing required command $req" >&2 |
| 32 |
exit 1 |
| 33 |
fi |
| 34 |
done |
| 35 |
|
| 36 |
if [ "$(dpkg-parsechangelog -SSource)" != 'dpkg' ] || ! [ -e .git ]; then |
| 37 |
echo "error: not inside the dpkg git tree" >&2 |
| 38 |
exit 1 |
| 39 |
fi |
| 40 |
|
| 41 |
# Setup. |
| 42 |
dist="${1:-unstable}" |
| 43 |
relver="${2:-$(dpkg-parsechangelog -SVersion)}" |
| 44 |
|
| 45 |
numjobs="$(nproc)" |
| 46 |
checkflags="-j$numjobs AUTHOR_TESTING=1 TEST_PARALLEL=$numjobs" |
| 47 |
|
| 48 |
dircode="$(pwd)" |
| 49 |
dirtests="$dircode/tests" |
| 50 |
dirbuild="$(mktemp --tmpdir --directory release-dpkg.XXXXXXXX)" |
| 51 |
|
| 52 |
# Update the source chroot. |
| 53 |
schroot -c "source:$dist" -- sudo eatmydata apt-get --yes update |
| 54 |
schroot -c "source:$dist" -- sudo eatmydata apt-get --yes upgrade |
| 55 |
|
| 56 |
# Setup a clean chroot session. |
| 57 |
chroot="$(schroot -c "$dist" -b)" |
| 58 |
|
| 59 |
echo "Release start: $(date -Iseconds)" |
| 60 |
|
| 61 |
cd "$dircode" |
| 62 |
|
| 63 |
schroot -c "$chroot" -r -- sudo eatmydata apt-get --yes build-dep \ |
| 64 |
-P pkg.dpkg.author-testing,pkg.dpkg.author-release . |
| 65 |
|
| 66 |
if ! git log --format=tformat:%s -s HEAD~2.. | grep 'po: Regenerate'; then |
| 67 |
# Clean slate. |
| 68 |
git clean -Xdf |
| 69 |
|
| 70 |
# Update the .pot and .po files. |
| 71 |
echo "$relver" >.dist-version |
| 72 |
schroot -c "$chroot" -r -- ./autogen |
| 73 |
schroot -c "$chroot" -r -- ./configure |
| 74 |
schroot -c "$chroot" -r -- make update-po |
| 75 |
rm -f .dist-version |
| 76 |
git commit -a -m 'po: Regenerate .pot files and merge .po files with them' |
| 77 |
fi |
| 78 |
|
| 79 |
if [ -z "$(git tag --list "$relver")" ]; then |
| 80 |
# Finalize the actual release. |
| 81 |
genchangelog='build-aux/gen-changelog' |
| 82 |
sed -i -e "2e$genchangelog" -e '2,3d' debian/changelog |
| 83 |
dch -r -D"$dist" |
| 84 |
git commit -a -m "Release $relver" |
| 85 |
git tag -s "$relver" -m "Release $relver" |
| 86 |
elif [ "$(git describe)" != "$relver" ]; then |
| 87 |
echo "error: mismatched tag for $relver not on git HEAD" >&2 |
| 88 |
exit 1 |
| 89 |
fi |
| 90 |
|
| 91 |
# Clean slate. |
| 92 |
git clean -Xdf |
| 93 |
|
| 94 |
# Prepare the tarball for distribution. |
| 95 |
schroot -c "$chroot" -r -- ./autogen |
| 96 |
schroot -c "$chroot" -r -- ./configure |
| 97 |
if [ "$dist" = unstable ]; then |
| 98 |
# Generate the CPAN distribution only from main. |
| 99 |
make dist-cpan |
| 100 |
fi |
| 101 |
# shellcheck disable=SC2086 |
| 102 |
schroot -c "$chroot" -r -- make $checkflags distcheck |
| 103 |
|
| 104 |
# Prepare for packaged release. |
| 105 |
mkdir -p "$dirbuild" |
| 106 |
mv "dpkg-$relver.tar.xz" "$dirbuild/" |
| 107 |
mv "Dpkg-$relver.tar.gz" "$dirbuild/" |
| 108 |
|
| 109 |
# Teardown pre-release chroot. |
| 110 |
schroot -c "$chroot" -e |
| 111 |
|
| 112 |
cd "$dirbuild" |
| 113 |
|
| 114 |
# Setup a clean chroot session for the dist tarballs. |
| 115 |
chroot="$(schroot -c "$dist" -b)" |
| 116 |
|
| 117 |
# Build twice, to make sure we can build ourselves with the new dpkg, |
| 118 |
# and to verify that we are building reproducibly. |
| 119 |
|
| 120 |
# Build A and B in a chroot. |
| 121 |
for iter in a b; do ( |
| 122 |
mkdir -p "build-$iter" |
| 123 |
cd "build-$iter" |
| 124 |
tar xaf "../dpkg-$relver.tar.xz" |
| 125 |
cd "dpkg-$relver" |
| 126 |
|
| 127 |
schroot -c "$chroot" -r -- sudo eatmydata apt-get --yes build-dep . |
| 128 |
schroot -c "$chroot" -r -- dpkg-buildpackage -us -uc --changes-option=-S |
| 129 |
|
| 130 |
# Install resulting .debs. |
| 131 |
schroot -c "$chroot" -r -- sudo eatmydata dpkg -iO ../*.deb |
| 132 |
) done |
| 133 |
|
| 134 |
# Run functional test-suite. |
| 135 |
( |
| 136 |
set -x |
| 137 |
set -e |
| 138 |
set -u |
| 139 |
|
| 140 |
cd "$dirtests" |
| 141 |
schroot -c "$chroot" -r -- sudo eatmydata apt-get --yes purge pkg-config |
| 142 |
schroot -c "$chroot" -r -- eatmydata make test-clean clean |
| 143 |
schroot -c "$chroot" -r -- eatmydata make test 2>&1 | tee test.log |
| 144 |
) |
| 145 |
|
| 146 |
schroot -c "$chroot" -r -- sudo eatmydata apt-get --yes install lintian |
| 147 |
|
| 148 |
# Verify the result. |
| 149 |
diff -u build-a/dpkg_*.changes build-b/dpkg_*.changes || true |
| 150 |
# Prompt to continue? (.buildinfo will differ) |
| 151 |
diff -u build-a/dpkg_*.buildinfo build-b/dpkg_*.buildinfo || true |
| 152 |
# Prompt to continue? (Build-Date, Environment will differ). |
| 153 |
schroot -c "$chroot" -r -- lintian build-b/*.changes build-b/*.deb |
| 154 |
|
| 155 |
# Teardown chroot. |
| 156 |
schroot -c "$chroot" -e |
| 157 |
|
| 158 |
# Sign and verify. |
| 159 |
cd "$dirbuild/build-b" |
| 160 |
debsign dpkg_"${relver}"_*.changes |
| 161 |
dscverify dpkg_"${relver}"_*.changes |
| 162 |
|
| 163 |
ls -l "$(pwd)" |
| 164 |
|
| 165 |
echo "Release process finished (dpkg ${relver}): $(date -Iseconds)" |
| 166 |
echo " Hint: upload to CPAN" |
| 167 |
echo " Hint: update https://www.wikidata.org/wiki/Q305892" |