ci: cleanup draft pr tags#1097
Conversation
WalkthroughThe pull request updates the GitHub Actions workflow responsible for cleaning up prerelease tags associated with pull requests. The logic for determining when to delete a prerelease tag is improved by checking both the PR state and draft status, and fallback Git commands for tag deletion are removed. Changes
Sequence Diagram(s)sequenceDiagram
participant Workflow
participant GitHubAPI
Workflow->>GitHubAPI: Query PR state and draft status for each prerelease tag
alt PR not found
Workflow->>Workflow: Delete prerelease tag
else PR not open or is draft
Workflow->>Workflow: Delete prerelease tag
else PR open and not draft
Workflow->>Workflow: Keep prerelease tag
end
Possibly related PRs
Suggested reviewers
Poem
🪧 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: 0
🧹 Nitpick comments (3)
.github/workflows/cleanup-pr-releases.yaml (3)
36-39: Refactor PR existence check for robustness
Relying on string comparison against"NOT_FOUND"can break if the output format changes. Instead, use the exit status ofgh pr viewto detect missing PRs:- if [[ "$pr_info" == "NOT_FOUND" ]]; then - echo "PR #$pr_number not found. Deleting prerelease tag $tag" - gh release delete "$tag" --yes --cleanup-tag - continue - fi + if ! pr_info=$(gh pr view "$pr_number" --json state,isDraft 2>/dev/null); then + echo "PR #$pr_number not found. Deleting prerelease tag $tag" + gh release delete "$tag" --yes --cleanup-tag + continue + fi
42-43: Use here-string for JSON parsing
To preserve JSON formatting and avoid potential whitespace issues, prefer:pr_state=$(jq -r '.state' <<< "$pr_info") pr_draft=$(jq -r '.isDraft' <<< "$pr_info")over piping through
echo.
45-46: Fix conditional draft label in log
${pr_draft:+ (draft)}expands for any non-empty value, causing "(draft)" to appear even whenpr_draftis"false". Introduce an explicit check:- echo "PR #$pr_number is $pr_state${pr_draft:+ (draft)}. Deleting prerelease tag $tag" + draft_label="" + if [[ "$pr_draft" == "true" ]]; then + draft_label=" (draft)" + fi + echo "PR #$pr_number is $pr_state$draft_label. Deleting prerelease tag $tag"
📜 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 comments (2)
.github/workflows/cleanup-pr-releases.yaml (2)
35-35: Ensure GH CLI supportsisDraftfield
The--json state,isDraftflag requires a recent GH CLI. Verify the CI environment uses GH CLI ≥ 2.22.0 or implement fallback logic ifisDraftisn’t supported.
49-49: Approve retention logic for active PRs
The else branch correctly retains tags for open, non-draft PRs with a clear log message.
Summary by CodeRabbit