Forráskód Böngészése

fix(build): page artifact lookup via temp file, avoid ARG_MAX overflow

resolve_artifact accumulated every artifact into a single all_artifacts
JSON string passed as --argjson on the command line each loop iteration.
On large runs (many artifacts) this exceeded the OS argument-length limit
('jq: Argument list too long'). Rewrite to page through the API and check
each page for the exact name using a temp file for jq input (not argv),
stopping as soon as a match is found. Output shape (url + digest) is
unchanged.
TheWildJames 2 hete
szülő
commit
6ae4475a82
1 módosított fájl, 22 hozzáadás és 17 törlés
  1. 22 17
      .github/workflows/build.yml

+ 22 - 17
.github/workflows/build.yml

@@ -603,33 +603,38 @@ jobs:
 
         resolve_artifact() {
           local artifact_name="$1"
-          local all_artifacts="[]"
           local page=1
-          local has_more=true
-
-          while [ "$has_more" = "true" ]; do
-            page_content="$(curl --fail --silent --show-error --location \
+          local match=""
+          local page_file
+          page_file="$(mktemp)"
+
+          # Page through the artifacts API, checking each page for the exact
+          # artifact name. Uses a temp file for jq input (not argv) so large
+          # artifact lists can't exceed the OS argument-length limit.
+          while :; do
+            curl --fail --silent --show-error --location \
               --header "Authorization: Bearer ${GH_TOKEN}" \
               --header "X-GitHub-Api-Version: 2022-11-28" \
-              "${artifacts_api}&page=${page}")"
-            all_artifacts="$(jq -cn --argjson acc "$all_artifacts" --argjson cur "$page_content" \
-              '$acc + $cur.artifacts')"
-            items="$(jq '(.artifacts | length) // 0' <<<"$page_content")"
-            if [ "$items" -lt 100 ]; then
-              has_more=false
+              "${artifacts_api}&page=${page}" -o "$page_file"
+
+            match="$(jq -r --arg name "$artifact_name" \
+              '[.artifacts[] | select(.name == $name and .expired == false)] | .[0]
+               | if . == null then "" else (.archive_download_url + "\t" + .digest) end' \
+              "$page_file")"
+
+            items="$(jq '(.artifacts | length) // 0' "$page_file")"
+            if [ "$items" -lt 100 ] || [ -n "$match" ]; then
+              break
             fi
             page=$((page + 1))
           done
 
-          local matches
-          matches="$(jq --arg name "$artifact_name" \
-            '[.artifacts[] | select(.name == $name and .expired == false)]' \
-            <<<"{\"artifacts\": $all_artifacts}")"
-          if [ "$(jq 'length' <<<"$matches")" -ne 1 ]; then
+          rm -f "$page_file"
+          if [ -z "$match" ]; then
             echo "Expected exactly one available artifact named ${artifact_name}." >&2
             exit 1
           fi
-          jq -r '.[0] | [.archive_download_url, .digest] | @tsv' <<<"$matches"
+          printf '%s\n' "$match"
         }
 
         read -r kernel_artifact_url kernel_artifact_sha256 < <(