From 456a12baaa8fba5ccafac2c8a0bd209644dc4e4c Mon Sep 17 00:00:00 2001 From: fres_a Date: Sat, 18 Jul 2026 00:59:35 +0300 Subject: [PATCH] Fix Gitea artifact pagination --- .gitea/workflows/sing-box-rr-sdk-24.10.6.yml | 68 +++++++++++++++++++- 1 file changed, 65 insertions(+), 3 deletions(-) diff --git a/.gitea/workflows/sing-box-rr-sdk-24.10.6.yml b/.gitea/workflows/sing-box-rr-sdk-24.10.6.yml index ff9d0824..ab244ee7 100644 --- a/.gitea/workflows/sing-box-rr-sdk-24.10.6.yml +++ b/.gitea/workflows/sing-box-rr-sdk-24.10.6.yml @@ -59,10 +59,72 @@ jobs: AUTH_ARGS=(-H "Authorization: token $SAM_GAD") fi + fetch_all_artifacts() { + local endpoint="$1" + local artifact_name="$2" + local output="$3" + local limit=50 + local page=1 + local seen=0 + local page_json page_count total_count + local items_jsonl="${output}.items.jsonl" + + : > "$items_jsonl" + + while :; do + page_json="${output}.page-${page}.json" + curl -fsSL "${AUTH_ARGS[@]}" --get \ + --data-urlencode "name=${artifact_name}" \ + --data-urlencode "limit=${limit}" \ + --data-urlencode "page=${page}" \ + "$endpoint" \ + -o "$page_json" + + page_count="$(jq ' + def arr: + if type == "array" then . + elif has("artifacts") then .artifacts + elif has("data") then .data + else [] end; + arr | length + ' "$page_json")" + + jq -c ' + def arr: + if type == "array" then . + elif has("artifacts") then .artifacts + elif has("data") then .data + else [] end; + arr[]? + ' "$page_json" >> "$items_jsonl" + + seen=$((seen + page_count)) + total_count="$(jq -r ' + if type == "object" then (.total_count // .total // 0) + else 0 end + ' "$page_json")" + + if [ "$page_count" -eq 0 ]; then + break + fi + if [ "$total_count" -gt 0 ] && [ "$seen" -ge "$total_count" ]; then + break + fi + if [ "$page_count" -lt "$limit" ]; then + break + fi + + page=$((page + 1)) + done + + jq -s '{artifacts: .}' "$items_jsonl" > "$output" + } + artifacts_json="$RUNNER_TEMP/rr-wrt-artifacts.json" - curl -fsSL "${AUTH_ARGS[@]}" \ - "${API_BASE}/artifacts?name=${RR_ARTIFACT_NAME}&per_page=100&page=1" \ - -o "$artifacts_json" + fetch_all_artifacts \ + "${API_BASE}/artifacts" \ + "$RR_ARTIFACT_NAME" \ + "$artifacts_json" jq -r ' def arr: