Files
alpine-packages/scripts/apk/list-packages.sh
T
Joachim Schlöffel faf7d5e404
Build Alpine Packages / build-and-publish (v3.24, 3.24) (push) Has been cancelled
Filter stale APKs from CI package cache
2026-07-12 10:09:45 +02:00

59 lines
1.6 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
# shellcheck source=scripts/apk/package-lib.sh
. "${repo_root}/scripts/apk/package-lib.sh"
repo_dir="${repo_root}/packages/local"
arches="${ALPINE_ARCHES:-x86_64 aarch64}"
declare -A expected_apks=()
while IFS= read -r package_source_dir; do
apk_validate_package_dir "${package_source_dir}"
for arch in ${arches}; do
if ! apk_package_supports_arch "${package_source_dir}" "${arch}"; then
continue
fi
while IFS= read -r apk_name; do
expected_apks["${repo_dir}/${arch}/${apk_name}"]=1
done < <(apk_package_apk_names "${package_source_dir}" "${arch}")
done
done < <(apk_all_package_dirs "${repo_root}")
if [[ -n "${ALPINE_ARCH:-}" ]]; then
package_dirs=("${repo_dir}/${ALPINE_ARCH}")
else
package_dirs=("${repo_dir}"/*)
fi
if [[ ! -d "${repo_dir}" || ! -d "${package_dirs[0]}" ]]; then
printf 'missing local repository: packages/local\n' >&2
printf 'run: mise run apk:build-all\n' >&2
exit 1
fi
for package_dir in "${package_dirs[@]}"; do
[[ -d "${package_dir}" ]] || continue
shopt -s nullglob
apks=("${package_dir}"/*.apk)
shopt -u nullglob
if [[ "${#apks[@]}" -eq 0 ]]; then
continue
fi
printf '## %s\n' "$(basename "${package_dir}")"
for apk in "${apks[@]}"; do
if [[ -z "${expected_apks[${apk}]:-}" ]]; then
printf 'Skipping stale local APK: %s\n' "${apk#"${repo_root}/"}"
continue
fi
printf '### %s\n' "$(basename "${apk}")"
tar -xOf "${apk}" .PKGINFO 2>/dev/null \
| sed -n '/^pkgname =/p;/^pkgver =/p;/^arch =/p;/^depend =/p;/^provides =/p;/^install_if =/p'
done
done