chore: refine logging output for clarity and conciseness in entrypoint script and README
This commit is contained in:
+1
-35
@@ -33,10 +33,7 @@ url_encode() {
|
||||
|
||||
resolve_token() {
|
||||
# Resolve the already-merged token input passed in RUNNER_TOKEN.
|
||||
log "Trying token from RUNNER_TOKEN"
|
||||
|
||||
if [[ -n "${RUNNER_TOKEN:-}" ]]; then
|
||||
log "Using token from RUNNER_TOKEN"
|
||||
printf '%s' "${RUNNER_TOKEN}"
|
||||
return 0
|
||||
fi
|
||||
@@ -142,12 +139,6 @@ api_request() {
|
||||
awk -F': *' 'tolower($1)=="x-gitea-request-id" || tolower($1)=="x-request-id" {value=$2} END {print value}' "${headers_file}" | tr -d '\r'
|
||||
)"
|
||||
|
||||
if [[ -n "${request_id}" ]]; then
|
||||
log "${method} ${path} -> ${status_text} request_id=${request_id}"
|
||||
else
|
||||
log "${method} ${path} -> ${status_text}"
|
||||
fi
|
||||
|
||||
printf '%s\t%s\t%s\n' "${http_code}" "${status_text}" "${request_id}"
|
||||
}
|
||||
|
||||
@@ -242,7 +233,6 @@ collect_package_candidates() {
|
||||
versions_json="$(fetch_package_versions "${owner}" "${package_name}" "${token}")"
|
||||
|
||||
if [[ "$(jq 'length' <<<"${versions_json}")" -eq 0 ]]; then
|
||||
log "No versions found for package ${package_name}"
|
||||
continue
|
||||
fi
|
||||
|
||||
@@ -250,15 +240,7 @@ collect_package_candidates() {
|
||||
total_versions="$(jq 'length' <<<"${versions_json}")"
|
||||
total_version_count=$((total_version_count + total_versions))
|
||||
|
||||
log "Package ${package_name}: total_versions=${total_versions} keep_count=${keep_count}"
|
||||
log "Package ${package_name} versions (oldest -> newest):"
|
||||
while IFS=$'\t' read -r version created_at; do
|
||||
[[ -z "${version}" ]] && continue
|
||||
log " - ${version} (${created_at})"
|
||||
done < <(jq -r 'sort_by(.created_at, .version)[] | [.version, .created_at] | @tsv' <<<"${versions_json}")
|
||||
|
||||
if (( total_versions <= keep_count )); then
|
||||
log " keep all ${total_versions} versions"
|
||||
kept_count=$((kept_count + total_versions))
|
||||
continue
|
||||
fi
|
||||
@@ -271,7 +253,6 @@ collect_package_candidates() {
|
||||
|
||||
while IFS=$'\t' read -r package version created_at; do
|
||||
[[ -z "${package}" ]] && continue
|
||||
log "Candidate to delete: package ${package} version ${version} (created: ${created_at})"
|
||||
printf '%s\t%s\t%s\n' "${package}" "${version}" "${created_at}" >> "${candidate_file}"
|
||||
candidate_count=$((candidate_count + 1))
|
||||
done < <(jq -r '.[] | [.name, .version, .created_at] | @tsv' <<<"${candidates_json}")
|
||||
@@ -304,7 +285,6 @@ process_candidates() {
|
||||
local body_file headers_file meta http_code status_text request_id
|
||||
|
||||
if [[ ! -s "${candidate_file}" ]]; then
|
||||
log "No delete candidates found"
|
||||
log "Summary: packages=${package_count} versions=${total_version_count} kept=${kept_count} candidates=0 deleted=0 errors=0"
|
||||
return 0
|
||||
fi
|
||||
@@ -323,7 +303,6 @@ process_candidates() {
|
||||
IFS=$'\t' read -r http_code status_text request_id <<< "${meta}"
|
||||
|
||||
if [[ "${http_code}" =~ ^2 ]]; then
|
||||
log "Deleted package ${package_name} version ${version} -> ${status_text}"
|
||||
deleted_count=$((deleted_count + 1))
|
||||
else
|
||||
if [[ -n "${request_id}" ]]; then
|
||||
@@ -342,13 +321,10 @@ process_candidates() {
|
||||
main() {
|
||||
# Entry point for the Docker container. Resolves inputs, builds candidates,
|
||||
# and applies deletes for the selected NuGet packages.
|
||||
local token keep_count repository owner _repo package_names_csv
|
||||
local token keep_count repository owner _repo
|
||||
local -a package_names
|
||||
local candidate_file summary package_count total_version_count kept_count candidate_count
|
||||
|
||||
log "Gitea Server Url: ${GITEA_SERVER_URL:-}"
|
||||
log "Gitea Repository: ${GITEA_REPOSITORY:-}"
|
||||
|
||||
if ! token="$(resolve_token)"; then
|
||||
fail "No Gitea token available, exiting"
|
||||
fi
|
||||
@@ -358,11 +334,6 @@ main() {
|
||||
keep_count="$(resolve_keep_count)"
|
||||
|
||||
mapfile -t package_names < <(resolve_package_names)
|
||||
package_names_csv="$(IFS=,; echo "${package_names[*]}")"
|
||||
|
||||
log "keep_count=${keep_count}"
|
||||
log "package_names=${package_names_csv}"
|
||||
log "Token source resolved successfully"
|
||||
|
||||
candidate_file="$(mktemp)"
|
||||
cleanup_candidate_file="${candidate_file}"
|
||||
@@ -371,12 +342,7 @@ main() {
|
||||
summary="$(collect_package_candidates "${owner}" "${keep_count}" "${candidate_file}" "${token}" "${package_names[@]}")"
|
||||
IFS=$'\t' read -r package_count total_version_count kept_count candidate_count <<< "${summary}"
|
||||
|
||||
if (( package_count == 0 )); then
|
||||
log "No matching packages found for requested package_names"
|
||||
fi
|
||||
|
||||
process_candidates "${owner}" "${candidate_file}" "${package_count}" "${total_version_count}" "${kept_count}" "${candidate_count}" "${token}"
|
||||
log "Stage 4 complete"
|
||||
}
|
||||
|
||||
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
|
||||
|
||||
Reference in New Issue
Block a user