ci: fix docker-ci.yml image cleanup after PR closure - #326
Conversation
Previously failed to delete the images, see https://github.com/Ryan-Millard/Img2Num/actions/runs/24804191793/job/72594225429.
WalkthroughReplaces the previous Changes
Sequence Diagram(s)sequenceDiagram
participant Action as GitHub Action (runner)
participant GHAPI as GH REST API (api.github.com)
participant GHCR as GHCR package endpoint (api.github.com/orgs/.../packages/container/img2num-dev/versions)
Action->>GHAPI: Set GH_TOKEN (secrets.GHCR_DELETE_TOKEN)
Action->>Action: Determine PR number (event or needs.guard.outputs.pr_number)
loop for each tag in [pr-${PR}, cache-pr-${PR}]
Action->>GHCR: GET versions (per_page=100)
GHCR-->>Action: JSON list of versions (with metadata.container.tags)
alt matching versions found
Action->>GHAPI: DELETE /orgs/.../packages/container/.../versions/{id}
GHAPI-->>Action: 204 No Content
else no matches
Action-->>Action: Log "No version found for tag"
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
.github/workflows/docker-ci.yml (1)
9-10:⚠️ Potential issue | 🟠 MajorUse
pull_request_targetfor close cleanup that needsGHCR_DELETE_TOKEN.Fork PRs triggered with
pull_requestdo not receive repository secrets other thanGITHUB_TOKEN, so cleanup fails after closing a fork PR becausesecrets.GHCR_DELETE_TOKEN(line 259) is unavailable. Since this job only performs API cleanup and does not checkout or execute PR code, switch topull_request_targetand update the job condition accordingly.Proposed fix
on: @@ - pull_request: + pull_request_target: types: [closed] @@ cleanup-on-close: - if: github.event_name == 'pull_request' + if: github.event_name == 'pull_request_target'🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.github/workflows/docker-ci.yml around lines 9 - 10, Change the workflow trigger from pull_request to pull_request_target and update the job condition that checks for GHCR_DELETE_TOKEN so cleanup jobs run on the target repo (not fork) after a PR is closed; specifically, replace the trigger block containing "pull_request: types: [closed]" with "pull_request_target: types: [closed]" and ensure the job that references secrets.GHCR_DELETE_TOKEN (the cleanup job using the GHCR_DELETE_TOKEN secret) is conditioned to run only when that secret is present and the event is a closed PR on the target repo (no checkout or execution of PR code).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In @.github/workflows/docker-ci.yml:
- Around line 9-10: Change the workflow trigger from pull_request to
pull_request_target and update the job condition that checks for
GHCR_DELETE_TOKEN so cleanup jobs run on the target repo (not fork) after a PR
is closed; specifically, replace the trigger block containing "pull_request:
types: [closed]" with "pull_request_target: types: [closed]" and ensure the job
that references secrets.GHCR_DELETE_TOKEN (the cleanup job using the
GHCR_DELETE_TOKEN secret) is conditioned to run only when that secret is present
and the event is a closed PR on the target repo (no checkout or execution of PR
code).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d7c5683f-4a2a-43ab-9f59-815a62b9d456
📒 Files selected for processing (1)
.github/workflows/docker-ci.yml
|
@coderabbitai propose a conventional commit and description for this. |
|
Tip For best results, initiate chat on the files or code changes.
Commit subject Commit body Commit footer So the full commit would look like: |
What was changed & why
Cleanup job in
docker-ci.ymlwas updated - lets hope it works.Previously failed to delete the images,
see https://github.com/Ryan-Millard/Img2Num/actions/runs/24804191793/job/72594225429.
Fixes: #none - see here.
Changes
Simple job update
Testing & Verification
Additional Resources
Summary by CodeRabbit