Filter stale APKs from CI package cache
Build Alpine Packages / build-and-publish (v3.24, 3.24) (push) Has been cancelled
Build Alpine Packages / build-and-publish (v3.24, 3.24) (push) Has been cancelled
This commit is contained in:
@@ -14,7 +14,7 @@ command_name="${1:-prepare}"
|
||||
all_packages() {
|
||||
while IFS= read -r package_dir; do
|
||||
apk_package_name "${package_dir}"
|
||||
done < <(apk_package_dirs "${repo_root}")
|
||||
done < <(apk_all_package_dirs "${repo_root}")
|
||||
}
|
||||
|
||||
mark_all_packages() {
|
||||
@@ -97,23 +97,7 @@ package_apk_names() {
|
||||
local package_dir="$1"
|
||||
local arch="$2"
|
||||
|
||||
(
|
||||
set +u
|
||||
local pkgname
|
||||
local pkgver
|
||||
local pkgrel
|
||||
local subpackages
|
||||
export CARCH="${arch}"
|
||||
cd "${package_dir}"
|
||||
# shellcheck source=/dev/null
|
||||
. ./APKBUILD
|
||||
|
||||
printf '%s-%s-r%s.apk\n' "${pkgname}" "${pkgver}" "${pkgrel}"
|
||||
for subpackage in ${subpackages:-}; do
|
||||
subpackage="${subpackage%%:*}"
|
||||
printf '%s-%s-r%s.apk\n' "${subpackage}" "${pkgver}" "${pkgrel}"
|
||||
done
|
||||
)
|
||||
apk_package_apk_names "${package_dir}" "${arch}"
|
||||
}
|
||||
|
||||
package_cache_complete() {
|
||||
@@ -155,7 +139,46 @@ select_missing_packages() {
|
||||
if ! package_cache_complete "${package_dir}"; then
|
||||
printf '%s\n' "${package_name}"
|
||||
fi
|
||||
done < <(apk_package_dirs "${repo_root}")
|
||||
done < <(apk_all_package_dirs "${repo_root}")
|
||||
}
|
||||
|
||||
prune_stale_apks() {
|
||||
local package_dir
|
||||
local arch
|
||||
local apk_name
|
||||
local current_apk
|
||||
declare -A expected_apks=()
|
||||
|
||||
if [[ ! -d "${repo_dest}" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
while IFS= read -r package_dir; do
|
||||
apk_validate_package_dir "${package_dir}"
|
||||
for arch in ${arches}; do
|
||||
case "${arch}" in
|
||||
x86_64|aarch64) ;;
|
||||
*) printf 'unsupported Alpine architecture: %s\n' "${arch}" >&2; exit 2 ;;
|
||||
esac
|
||||
|
||||
if ! apk_package_supports_arch "${package_dir}" "${arch}"; then
|
||||
continue
|
||||
fi
|
||||
|
||||
while IFS= read -r apk_name; do
|
||||
expected_apks["${repo_dest}/${arch}/${apk_name}"]=1
|
||||
done < <(package_apk_names "${package_dir}" "${arch}")
|
||||
done
|
||||
done < <(apk_all_package_dirs "${repo_root}")
|
||||
|
||||
shopt -s nullglob
|
||||
for current_apk in "${repo_dest}"/*/*.apk; do
|
||||
if [[ -z "${expected_apks[${current_apk}]:-}" ]]; then
|
||||
rm -f "${current_apk}"
|
||||
printf 'Pruned stale cached APK: %s\n' "${current_apk#"${repo_root}/"}"
|
||||
fi
|
||||
done
|
||||
shopt -u nullglob
|
||||
}
|
||||
|
||||
prepare() {
|
||||
@@ -164,6 +187,7 @@ prepare() {
|
||||
declare -A selected_map=()
|
||||
|
||||
restore_cache
|
||||
prune_stale_apks
|
||||
|
||||
while IFS= read -r selected; do
|
||||
[[ -n "${selected}" ]] || continue
|
||||
@@ -205,6 +229,7 @@ sync_cache() {
|
||||
exit 1
|
||||
fi
|
||||
|
||||
prune_stale_apks
|
||||
mkdir -p "${cache_root}"
|
||||
find "${cache_root}" -mindepth 1 -maxdepth 1 -exec rm -rf {} +
|
||||
cp -a "${repo_dest}/." "${cache_root}/"
|
||||
|
||||
Reference in New Issue
Block a user