mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-02 22:25:23 +01:00
92bd7066d4
* ci: cache the apt packages of the Linux jobs, install only the X11 headers GLFW needs The "Install Linux dependencies" step timed out after 15 minutes in many runs: the runners' Ubuntu mirror delivered about 150 kB/s, with 30 s stalls on single files, and the step downloaded 136 packages (32.4 MB) every time. - a local action, .github/actions/apt-install, keeps the downloaded .deb files in the Actions cache, keyed by the runner image and the package list. With the same image and list it installs the cached files without apt-get update and without the mirror; otherwise it runs apt-get update and downloads only what the cache lacks - --no-install-recommends, and Acquire::Languages "none" for apt-get update - xorg-dev (about 45 packages nothing used) is replaced by the X11 headers GLFW 3.4 checks for: libx11-dev, libxcursor-dev, libxext-dev, libxi-dev, libxinerama-dev, libxrandr-dev; pkg-config is listed, as it is only a recommendation of libsndfile1-dev - Build, Build binaries and Coverage use it; Coverage gets the 15-minute step timeout and the apt retries too - Dependabot also updates the actions pinned in .github/actions * ci: a repaired apt cache is saved under a key of its own run, and the newest one is restored
138 lines
6.6 KiB
YAML
138 lines
6.6 KiB
YAML
# Installs Ubuntu packages, with the downloaded .deb files kept in the Actions cache.
|
|
#
|
|
# The Ubuntu mirror of the hosted runners has been slow: about 150 kB/s, with stalls of 30 s on single files,
|
|
# so 130 small packages took over 13 minutes to download. The .deb files of the last install are kept in the
|
|
# cache, under a key of the runner image and the package list:
|
|
# - the same image and list (the usual case): the cached files are installed as they are, without the mirror
|
|
# and without `apt-get update`; should that fail, the next way is taken
|
|
# - otherwise: `apt-get update`, then `apt-get install`, which takes the cached files of the same version
|
|
# (checked against the index) and downloads the rest; the files of this install are cached for the next run
|
|
#
|
|
# A cache entry can't be overwritten, so each one is saved under the key with the run appended, and the newest
|
|
# entry of a key is restored by its prefix. Cached files that failed to install are then replaced by the next
|
|
# save rather than restored again on every run of that image.
|
|
#
|
|
# Caches of a pull request are seen only by that pull request; the pushes to staging and master (Build binaries)
|
|
# fill the ones every pull request starts from.
|
|
|
|
name: Install apt packages
|
|
description: apt-get install, with the downloaded packages kept in the Actions cache
|
|
|
|
inputs:
|
|
packages:
|
|
description: The packages to install, separated by spaces or new lines
|
|
required: true
|
|
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
# the key: the runner image (its packages are what the cached files were resolved against) and the list,
|
|
# sorted, so neither its order nor its line breaks change it. Without ImageVersion (not a GitHub-hosted
|
|
# runner) the image isn't known, so the cached files are never installed as they are
|
|
- name: Cache key of the packages
|
|
id: key
|
|
shell: bash
|
|
env:
|
|
PACKAGES: ${{ inputs.packages }}
|
|
run: |
|
|
set -euo pipefail
|
|
printf '%s\n' "$PACKAGES" | tr -s '[:space:]' '\n' | sed '/^$/d' | sort -u > "$RUNNER_TEMP/apt-packages.txt"
|
|
os="${ImageOS:-$(. /etc/os-release && echo "${ID}${VERSION_ID}")}"
|
|
image="${ImageVersion:-unknown}"
|
|
prefix="apt-v2-${os}-$(dpkg --print-architecture)-"
|
|
list_hash="$(sha256sum < "$RUNNER_TEMP/apt-packages.txt" | cut -c1-16)"
|
|
{
|
|
echo "key=${prefix}${image}-${list_hash}"
|
|
echo "save-key=${prefix}${image}-${list_hash}-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
|
|
echo "image-prefix=${prefix}${image}-"
|
|
echo "prefix=${prefix}"
|
|
echo "known-image=$([ -n "${ImageVersion:-}" ] && echo true || echo false)"
|
|
} >> "$GITHUB_OUTPUT"
|
|
cat "$RUNNER_TEMP/apt-packages.txt"
|
|
|
|
# no entry is saved under the key itself, so this restores the newest entry of the key (by its prefix), else
|
|
# a cache of another list (another workflow) or of an older image: the files apt finds there in the version
|
|
# it wants aren't downloaded again
|
|
- name: Restore the downloaded packages
|
|
id: restore
|
|
uses: actions/cache/restore@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
|
|
with:
|
|
path: /tmp/apt-archives
|
|
key: ${{ steps.key.outputs.key }}
|
|
restore-keys: |
|
|
${{ steps.key.outputs.image-prefix }}
|
|
${{ steps.key.outputs.prefix }}
|
|
|
|
# /tmp rather than the runner's temp folder: apt downloads as the user _apt, who has to reach the folder.
|
|
# Recommended packages are left out: the build needs the headers and libraries the packages depend on
|
|
- name: Install the packages
|
|
id: install
|
|
shell: bash
|
|
env:
|
|
EXACT_HIT: ${{ startsWith(steps.restore.outputs.cache-matched-key, format('{0}-', steps.key.outputs.key)) && steps.key.outputs.known-image == 'true' }}
|
|
run: |
|
|
set -euo pipefail
|
|
archives=/tmp/apt-archives
|
|
mkdir -p "$archives/partial"
|
|
|
|
# a mirror that stops answering used to hold this step for over an hour: time out each download and
|
|
# retry it. The translations of the package descriptions aren't needed
|
|
printf '%s\n' \
|
|
'Acquire::Retries "3";' \
|
|
'Acquire::http::Timeout "60";' \
|
|
'Acquire::https::Timeout "60";' \
|
|
'Acquire::Languages "none";' \
|
|
| sudo tee /etc/apt/apt.conf.d/80-ci-retries > /dev/null
|
|
|
|
mapfile -t packages < "$RUNNER_TEMP/apt-packages.txt"
|
|
apt=(sudo apt-get -y --no-install-recommends -o "Dir::Cache::Archives=$archives/")
|
|
|
|
all_installed() {
|
|
local package
|
|
for package in "${packages[@]}"; do
|
|
[[ "$(dpkg-query -W -f '${db:Status-Abbrev}' "$package" 2> /dev/null)" == ii* ]] || return 1
|
|
done
|
|
}
|
|
|
|
done=false
|
|
fix=()
|
|
if [ "$EXACT_HIT" = true ] && compgen -G "$archives/*.deb" > /dev/null; then
|
|
echo "::group::Install the $(ls "$archives"/*.deb | wc -l) cached packages"
|
|
if "${apt[@]}" install "$archives"/*.deb && all_installed; then
|
|
done=true
|
|
echo "from-cache=true" >> "$GITHUB_OUTPUT"
|
|
else
|
|
echo "::warning::The cached packages didn't install; installing from the mirror"
|
|
fix=(--fix-broken)
|
|
fi
|
|
echo "::endgroup::"
|
|
fi
|
|
|
|
if [ "$done" != true ]; then
|
|
sudo apt-get update
|
|
"${apt[@]}" "${fix[@]}" install "${packages[@]}"
|
|
all_installed
|
|
fi
|
|
|
|
# only the files of the packages now installed are kept, in the version installed: the cached files then
|
|
# are exactly this install, and the next run on this image can install them as they are
|
|
sudo rm -rf "$archives/partial" "$archives/lock"
|
|
sudo chown -R "$(id -u):$(id -g)" "$archives"
|
|
installed="$(dpkg-query -W -f '${db:Status-Abbrev}|${Package}|${Version}|${Architecture}\n' \
|
|
| awk -F'|' '$1 ~ /^ii/ { print $2 "|" $3 "|" $4 }')"
|
|
for deb in "$archives"/*.deb; do
|
|
[ -e "$deb" ] || continue
|
|
id="$(dpkg-deb --show --showformat='${Package}|${Version}|${Architecture}' "$deb")"
|
|
grep -qxF -- "$id" <<< "$installed" || rm -f "$deb"
|
|
done
|
|
echo "Cached packages: $(find "$archives" -maxdepth 1 -name '*.deb' | wc -l), $(du -sh "$archives" | cut -f1)"
|
|
|
|
# saved unless the cached files of this image and list installed as they are: after a miss, and after cached
|
|
# files that failed to install and were replaced from the mirror
|
|
- name: Save the downloaded packages
|
|
if: steps.install.outputs.from-cache != 'true'
|
|
uses: actions/cache/save@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
|
|
with:
|
|
path: /tmp/apt-archives
|
|
key: ${{ steps.key.outputs.save-key }}
|