@@ -43,19 +43,30 @@ tpl_tmp_file="$(mktemp)"
4343envsubst ' $GITHUB_HEAD_REF' < " $CURDIR " /artifact_template.tpl > " $tpl_tmp_file "
4444ARTIFACT_TEMPLATE=" $( cat " $tpl_tmp_file " ) "
4545
46- ARTIFACT_API_URL=" /repos/$GITHUB_REPOSITORY /actions/artifacts"
47- gh api " $ARTIFACT_API_URL " --paginate --template " $ARTIFACT_TEMPLATE "
46+ RUNS_API_URL=" /repos/$GITHUB_REPOSITORY /actions/runs"
47+
48+ # List workflow runs scoped to the PR branch instead of paginating all repo artifacts.
49+ # This avoids timeouts in large repositories with many accumulated artifacts.
50+ runIds=" $( gh api " ${RUNS_API_URL} ?branch=${GITHUB_HEAD_REF} &per_page=100" --paginate --jq ' .workflow_runs[].id' ) "
51+
52+ for runId in $runIds ; do
53+ gh api " /repos/$GITHUB_REPOSITORY /actions/runs/$runId /artifacts" --template " $ARTIFACT_TEMPLATE "
54+ done
4855echo
4956
50- artifactIds=" $( gh api " $ARTIFACT_API_URL " --paginate --jq ' .artifacts[] | select(.workflow_run.head_branch == "' " $GITHUB_HEAD_REF " ' ") | .id' ) "
5157echo " Deleting artifacts..."
52- for artifactId in $artifactIds
53- do
54- echo " Deleting artifact: $artifactId "
55- gh api -X DELETE " $ARTIFACT_API_URL /$artifactId " || true
58+ for runId in $runIds ; do
59+ artifactIds=" $( gh api " /repos/$GITHUB_REPOSITORY /actions/runs/$runId /artifacts" --jq ' .artifacts[].id' ) "
60+ for artifactId in $artifactIds
61+ do
62+ echo " Deleting artifact: $artifactId "
63+ gh api -X DELETE " /repos/$GITHUB_REPOSITORY /actions/artifacts/$artifactId " || true
64+ done
5665done
5766echo
5867
5968echo " Fetching list of artifacts after deletion"
60- gh api " $ARTIFACT_API_URL " --paginate --template " $ARTIFACT_TEMPLATE "
69+ for runId in $runIds ; do
70+ gh api " /repos/$GITHUB_REPOSITORY /actions/runs/$runId /artifacts" --template " $ARTIFACT_TEMPLATE "
71+ done
6172echo " ::endgroup::"
0 commit comments