diff --git a/.github/actions/apt-install/action.yml b/.github/actions/apt-install/action.yml new file mode 100644 index 000000000..0495b07ac --- /dev/null +++ b/.github/actions/apt-install/action.yml @@ -0,0 +1,137 @@ +# 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 }} diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 0a520876d..23c5f7c9d 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,10 +1,12 @@ -# Keeps the GitHub Actions used by the workflows up to date. The actions are pinned by commit hash, with the -# version in a comment; Dependabot updates both. One pull request a week for all of them, so the workflows -# stay on the same versions. +# Keeps the GitHub Actions used by the workflows and by the local actions (.github/actions) up to date. The actions +# are pinned by commit hash, with the version in a comment; Dependabot updates both. One pull request a week for all +# of them, so the workflows stay on the same versions. version: 2 updates: - package-ecosystem: github-actions - directory: / + directories: + - / + - /.github/actions/* schedule: interval: weekly groups: diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7eaf891fe..3b279bbb0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -41,23 +41,20 @@ jobs: with: python-version: '3.14' - # A mirror that stops answering used to hold this step for over an hour. - # Time out each download, retry it, and give up on the whole step early. + # The packages are kept in the Actions cache (.github/actions/apt-install): the mirror of the + # runners has been too slow to download them every time. The timeout is a safety net. + # The X11 packages are the ones GLFW (ref/glfw, 3.4) looks for; xorg-dev brought ~45 more. - name: Install build dependencies timeout-minutes: 15 - run: | - printf '%s\n' \ - 'Acquire::Retries "3";' \ - 'Acquire::http::Timeout "60";' \ - 'Acquire::https::Timeout "60";' \ - | sudo tee /etc/apt/apt.conf.d/80-ci-retries > /dev/null - sudo apt-get update -y - sudo apt-get install -y \ - build-essential \ - libgl1-mesa-dev libglew-dev libglfw3-dev \ - libpng-dev libopenal-dev libluajit-5.1-dev \ - libserialport-dev libsndfile1-dev \ - xorg-dev libxkbcommon-dev libwayland-dev wayland-protocols + uses: ./.github/actions/apt-install + with: + packages: >- + build-essential pkg-config + libgl1-mesa-dev libglew-dev libglfw3-dev + libpng-dev libopenal-dev libluajit-5.1-dev + libserialport-dev libsndfile1-dev + libx11-dev libxcursor-dev libxext-dev libxi-dev libxinerama-dev libxrandr-dev + libxkbcommon-dev libwayland-dev wayland-protocols - name: Build current OpenAL Soft run: | diff --git a/.github/workflows/build_bin.yml b/.github/workflows/build_bin.yml index 13f36b0c7..91ad66978 100644 --- a/.github/workflows/build_bin.yml +++ b/.github/workflows/build_bin.yml @@ -400,37 +400,39 @@ jobs: with: python-version: "3.14" - # A mirror that stops answering used to hold this step for over an hour. - # Time out each download, retry it, and give up on the whole step early. + # The packages are kept in the Actions cache (.github/actions/apt-install): the mirror of the runners has been + # too slow to download them every time. The timeout is a safety net. + # libasound2-dev, libpulse-dev and libpipewire-0.3-dev: the headers of OpenAL Soft's audio backends (built below). + # Without them it builds with OSS only, which modern distributions and the Steam Linux Runtime don't have: no sound. + # The X11 packages are the ones GLFW (ref/glfw, 3.4) looks for; xorg-dev brought ~45 more. The game loads the + # X11 and Wayland libraries of the system, none of them is bundled (CMake_modules/bundle_runtime_libs.cmake). - name: Install Linux dependencies timeout-minutes: 15 - run: | - printf '%s\n' \ - 'Acquire::Retries "3";' \ - 'Acquire::http::Timeout "60";' \ - 'Acquire::https::Timeout "60";' \ - | sudo tee /etc/apt/apt.conf.d/80-ci-retries > /dev/null - sudo apt-get update - - # libasound2-dev, libpulse-dev and libpipewire-0.3-dev: the headers of OpenAL Soft's audio backends (built below). - # Without them it builds with OSS only, which modern distributions and the Steam Linux Runtime don't have: no sound. - sudo apt-get install -y \ - build-essential \ - libasound2-dev \ - libpulse-dev \ - libpipewire-0.3-dev \ - libgl1-mesa-dev \ - libglew-dev \ - libglfw3-dev \ - libpng-dev \ - libopenal-dev \ - libluajit-5.1-dev \ - libserialport-dev \ - libsndfile1-dev \ - libcurl4-openssl-dev \ - xorg-dev \ - libxkbcommon-dev \ - libwayland-dev \ + uses: ./.github/actions/apt-install + with: + packages: >- + build-essential + pkg-config + libasound2-dev + libpulse-dev + libpipewire-0.3-dev + libgl1-mesa-dev + libglew-dev + libglfw3-dev + libpng-dev + libopenal-dev + libluajit-5.1-dev + libserialport-dev + libsndfile1-dev + libcurl4-openssl-dev + libx11-dev + libxcursor-dev + libxext-dev + libxi-dev + libxinerama-dev + libxrandr-dev + libxkbcommon-dev + libwayland-dev wayland-protocols # diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index d2f00bccd..27fa64bc2 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -47,14 +47,19 @@ jobs: # the same packages as the Build workflow: the game is configured as a whole, # though only the unit tests and the core library they link are built - name: Install build dependencies + timeout-minutes: 15 + uses: ./.github/actions/apt-install + with: + packages: >- + build-essential pkg-config + libgl1-mesa-dev libglew-dev libglfw3-dev + libpng-dev libopenal-dev libluajit-5.1-dev + libserialport-dev libsndfile1-dev + libx11-dev libxcursor-dev libxext-dev libxi-dev libxinerama-dev libxrandr-dev + libxkbcommon-dev libwayland-dev wayland-protocols + + - name: Install gcovr run: | - sudo apt-get update -y - sudo apt-get install -y \ - build-essential \ - libgl1-mesa-dev libglew-dev libglfw3-dev \ - libpng-dev libopenal-dev libluajit-5.1-dev \ - libserialport-dev libsndfile1-dev \ - xorg-dev libxkbcommon-dev libwayland-dev wayland-protocols python3 -m pip install --no-cache-dir --only-binary :all: gcovr==8.3 - name: Build current OpenAL Soft