chore: prettify cleanup action logs
This commit is contained in:
+46
-2
@@ -10,6 +10,15 @@ fail() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
section() {
|
||||
log ""
|
||||
log "$1"
|
||||
}
|
||||
|
||||
kv() {
|
||||
printf ' %-11s: %s\n' "$1" "$2" >&2
|
||||
}
|
||||
|
||||
cleanup_candidate_file=""
|
||||
|
||||
cleanup() {
|
||||
@@ -283,8 +292,16 @@ process_candidates() {
|
||||
local package_name version _created_at
|
||||
local encoded_owner encoded_package_name encoded_version
|
||||
local body_file headers_file meta http_code status_text request_id
|
||||
local current_package=""
|
||||
|
||||
if [[ ! -s "${candidate_file}" ]]; then
|
||||
section "Cleanup summary"
|
||||
kv "packages" "${package_count}"
|
||||
kv "versions" "${total_version_count}"
|
||||
kv "kept" "${kept_count}"
|
||||
kv "candidates" "0"
|
||||
kv "deleted" "0"
|
||||
kv "errors" "0"
|
||||
log "Summary: packages=${package_count} versions=${total_version_count} kept=${kept_count} candidates=0 deleted=0 errors=0"
|
||||
return 0
|
||||
fi
|
||||
@@ -292,6 +309,25 @@ process_candidates() {
|
||||
body_file="$(mktemp)"
|
||||
headers_file="$(mktemp)"
|
||||
encoded_owner="$(url_encode "${owner}")"
|
||||
|
||||
section "Cleanup summary"
|
||||
kv "packages" "${package_count}"
|
||||
kv "versions" "${total_version_count}"
|
||||
kv "kept" "${kept_count}"
|
||||
kv "candidates" "${candidate_count}"
|
||||
|
||||
section "Delete queue"
|
||||
while IFS=$'\t' read -r package_name version _created_at; do
|
||||
[[ -z "${package_name}" ]] && continue
|
||||
|
||||
if [[ "${package_name}" != "${current_package:-}" ]]; then
|
||||
current_package="${package_name}"
|
||||
log " ${current_package}"
|
||||
fi
|
||||
log " - ${version} (created_at=${_created_at})"
|
||||
done < "${candidate_file}"
|
||||
|
||||
section "Delete results"
|
||||
while IFS=$'\t' read -r package_name version _created_at; do
|
||||
[[ -z "${package_name}" ]] && continue
|
||||
|
||||
@@ -304,16 +340,24 @@ process_candidates() {
|
||||
|
||||
if [[ "${http_code}" =~ ^2 ]]; then
|
||||
deleted_count=$((deleted_count + 1))
|
||||
log " - deleted ${package_name}@${version} [${status_text}]"
|
||||
else
|
||||
if [[ -n "${request_id}" ]]; then
|
||||
log "ERROR: DELETE package ${package_name} version ${version} -> ${status_text} request_id=${request_id}"
|
||||
log " - failed ${package_name}@${version} [${status_text}] request_id=${request_id}"
|
||||
else
|
||||
log "ERROR: DELETE package ${package_name} version ${version} -> ${status_text}"
|
||||
log " - failed ${package_name}@${version} [${status_text}]"
|
||||
fi
|
||||
error_count=$((error_count + 1))
|
||||
fi
|
||||
done < "${candidate_file}"
|
||||
|
||||
section "Final summary"
|
||||
kv "packages" "${package_count}"
|
||||
kv "versions" "${total_version_count}"
|
||||
kv "kept" "${kept_count}"
|
||||
kv "candidates" "${candidate_count}"
|
||||
kv "deleted" "${deleted_count}"
|
||||
kv "errors" "${error_count}"
|
||||
log "Summary: packages=${package_count} versions=${total_version_count} kept=${kept_count} candidates=${candidate_count} deleted=${deleted_count} errors=${error_count}"
|
||||
rm -f "${body_file}" "${headers_file}"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user