Filter stale APKs from CI package cache
Build Alpine Packages / build-and-publish (v3.24, 3.24) (push) Has been cancelled

This commit is contained in:
Joachim Schlöffel
2026-07-12 10:09:45 +02:00
parent 7781653941
commit faf7d5e404
4 changed files with 134 additions and 21 deletions
+36 -2
View File
@@ -2,8 +2,12 @@
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_name="${ALPINE_REPO_NAME:-local}"
alpine_version="${ALPINE_VERSION:-3.24}"
arches="${ALPINE_ARCHES:-x86_64 aarch64}"
branch="${ALPINE_REGISTRY_BRANCH:-v${alpine_version}}"
repository="${ALPINE_REGISTRY_REPOSITORY:-${PACKAGE_NAME:-main}}"
instance_url="${INSTANCE_URL:-}"
@@ -46,20 +50,50 @@ if [[ "${#apks[@]}" -eq 0 ]]; then
exit 1
fi
declare -A expected_apks=()
while IFS= read -r package_dir; do
apk_validate_package_dir "${package_dir}"
for arch in ${arches}; do
if ! apk_package_supports_arch "${package_dir}" "${arch}"; then
continue
fi
while IFS= read -r apk_name; do
expected_apks["${package_root}/${arch}/${apk_name}"]=1
done < <(apk_package_apk_names "${package_dir}" "${arch}")
done
done < <(apk_all_package_dirs "${repo_root}")
declare -A published_filenames=()
unique_apks=()
stale_count=0
duplicate_count=0
for apk in "${apks[@]}"; do
filename="$(basename "${apk}")"
if [[ -z "${expected_apks[${apk}]:-}" ]]; then
printf 'Skipping stale local APK: %s\n' "${apk#"${repo_root}/"}"
stale_count=$((stale_count + 1))
continue
fi
if [[ -n "${published_filenames[${filename}]:-}" ]]; then
duplicate_count=$((duplicate_count + 1))
continue
fi
published_filenames["${filename}"]=1
unique_apks+=("${apk}")
done
if [[ "${#unique_apks[@]}" -eq 0 ]]; then
printf 'no current APK files found under %s\n' "${package_root}" >&2
exit 1
fi
printf 'Publishing %d APK files to %s\n' "${#unique_apks[@]}" "${upload_url}"
if [[ "${#unique_apks[@]}" -ne "${#apks[@]}" ]]; then
printf 'Skipping %d duplicate local APK filename(s)\n' "$((${#apks[@]} - ${#unique_apks[@]}))"
if [[ "${duplicate_count}" -ne 0 ]]; then
printf 'Skipping %d duplicate local APK filename(s)\n' "${duplicate_count}"
fi
if [[ "${stale_count}" -ne 0 ]]; then
printf 'Skipping %d stale local APK file(s)\n' "${stale_count}"
fi
for apk in "${unique_apks[@]}"; do