Skip to content

BUILD-10625: fix artifact cleanup timeout by scoping lookup to PR branch runs#228

Merged
matemoln merged 5 commits intomasterfrom
bugfix/matemoln/BUILD-10625-pr-cleanup-artifacts
Mar 11, 2026
Merged

BUILD-10625: fix artifact cleanup timeout by scoping lookup to PR branch runs#228
matemoln merged 5 commits intomasterfrom
bugfix/matemoln/BUILD-10625-pr-cleanup-artifacts

Conversation

@matemoln
Copy link
Contributor

@matemoln matemoln commented Mar 9, 2026

Summary

  • The pr_cleanup/cleanup.sh script was paginating all repository artifacts (/repos/.../actions/artifacts --paginate) to find ones matching the closed PR's head branch. In sonar-enterprise this means iterating ~199,000 artifacts across ~2,000 API pages, causing the job to time out on every PR close.
  • Fix: replaced full-repo artifact pagination with a branch-scoped two-step lookup:
    1. Fetch workflow run IDs for $GITHUB_HEAD_REF via /actions/runs?branch=<branch> — bounded by the number of CI runs for that branch, typically a few dozen API pages at most.
    2. For each run, list and delete its artifacts via /actions/runs/<runId>/artifacts --paginate — ensures all artifacts are captured even when a run has more than 30.
  • Also fixed: artifact display template now suppresses empty header rows for runs with no artifacts (previously printed one empty table header per run ID after deletion).
  • Updated spec/pr_cleanup_spec.sh to mock the new API call pattern.

Fixes: https://sonarsource.atlassian.net/browse/BUILD-10625
Related: https://sonarsource.atlassian.net/browse/PREQ-4580

Test plan

@hashicorp-vault-sonar-prod
Copy link

hashicorp-vault-sonar-prod bot commented Mar 9, 2026

BUILD-10625

@matemoln matemoln force-pushed the bugfix/matemoln/BUILD-10625-pr-cleanup-artifacts branch 2 times, most recently from 2c9f189 to fd6706e Compare March 9, 2026 19:07
@matemoln matemoln force-pushed the bugfix/matemoln/BUILD-10625-pr-cleanup-artifacts branch from fd6706e to a992f86 Compare March 9, 2026 19:21
…rtifacts

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes PR artifact cleanup timeouts by avoiding full-repo artifact pagination and instead scoping artifact discovery/deletion to workflow runs for the PR’s head branch.

Changes:

  • Fetch workflow run IDs for $GITHUB_HEAD_REF, then list/delete artifacts per run (with pagination).
  • Update artifact display template to avoid printing table headers for runs with no artifacts.
  • Update the ShellSpec test to mock the new actions/runs?branch=... lookup flow.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
pr_cleanup/cleanup.sh Replaces repo-wide artifact pagination with branch-scoped workflow run lookup and per-run artifact listing/deletion.
pr_cleanup/artifact_template.tpl Suppresses rendering when the response contains no artifacts to avoid empty headers.
spec/pr_cleanup_spec.sh Adjusts mocks to match the new GitHub API call pattern (branch runs + per-run artifacts).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

matemoln and others added 2 commits March 10, 2026 14:43
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
@sonarqubecloud
Copy link

@matemoln matemoln marked this pull request as ready for review March 11, 2026 10:51
@matemoln matemoln requested a review from a team as a code owner March 11, 2026 10:51
@matemoln matemoln merged commit 4f15d50 into master Mar 11, 2026
13 checks passed
@matemoln matemoln deleted the bugfix/matemoln/BUILD-10625-pr-cleanup-artifacts branch March 11, 2026 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants