Files
spotify/tools/ci-apt.sh
Tamas Csikel 5a76e56fe1
All checks were successful
release / release (push) Successful in 14m0s
CI: align Multi-Arch versions when ports.ubuntu.com lags behind
The arm64 mirror had an older libpcre2 than the amd64 one already in the
runner image; Multi-Arch: same packages need one version on both, so apt
refused. tools/ci-apt.sh pins the packages apt names (and their siblings
from the same source) to the arm64 version on both architectures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-03 18:19:20 +01:00

42 lines
1.9 KiB
Bash
Executable File

#!/bin/sh
# apt-get install for the CI's two architectures (amd64 + arm64 multiarch).
#
# ports.ubuntu.com (arm64) often lags behind the main mirror (amd64). A
# "Multi-Arch: same" library must have one version on both architectures, so
# when the image already has a newer amd64 build (libpcre2, glib...) apt
# gives up ("held broken packages"). Then this script takes the arm64
# packages apt complains about, and pins every installed package of the same
# source package on both architectures to the arm64 candidate version
# (a downgrade on amd64), and tries again.
#
# Usage: tools/ci-apt.sh <packages...>
set -u
export DEBIAN_FRONTEND=noninteractive
pins=""
for try in 1 2 3 4; do
if apt-get install -y --no-install-recommends --allow-downgrades "$@" $pins >/tmp/apt.log 2>&1; then
[ -n "$pins" ] && echo "installed with aligned versions:$pins"
exit 0
fi
names=$(sed -n 's/.*Depends: \([a-z0-9.+-]*\):arm64.*/\1/p' /tmp/apt.log | sort -u)
if [ -z "$names" ] || [ "$try" = 4 ]; then
sed -n '/following packages have unmet/,$p' /tmp/apt.log | head -60
tail -20 /tmp/apt.log
exit 1
fi
for n in $names; do
src=$(apt-cache show "$n:arm64" 2>/dev/null | sed -n 's/^Source: \([^ ]*\).*/\1/p' | head -1)
[ -n "$src" ] || src=$n
ver=$(apt-cache policy "$n:arm64" | sed -n 's/^ *Candidate: //p')
[ -n "$ver" ] && [ "$ver" != "(none)" ] || continue
# The package itself and its installed siblings from the same source.
sibs=$(dpkg-query -W -f '${Package} ${source:Package}\n' 2>/dev/null | awk -v s="$src" '$2 == s { print $1 }' | sed 's/:.*//' | sort -u)
for p in $n $sibs; do
v=$(apt-cache policy "$p:arm64" | sed -n 's/^ *Candidate: //p')
[ -n "$v" ] && [ "$v" != "(none)" ] || v=$ver
case " $pins " in *" $p=$v "*) ;; *) pins="$pins $p=$v $p:arm64=$v" ;; esac
done
done
echo "apt: aligning to the arm64 versions:$pins"
done