Skip to content

🐛 Add 7-day screenshot retention policy with automated cleanup#4352

Merged
clubanderson merged 2 commits intomainfrom
fix/screenshot-cleanup-retention
Apr 2, 2026
Merged

🐛 Add 7-day screenshot retention policy with automated cleanup#4352
clubanderson merged 2 commits intomainfrom
fix/screenshot-cleanup-retention

Conversation

@clubanderson
Copy link
Copy Markdown
Collaborator

Summary

  • Adds a scheduled GitHub Actions workflow (cleanup-screenshots.yml) that runs daily and deletes screenshot files older than 7 days from .github/screenshots/
  • Before deleting, rewrites any branch-based raw URLs in issue comments to commit-SHA-based URLs so images remain visible in issues after cleanup
  • Updates process-screenshots.yml to emit permanent commit-SHA URLs from the start, so new screenshots survive cleanup without needing URL rewriting

How it works

Problem: Screenshots committed to .github/screenshots/ accumulate indefinitely, growing repository size.

Solution (two-part):

  1. process-screenshots.yml change: New screenshots now use https://raw.githubusercontent.com/{owner}/{repo}/{commitSha}/{path} instead of download_url (which uses branch refs like /main/). SHA-based URLs reference the exact commit that added the file, so they remain valid even after the file is deleted from the default branch.

  2. cleanup-screenshots.yml (new): Runs daily at 2 AM UTC. For each screenshot older than 7 days:

    • Extracts the issue number from the commit message
    • Rewrites any branch-based URLs in that issue's comments to SHA-based URLs (transition period for pre-existing screenshots)
    • Deletes the file via git rm
    • Commits and pushes all deletions in a single commit

Test plan

  • Verify process-screenshots.yml correctly uses data.commit.sha from the Contents API response
  • Verify cleanup workflow can be triggered manually via workflow_dispatch
  • Confirm SHA-based raw URLs (raw.githubusercontent.com/{owner}/{repo}/{sha}/...) resolve correctly even after the file is deleted from main
  • Verify empty screenshot directories are cleaned up after file deletion

Closes #4349

- Create cleanup-screenshots.yml: scheduled daily workflow that deletes
  screenshot files older than 7 days from .github/screenshots/
- Before deletion, rewrites any branch-based raw URLs in issue comments
  to commit-SHA-based URLs so images remain visible in issues
- Update process-screenshots.yml to emit permanent commit-SHA URLs from
  the start, eliminating the need for URL rewriting on new screenshots

Closes #4349

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
Copilot AI review requested due to automatic review settings April 2, 2026 22:57
@kubestellar-prow kubestellar-prow bot added the dco-signoff: yes Indicates the PR's author has signed the DCO. label Apr 2, 2026
@kubestellar-prow
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign clubanderson for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@netlify
Copy link
Copy Markdown

netlify bot commented Apr 2, 2026

Deploy Preview for kubestellarconsole canceled.

Name Link
🔨 Latest commit f5940cf
🔍 Latest deploy log https://app.netlify.com/projects/kubestellarconsole/deploys/69cef4db3de4370007dd8f69

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

👋 Hey @clubanderson — thanks for opening this PR!

🤖 This project is developed exclusively using AI coding assistants.

Please do not attempt to code anything for this project manually.
All contributions should be authored using an AI coding tool such as:

This ensures consistency in code style, architecture patterns, test coverage,
and commit quality across the entire codebase.


This is an automated message.

@kubestellar-prow kubestellar-prow bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 2, 2026
- Use --diff-filter=A in git log to find the original add-commit (not
  the most recent commit that touched the file) for correct age and SHA
- Switch from execSync to execFileSync to prevent shell injection from
  untrusted request ID path components
- Use replaceAll instead of replace for URL rewriting in comments
- Paginate listComments via github.paginate() to handle issues with
  more than 100 comments
- Add git pull --rebase before push to handle concurrent main commits

Signed-off-by: Andrew Anderson <andy@clubanderson.com>
Copy link
Copy Markdown
Contributor

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

