mirror-ublue-os-akmods/build_files/prep/dnf-retry.sh
Benjamin Sherman bd91a7eb53
fix(ci): stop four recurring CI flakes (#618)
* fix(build): retry dnf installs with fresh metadata

Fedora updates pushes leave mirrors briefly inconsistent. dnf rejects the
new repomd, accepts an older one, then 404s on RPMs that have already been
removed. A plain retry reuses that metadata, especially with the persistent
libdnf5 cache, so refresh it between attempts.

* fix(zfs): pin ZFS release instead of querying the GitHub API

Unauthenticated api.github.com calls from shared runner IPs get rate-limited,
and short curl retries cannot outlast an hourly limit. Pinning the full
release removes that call and makes version bumps show up as PRs.

BREAKING: ZFS_MINOR_VERSION and zfs.*.minor_version are no longer read.
Use ZFS_VERSION and zfs.*.version (full X.Y.Z). Renovate manages the pin.

* fix(just): resolve CoreOS kernel without pulling the image

cache-kernel pulls the full fedora-coreos image on every arch just to run
rpm -q kernel, and a quay.io CDN EOF fails the job. Read the build id from
the image index and the kernel from commitmeta.json instead.

An empty or invalid cache.json was also published, so the later step failed
with "Input required and not supplied: path". Write the cache only after
the fields check out, and drop a restored cache that does not match.

* fix(just): retry koji kernel lookups

A transient curl error was treated as "not found" because the check matched
the string "200 OK" with no retry. That dropped the release number by 100
and could select the wrong kernel or none. Retry transport failures, and
only use the fallback after a successful request that returns 404.

* docs: document RPMFUSION_MIRROR build override

The variable already changes where the build fetches RPM Fusion packages,
but it was not listed with the other Justfile environment variables.
2026-10-24 18:08:40 -05:00

21 lines
833 B
Bash

# shellcheck shell=bash
# dnf_retry <dnf args...>: retry dnf with fresh metadata after a failure.
dnf_retry() {
local attempts="${DNF_RETRY_ATTEMPTS:-3}" delay="${DNF_RETRY_DELAY:-90}"
local attempt=1 rc=0
while :; do
if (( attempt == 1 )); then
dnf "$@" && return 0 || rc=$?
else
dnf --refresh "$@" && return 0 || rc=$?
fi
if (( attempt >= attempts )); then
echo "dnf_retry: giving up after ${attempt} attempts (exit ${rc})" >&2
return "$rc"
fi
echo "dnf_retry: attempt ${attempt}/${attempts} failed (exit ${rc}); refreshing metadata" >&2
dnf clean metadata || echo "dnf_retry: 'dnf clean metadata' failed (exit $?), continuing" >&2
sleep $(( delay * attempt ))
attempt=$(( attempt + 1 ))
done
}