chore: prettify cleanup action logs
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
- 預設每個套件保留最新 `2` 個版本。
|
||||
- 直接刪除超出保留數量的舊版本。
|
||||
- 只處理你指定的 NuGet 套件名稱,可一次指定多個。
|
||||
- 輸出精簡 log,只保留必要的錯誤與 summary。
|
||||
- 輸出整理過的 log,分成 summary、delete queue、delete results 幾個區塊。
|
||||
- 每頁預設抓取 100 筆版本,可用 `PAGE_LIMIT` 調整。
|
||||
|
||||
## Token 來源順序
|
||||
@@ -33,9 +33,11 @@ Action 會依序嘗試以下來源:
|
||||
|
||||
執行時只會輸出必要資訊:
|
||||
|
||||
- `ERROR: ...`
|
||||
- `Cleanup summary`
|
||||
- `Delete queue`
|
||||
- `Delete results`
|
||||
- `Final summary`
|
||||
- `Summary: packages=... versions=... kept=... candidates=... deleted=... errors=...`
|
||||
- `No matching packages found for requested package_names` 之類的少量狀態訊息
|
||||
|
||||
## Workflow 範例
|
||||
|
||||
|
||||
+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}"
|
||||
}
|
||||
|
||||
+8
-1
@@ -396,6 +396,7 @@ test_process_candidates_empty() {
|
||||
candidate_file="$(mktemp)"
|
||||
|
||||
capture_call process_candidates acme "${candidate_file}" 0 0 0 0 token
|
||||
assert_contains "${CAPTURE_STDERR}" "Cleanup summary" "process_candidates empty section"
|
||||
assert_contains "${CAPTURE_STDERR}" "Summary: packages=0 versions=0 kept=0 candidates=0 deleted=0 errors=0" "process_candidates empty summary"
|
||||
}
|
||||
|
||||
@@ -410,7 +411,10 @@ test_process_candidates() {
|
||||
add_route DELETE "https://gitea.example/api/v1/packages/acme/nuget/pkg-b/2.0.0" 500 "Internal Server Error" del-2 '{"error":"boom"}'
|
||||
|
||||
capture_call process_candidates acme "${candidate_file}" 2 4 3 2 token
|
||||
assert_contains "${CAPTURE_STDERR}" "ERROR: DELETE package pkg-b version 2.0.0 -> 500 Internal Server Error request_id=del-2" "process_candidates failure path"
|
||||
assert_contains "${CAPTURE_STDERR}" "Delete queue" "process_candidates queue section"
|
||||
assert_contains "${CAPTURE_STDERR}" "Delete results" "process_candidates results section"
|
||||
assert_contains "${CAPTURE_STDERR}" " - failed pkg-b@2.0.0 [500 Internal Server Error] request_id=del-2" "process_candidates failure path"
|
||||
assert_contains "${CAPTURE_STDERR}" "Final summary" "process_candidates final summary section"
|
||||
assert_contains "${CAPTURE_STDERR}" "Summary: packages=2 versions=4 kept=3 candidates=2 deleted=1 errors=1" "process_candidates summary"
|
||||
}
|
||||
|
||||
@@ -427,6 +431,9 @@ test_main_integration() {
|
||||
add_route DELETE "https://gitea.example/api/v1/packages/acme/nuget/pkg-a/1.0.0" 204 "No Content" del-a ''
|
||||
|
||||
capture_call main
|
||||
assert_contains "${CAPTURE_STDERR}" "Cleanup summary" "main summary section"
|
||||
assert_contains "${CAPTURE_STDERR}" "Delete queue" "main queue section"
|
||||
assert_contains "${CAPTURE_STDERR}" "Delete results" "main results section"
|
||||
assert_contains "${CAPTURE_STDERR}" "Summary: packages=2 versions=4 kept=3 candidates=1 deleted=1 errors=0" "main summary"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user