debian/tests/skeleton-packaging
author Jérémy Bobbio <jeremy.bobbio@irq7.fr>
Wed, 10 Jul 2019 14:58:41 +0200
branch3.26
changeset 12690 d1b5fd6129bd
child 12709 280c9db41038
permissions -rw-r--r--
[pkg] Add new autopkgtest for skeleton packaging When running `cubicweb-ctl newcube`, the generated template provides debian packaging. So let's add automated tests for that using autopkgtest. The new test will generated a new cube, build a source tarball, build the package, try to install it, see if the Python 2 and 3 modules are available and even run autopkgtest against the newly created packages. Along the way it will also print information about the generated package: buildinfo, package content, and lintian report.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12690
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
     1
#!/bin/sh
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
     2
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
     3
set -e
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
     4
set -x
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
     5
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
     6
if [ -z "$AUTOPKGTEST_TMP" ]; then
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
     7
	echo "Not running as part as autopkgtest" >&2
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
     8
	exit 250
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
     9
fi
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    10
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    11
# Switch to unprivileged user if needed
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    12
if [ "$(id -u)" = 0 ]; then
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    13
	apt-get install -q -y sudo
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    14
	echo 'Defaults !fqdn' > /etc/sudoers.d/fqdn
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    15
	echo 'nobody ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers.d/nobody
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    16
	chown nobody:nogroup "$AUTOPKGTEST_TMP"
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    17
	exec su nobody -s /bin/sh -c "$0"
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    18
fi
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    19
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    20
cd "$AUTOPKGTEST_TMP"
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    21
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    22
# Create a cube
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    23
PACKAGE="cubicweb-mytest"
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    24
cubicweb-ctl newcube -s 'Just a test cube' ${PACKAGE#cubicweb-}
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    25
cd "$PACKAGE"
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    26
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    27
UPSTREAM_VERSION=$(python setup.py --version)
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    28
DEBIAN_VERSION=$(dpkg-parsechangelog -S Version)
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    29
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    30
# Create source tarball
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    31
python setup.py sdist
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    32
mv "dist/${PACKAGE}-${UPSTREAM_VERSION}.tar.gz" "../${PACKAGE}_${UPSTREAM_VERSION}.orig.tar.gz"
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    33
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    34
# Install build-dependencies
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    35
mk-build-deps --install --root-cmd sudo --remove \
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    36
	--tool 'apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends --quiet --assume-yes'
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    37
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    38
# Build!
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    39
dpkg-buildpackage
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    40
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    41
# Output .buildinfo for posterity
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    42
cat ../*.buildinfo
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    43
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    44
# Output package content, again for posterity
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    45
debc
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    46
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    47
# Install the package
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    48
sudo debi --with-depends
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    49
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    50
lintian -i ../*.dsc ../*.changes
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    51
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    52
# Test if Python module is usable
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    53
python -c 'import cubicweb_mytest; print(dir(cubicweb_mytest))'
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    54
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    55
# Test if Python3 module is usable
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    56
python3 -c 'import cubicweb_mytest; print(dir(cubicweb_mytest))'
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    57
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    58
# Run autopkgtest (uh… inception, anyone?)
d1b5fd6129bd [pkg] Add new autopkgtest for skeleton packaging
Jérémy Bobbio <jeremy.bobbio@irq7.fr>
parents:
diff changeset
    59
sudo autopkgtest ../*.changes -- null