[CI] Skip apt-get when the required packages are already installed (#33757)

This commit is contained in:
Liangsheng Yin
2026-08-05 15:06:01 -07:00
committed by GitHub
parent a3a1ebc7b7
commit 2d27133fcf
+21 -11
View File
@@ -134,22 +134,32 @@ cleanup_stale_shm() {
}
install_apt_packages() {
apt-get update || true
CI_APT_PACKAGES=(
python3 python3-pip python3-venv python3-dev git libnuma-dev libssl-dev pkg-config
libibverbs-dev libibverbs1 ibverbs-providers ibverbs-utils
ffmpeg libavcodec-dev libavformat-dev libavutil-dev libswscale-dev
)
apt-get install -y --no-install-recommends "${CI_APT_PACKAGES[@]}" || {
echo "Warning: apt-get install failed, checking if required packages are available..."
for pkg in "${CI_APT_PACKAGES[@]}"; do
if ! dpkg -l "$pkg" 2>/dev/null | grep -q "^ii"; then
echo "ERROR: Required package $pkg is not installed and apt-get failed"
exit 1
fi
done
echo "All required packages are already installed, continuing..."
}
# The images bake these in, so the usual run pays apt-get update's round
# trips to install nothing. Skipping it costs no currency either: apt-get
# install only ever considers the packages named above, and a passing run
# leaves 100+ others un-upgraded - the image is what pins these versions.
local pkg
local -a MISSING_APT_PACKAGES=()
for pkg in "${CI_APT_PACKAGES[@]}"; do
dpkg -l "$pkg" 2>/dev/null | grep -q "^ii" || MISSING_APT_PACKAGES+=("$pkg")
done
if [ ${#MISSING_APT_PACKAGES[@]} -eq 0 ]; then
echo "All required apt packages are already installed, skipping apt-get"
else
echo "Installing missing apt packages: ${MISSING_APT_PACKAGES[*]}"
apt-get update || true
apt-get install -y --no-install-recommends "${MISSING_APT_PACKAGES[@]}" || {
echo "ERROR: apt-get failed to install: ${MISSING_APT_PACKAGES[*]}"
exit 1
}
fi
mark_step_done "${FUNCNAME[0]}"
}