From a992f8682629dc070f0af400be12e915f587f608 Mon Sep 17 00:00:00 2001 From: Mate Molnar Date: Mon, 9 Mar 2026 20:00:09 +0100 Subject: [PATCH 1/5] BUILD-10625: fix artifact cleanup timeout by scoping lookup to PR branch runs --- pr_cleanup/cleanup.sh | 27 +++++++++++++++++++-------- spec/pr_cleanup_spec.sh | 4 +++- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/pr_cleanup/cleanup.sh b/pr_cleanup/cleanup.sh index 0cb02b64..02dfbd5a 100755 --- a/pr_cleanup/cleanup.sh +++ b/pr_cleanup/cleanup.sh @@ -43,19 +43,30 @@ tpl_tmp_file="$(mktemp)" envsubst '$GITHUB_HEAD_REF' < "$CURDIR"/artifact_template.tpl > "$tpl_tmp_file" ARTIFACT_TEMPLATE="$(cat "$tpl_tmp_file")" -ARTIFACT_API_URL="/repos/$GITHUB_REPOSITORY/actions/artifacts" -gh api "$ARTIFACT_API_URL" --paginate --template "$ARTIFACT_TEMPLATE" +RUNS_API_URL="/repos/$GITHUB_REPOSITORY/actions/runs" + +# List workflow runs scoped to the PR branch instead of paginating all repo artifacts. +# This avoids timeouts in large repositories with many accumulated artifacts. +runIds="$(gh api "${RUNS_API_URL}?branch=${GITHUB_HEAD_REF}&per_page=100" --paginate --jq '.workflow_runs[].id')" + +for runId in $runIds; do + gh api "/repos/$GITHUB_REPOSITORY/actions/runs/$runId/artifacts" --paginate --template "$ARTIFACT_TEMPLATE" +done echo -artifactIds="$(gh api "$ARTIFACT_API_URL" --paginate --jq '.artifacts[] | select(.workflow_run.head_branch == "'"$GITHUB_HEAD_REF"'") | .id')" echo "Deleting artifacts..." -for artifactId in $artifactIds -do - echo "Deleting artifact: $artifactId" - gh api -X DELETE "$ARTIFACT_API_URL/$artifactId" || true +for runId in $runIds; do + artifactIds="$(gh api "/repos/$GITHUB_REPOSITORY/actions/runs/$runId/artifacts" --paginate --jq '.artifacts[].id')" + for artifactId in $artifactIds + do + echo "Deleting artifact: $artifactId" + gh api -X DELETE "/repos/$GITHUB_REPOSITORY/actions/artifacts/$artifactId" || true + done done echo echo "Fetching list of artifacts after deletion" -gh api "$ARTIFACT_API_URL" --paginate --template "$ARTIFACT_TEMPLATE" +for runId in $runIds; do + gh api "/repos/$GITHUB_REPOSITORY/actions/runs/$runId/artifacts" --paginate --template "$ARTIFACT_TEMPLATE" +done echo "::endgroup::" diff --git a/spec/pr_cleanup_spec.sh b/spec/pr_cleanup_spec.sh index d80cf117..d5d4f061 100755 --- a/spec/pr_cleanup_spec.sh +++ b/spec/pr_cleanup_spec.sh @@ -19,7 +19,9 @@ Describe "cleanup.sh" cat "$CACHE_KEY_TO_DELETE" elif [[ "$*" =~ "cache delete" ]]; then echo "" > "$CACHE_KEY_TO_DELETE" - elif [[ "$*" =~ "api /repos/".*/actions/artifacts.*--paginate ]]; then + elif [[ "$*" =~ "branch=" ]]; then + echo "123456789" + elif [[ "$*" =~ actions/runs/[0-9]+/artifacts ]]; then cat "$ARTIFACT_TO_DELETE" elif [[ "$*" =~ "api -X DELETE" ]]; then echo "" > "$ARTIFACT_TO_DELETE" From e4e19511009aba798393d2f8f1aa7f36d5c5df01 Mon Sep 17 00:00:00 2001 From: Mate Molnar Date: Tue, 10 Mar 2026 10:11:06 +0100 Subject: [PATCH 2/5] BUILD-10625: suppress empty artifact table headers for runs with no artifacts Co-Authored-By: Claude Sonnet 4.6 --- pr_cleanup/artifact_template.tpl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pr_cleanup/artifact_template.tpl b/pr_cleanup/artifact_template.tpl index 7ef9d4b9..c6904a8f 100644 --- a/pr_cleanup/artifact_template.tpl +++ b/pr_cleanup/artifact_template.tpl @@ -1,5 +1,7 @@ +{{- if .artifacts -}} {{tablerow "NAME" "ID" "SIZE (BYTES)" "BRANCH" "HEAD_SHA" "RUN_ID"}} {{- range .artifacts -}} {{- tablerow .name .id .size_in_bytes .workflow_run.head_branch .workflow_run.head_sha .workflow_run.id -}} {{- end -}} {{- tablerender -}} +{{- end -}} From 83613ec03602eb770f8fa29cce8d7708703325c3 Mon Sep 17 00:00:00 2001 From: Mate Molnar Date: Tue, 10 Mar 2026 14:30:51 +0100 Subject: [PATCH 3/5] Update pr_cleanup/cleanup.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- pr_cleanup/cleanup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pr_cleanup/cleanup.sh b/pr_cleanup/cleanup.sh index 02dfbd5a..2297de2d 100755 --- a/pr_cleanup/cleanup.sh +++ b/pr_cleanup/cleanup.sh @@ -47,7 +47,7 @@ RUNS_API_URL="/repos/$GITHUB_REPOSITORY/actions/runs" # List workflow runs scoped to the PR branch instead of paginating all repo artifacts. # This avoids timeouts in large repositories with many accumulated artifacts. -runIds="$(gh api "${RUNS_API_URL}?branch=${GITHUB_HEAD_REF}&per_page=100" --paginate --jq '.workflow_runs[].id')" +runIds="$(gh api "$RUNS_API_URL" -f branch="$GITHUB_HEAD_REF" -f per_page=100 --paginate --jq '.workflow_runs[].id')" for runId in $runIds; do gh api "/repos/$GITHUB_REPOSITORY/actions/runs/$runId/artifacts" --paginate --template "$ARTIFACT_TEMPLATE" From 878cd4d0d616ff0ab7ac6e6a2d2e5cc6acc3d035 Mon Sep 17 00:00:00 2001 From: Mate Molnar Date: Tue, 10 Mar 2026 14:43:43 +0100 Subject: [PATCH 4/5] BUILD-10625: remove redundant envsubst/mktemp for artifact template artifact_template.tpl contains no shell variable references, so envsubst was a no-op producing an uncleaned temp file. Load it directly like the cache template. Co-Authored-By: Claude Sonnet 4.6 --- pr_cleanup/cleanup.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/pr_cleanup/cleanup.sh b/pr_cleanup/cleanup.sh index 2297de2d..7fbee18f 100755 --- a/pr_cleanup/cleanup.sh +++ b/pr_cleanup/cleanup.sh @@ -38,10 +38,7 @@ echo "::endgroup::" echo "::group::Artifact Cleanup" echo "Fetching list of artifacts on $GITHUB_REPOSITORY for $GITHUB_HEAD_REF" -tpl_tmp_file="$(mktemp)" -# shellcheck disable=SC2016 -envsubst '$GITHUB_HEAD_REF' < "$CURDIR"/artifact_template.tpl > "$tpl_tmp_file" -ARTIFACT_TEMPLATE="$(cat "$tpl_tmp_file")" +ARTIFACT_TEMPLATE="$(cat "$CURDIR"/artifact_template.tpl)" RUNS_API_URL="/repos/$GITHUB_REPOSITORY/actions/runs" From 11d25176e67c23db88d4b51da067e96286f5027b Mon Sep 17 00:00:00 2001 From: Mate Molnar Date: Tue, 10 Mar 2026 14:48:47 +0100 Subject: [PATCH 5/5] BUILD-10625: fix GET method lost when using -f flags with gh api gh api implicitly switches to POST when -f flags are used without an explicit -X GET, causing a 404 on the runs endpoint. Co-Authored-By: Claude Sonnet 4.6 --- pr_cleanup/cleanup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pr_cleanup/cleanup.sh b/pr_cleanup/cleanup.sh index 7fbee18f..a6a6ac73 100755 --- a/pr_cleanup/cleanup.sh +++ b/pr_cleanup/cleanup.sh @@ -44,7 +44,7 @@ RUNS_API_URL="/repos/$GITHUB_REPOSITORY/actions/runs" # List workflow runs scoped to the PR branch instead of paginating all repo artifacts. # This avoids timeouts in large repositories with many accumulated artifacts. -runIds="$(gh api "$RUNS_API_URL" -f branch="$GITHUB_HEAD_REF" -f per_page=100 --paginate --jq '.workflow_runs[].id')" +runIds="$(gh api -X GET "$RUNS_API_URL" -f branch="$GITHUB_HEAD_REF" -f per_page=100 --paginate --jq '.workflow_runs[].id')" for runId in $runIds; do gh api "/repos/$GITHUB_REPOSITORY/actions/runs/$runId/artifacts" --paginate --template "$ARTIFACT_TEMPLATE"