Implements a 7-day retention policy for issue screenshot artifacts stored in-repo, while keeping issue-embedded images working by switching to commit-SHA-based raw URLs and adding an automated cleanup workflow.

Changes:

  • Update screenshot processing workflow to emit commit-SHA-based raw.githubusercontent.com/.../{sha}/... URLs in issue comments.
  • Add a scheduled cleanup workflow that deletes screenshots older than 7 days and rewrites legacy branch-based URLs in issue comments before deletion.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
.github/workflows/process-screenshots.yml Switches generated screenshot links in comments from branch-based URLs to commit-SHA-based permanent raw URLs.
.github/workflows/cleanup-screenshots.yml Adds a daily scheduled job to rewrite legacy URLs and remove expired screenshots from .github/screenshots/.

Comment on lines +105 to +107
const issueNumber = parseInt(issueMatch[1]);
const branchUrl = `${RAW_PREFIX}/main/${file}`;
const permanentUrl = `${RAW_PREFIX}/${commitSha}/${file}`;
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

branchUrl is hardcoded to /main/, which will fail if the repo default branch is not main (or if it changes). Use context.payload.repository.default_branch (available on schedule/dispatch) to build the branch-based URL you’re trying to rewrite.

Copilot uses AI. Check for mistakes.
Comment on lines +110 to +115
const { data: comments } = await github.rest.issues.listComments({
owner,
repo,
issue_number: issueNumber,
per_page: 100,
});
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

issues.listComments only fetches the first 100 comments. For long-running issues with many comments, URLs beyond the first page won’t be rewritten and links may break after deletion. Consider using Octokit pagination (github.paginate(...)) or iterating page until empty.

Suggested change
const { data: comments } = await github.rest.issues.listComments({
owner,
repo,
issue_number: issueNumber,
per_page: 100,
});
const comments = await github.paginate(
github.rest.issues.listComments,
{
owner,
repo,
issue_number: issueNumber,
per_page: 100,
}
);

Copilot uses AI. Check for mistakes.
owner,
repo,
comment_id: comment.id,
body: comment.body.replace(branchUrl, permanentUrl),
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

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

comment.body.replace(branchUrl, permanentUrl) only replaces the first occurrence. If a comment contains multiple screenshots (or repeated URLs), some links will remain branch-based. Use replaceAll (Node 16+) or a global regex to ensure every occurrence is rewritten.

Suggested change
body: comment.body.replace(branchUrl, permanentUrl),
body: comment.body.replaceAll(branchUrl, permanentUrl),

Copilot uses AI. Check for mistakes.
@clubanderson
Copy link
Copy Markdown
Collaborator Author

🔄 Auto-Applying Copilot Code Review

Copilot code review found 2 code suggestion(s) and 1 general comment(s).

@copilot Please apply all of the following code review suggestions:

  • .github/workflows/cleanup-screenshots.yml (line 115): const comments = await github.paginate( github.rest.issues.lis...
  • .github/workflows/cleanup-screenshots.yml (line 123): body: comment.body.replaceAll(branchUrl, permanentUrl),

Also address these general comments:

  • .github/workflows/cleanup-screenshots.yml (line 117): branchUrl is hardcoded to /main/, which will fail if the repo default branch is not main (or if it changes). Use `

Push all fixes in a single commit. Run cd web && npm run build && npm run lint before committing.


Auto-generated by copilot-review-apply workflow.

@clubanderson clubanderson merged commit d4b0ae3 into main Apr 2, 2026
7 of 8 checks passed
@kubestellar-prow kubestellar-prow bot deleted the fix/screenshot-cleanup-retention branch April 2, 2026 22:59
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

Thank you for your contribution! Your PR has been merged.

Check out what's new:

Stay connected: Slack #kubestellar-dev | Multi-Cluster Survey

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

Post-merge build verification passed

Both Go and frontend builds compiled successfully against merge commit d4b0ae3b34818d33f35a7d0a824af58ac07f254b.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the DCO. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Screenshots Persist in Repository Without Cleanup — Missing 7-Day Retention Policy

3 participants