ci: add pr release cleanup job#1090
Conversation
WalkthroughA new GitHub Actions workflow has been added to automate the cleanup of prereleases associated with closed pull requests. The workflow identifies prerelease tags following a specific pattern, checks the status of related pull requests, and deletes prereleases and tags if the pull requests are no longer open. Changes
Sequence Diagram(s)sequenceDiagram
participant GitHub Actions
participant GitHub CLI
participant Repository
GitHub Actions->>GitHub CLI: List up to 1000 prereleases
loop For each prerelease tag matching vX.Y.Z-prN
GitHub Actions->>GitHub CLI: Query PR N state
alt PR is not open
GitHub Actions->>GitHub CLI: Delete prerelease
GitHub Actions->>Repository: Delete associated git tag
else PR is open
GitHub Actions-->>GitHub Actions: Skip deletion
end
end
Poem
Note ⚡️ AI Code Reviews for VS Code, Cursor, WindsurfCodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (4)
.github/workflows/cleanup-pr-releases.yaml (4)
13-16: Prevent overlapping runs with concurrency settings.Without a concurrency group, scheduled and manual runs could overlap. Consider adding:
jobs: cleanup-prereleases: + concurrency: + group: cleanup-prereleases + cancel-in-progress: true runs-on: ubuntu-latestThis ensures only one cleanup job runs at a time.
20-23: Fail fast on script errors.By default, errors in the script may be ignored. Add
set -euo pipefailto exit immediately on failures and undefined vars:run: | + set -euo pipefail echo "Fetching all prereleases..." releases=$(gh release list --limit 1000 --json tagName,isPrerelease \ --jq '.[] | select(.isPrerelease) | .tagName')
24-28: Handle tags with spaces safely.Iterating over
$releasescan break on whitespace. Use awhile readloop:- for tag in $releases; do + while IFS= read -r tag; do if [[ "$tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+-pr([0-9]+)$ ]]; then pr_number="${BASH_REMATCH[1]}" echo "Checking PR #$pr_number for tag $tag" … - done + done <<< "$releases"This approach preserves each tag string intact.
41-41: Add trailing newline for YAML lint.The file is missing a newline at EOF, which YAMLlint flags. Please add a blank line at the end.
🧰 Tools
🪛 YAMLlint (1.37.1)
[error] 41-41: no new line character at the end of file
(new-line-at-end-of-file)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
.github/workflows/cleanup-pr-releases.yaml(1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.37.1)
.github/workflows/cleanup-pr-releases.yaml
[error] 41-41: no new line character at the end of file
(new-line-at-end-of-file)
🔇 Additional comments (3)
.github/workflows/cleanup-pr-releases.yaml (3)
3-8: Event triggers are correctly configured.The workflow listens to manual dispatch, a daily cron schedule, and PR closed events via
pull_request_target. This covers both scheduled cleanups and immediate cleanup when PRs close.
10-12: Minimal scoped permissions are correctly set.Granting
contents: writeis sufficient for deleting releases and tags without over-privileging the workflow.
25-27: PR tag regex is precise for semver-prN patterns.The regex
^v[0-9]+\.[0-9]+\.[0-9]+-pr([0-9]+)$cleanly captures the PR number and avoids false positives.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (5)
.github/workflows/cleanup-pr-releases.yaml (5)
18-22: Consider upgrading the checkout action and fetching tags
actions/checkout@v3works, but v4 is available with fixes and performance improvements.- To make
git tag -deffective, setfetch-depth: 0andfetch-tags: trueunderwith:so that tags are actually present locally.🧰 Tools
🪛 actionlint (1.7.7)
19-19: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
23-26: Simplify token injection for GH CLI
The GitHub CLI will auto-pick upGITHUB_TOKEN, so you can rely on that instead of explicitly mappingGH_TOKEN. This reduces duplication and aligns with common examples.
27-29: Use native prerelease filter
Instead of piping JSON through jq, leverage the built-in flag:gh release list --prerelease --limit 1000 --json tagNameThis simplifies the command and avoids extra filtering.
35-36: Handle merged vs closed PRs explicitly if needed
GitHub’sstatefield returnsOPENorCLOSED(merged PRs are marked closed). If you ever need to distinguish merges, consider querying.mergedin addition to.state.
48-48: Add trailing newline
YAML linters expect a newline at EOF. Please add a blank line after line 48 to satisfynew-line-at-end-of-file.🧰 Tools
🪛 YAMLlint (1.37.1)
[error] 48-48: no new line character at the end of file
(new-line-at-end-of-file)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
.github/workflows/cleanup-pr-releases.yaml(1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.7)
.github/workflows/cleanup-pr-releases.yaml
19-19: the runner of "actions/checkout@v3" action is too old to run on GitHub Actions. update the action's version to fix this issue
(action)
🪛 YAMLlint (1.37.1)
.github/workflows/cleanup-pr-releases.yaml
[error] 48-48: no new line character at the end of file
(new-line-at-end-of-file)
🔇 Additional comments (5)
.github/workflows/cleanup-pr-releases.yaml (5)
3-9: Appropriate event triggers with safe checkout
Usingpull_request_targetalongsideworkflow_dispatchand a daily cron ensures closed‐PR cleanup runs on trusted code (you explicitly checkout the default branch). This setup aligns well with security best practices.
10-13: Verify token scope covers release deletion
You’ve scopedcontents: writeandpull-requests: read. Please confirm thatcontents: writeis sufficient forgh release deleteand git-tag removal. If deletion fails due to insufficient permissions, consider granting a dedicatedreleases: writeor fullrepopermission.
30-34: Correct regex for PR-linked tags
Your pattern^v[0-9]+\.[0-9]+\.[0-9]+-pr([0-9]+)$cleanly matches semver prerelease tags (v1.2.3-pr45). Ensure all generated prereleases conform to this naming convention.
38-41: Robust release and tag deletion with fallback
Good use of--cleanup-tagwith a fallbackgit push --delete origin. This covers GH CLI versions <2.3.0. You may drop the localgit tag -dstep if you don’t fetch tags, or adjust checkout to include tags (see earlier comment).
45-47: Clear logging for skipped tags
Skipping non-PR tags with an explanatory log makes the workflow’s decisions transparent. Nice touch.
Summary by CodeRabbit