For Debian package maintainers, the wrap-and-sort tool is one of those nice tools that I use once in a while, and every time have to re-read the documentation to conclude that I want to use the --wrap-always --short-indent --trailing-comma --sort-binary-package
options (or -satb
for short). Every time, I also wish that I could automate this and have it always be invoked to keep my debian/
directory tidy, so I don’t have to do this manually once every blue moon. I haven’t found a way to achieve this automation in a non-obtrusive way that interacts well with my git-based packaging workflow. Ideally I would like for something like the lintian-hook during gbp buildpackage
to check for this – ideas?
Meanwhile, I have come up with a way to make sure I don’t forget to run wrap-and-sort
for long, and that others who work on the same package won’t either: create an autopkgtest which is invoked during the Salsa CI/CD pipeline using the following as debian/tests/wrap-and-sort
:
#!/bin/sh
set -eu
TMPDIR=$(mktemp -d)
trap "rm -rf $TMPDIR" 0 INT QUIT ABRT PIPE TERM
cp -a debian $TMPDIR
cd $TMPDIR
wrap-and-sort -satb
diff -ur $OLDPWD/debian debian
Add the following to debian/tests/control
to invoke it – which is intentionally not indented properly so that the self-test will fail so you will learn how it behaves.
Tests: wrap-and-sort
Depends: devscripts, python3-debian
Restrictions: superficial
Now I will get build failures in the pipeline once I upload the package into Salsa, which I usually do before uploading into Debian. I will get a diff output, and it won’t be happy until I push a commit with the output of running wrap-and-sort
with the parameters I settled with.
While autopkgtest
is intended to test the installed package, the tooling around autopkgtest
is powerful and easily allows this mild abuse of its purpose for a pleasant QA improvement.
Thoughts? Happy hacking!