-
Notifications
You must be signed in to change notification settings - Fork 383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
delete-on-pr-close #617
delete-on-pr-close #617
Conversation
Caution Review failedThe pull request is closed. WalkthroughThis pull request enhances GitHub Actions workflows for managing pull requests, deployments, and review apps. The changes span four workflow files, introducing updates such as refined comment generation, improved handling of review app deletions, streamlined deployment processes, and enhanced help command functionality. Key modifications include new triggers for workflows, adjustments to environment variable handling, and the implementation of concurrency controls to prevent duplicate runs. Changes
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (4)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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 (
|
Hi 👋 To deploy a review app, please comment |
/deploy-review-app |
/deploy-review-app |
/help |
📚 Available Commands
|
Available Commands
|
/help |
📚 Available Commands
|
Available Commands
|
/deploy-review-app |
/help |
📚 Available Commands
|
Available Commands
|
/help |
Available Commands
|
📚 Available Commands
|
🚀 Starting deployment... |
❌ Review app deployment failed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
🧹 Nitpick comments (4)
.github/workflows/add-comment-on-pr-creation.yml (1)
13-30
: Add error handling for comment creation.While the implementation is good, it's missing error handling for the comment creation process.
- name: Add comment uses: actions/github-script@v7 with: script: | + try { await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.payload.pull_request.number, body: [ "Hi 👋 Here are the commands available for this PR:", "", "- `/deploy`: Deploy your changes to a review environment", "- `/delete-review-app`: Clean up the review environment when you're done", "- `/help`: Show detailed information about all commands", "", "Use `/help` to see full documentation, including configuration options." ].join("\n") }); + } catch (error) { + core.setFailed(`Failed to create initial comment: ${error.message}`); + }.github/workflows/delete-review-app.yml (2)
24-28
: Fix trailing spaces in conditions.Remove trailing spaces in the conditional expression to maintain consistent formatting.
- (github.event_name == 'issue_comment' && - github.event.issue.pull_request && - github.event.comment.body == '/delete-review-app') || - (github.event_name == 'pull_request' && - github.event.action == 'closed') + (github.event_name == 'issue_comment' && + github.event.issue.pull_request && + github.event.comment.body == '/delete-review-app') || + (github.event_name == 'pull_request' && + github.event.action == 'closed')🧰 Tools
🪛 yamllint (1.35.1)
[error] 24-24: trailing spaces
(trailing-spaces)
[error] 25-25: trailing spaces
(trailing-spaces)
[error] 27-27: trailing spaces
(trailing-spaces)
88-101
: Consider adding retry logic for comment updates.The comment update operation might fail due to GitHub API rate limits or temporary issues. Consider adding retry logic for better reliability.
- let message; - if (success) { - message = '✅ Review app for PR #' + prNumber + ' was successfully deleted'; - if ('${{ github.event_name }}' === 'pull_request') { - const merged = '${{ github.event.pull_request.merged }}' === 'true'; - message += merged ? ' after merge' : ' after PR was closed'; - } - } else { - message = [ - '❌ Review app for PR #' + prNumber + ' failed to be deleted', - '', - '🎮 [Control Plane Console for Review App with PR #' + prNumber + '](' + cpConsoleUrl + ')' - ].join('\n'); - } - - await github.rest.issues.updateComment({ + const updateComment = async (retries = 3) => { + let message; + if (success) { + message = '✅ Review app for PR #' + prNumber + ' was successfully deleted'; + if ('${{ github.event_name }}' === 'pull_request') { + const merged = '${{ github.event.pull_request.merged }}' === 'true'; + message += merged ? ' after merge' : ' after PR was closed'; + } + } else { + message = [ + '❌ Review app for PR #' + prNumber + ' failed to be deleted', + '', + '🎮 [Control Plane Console for Review App with PR #' + prNumber + '](' + cpConsoleUrl + ')' + ].join('\n'); + } + + try { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: ${{ fromJSON(steps.init-delete.outputs.result).commentId }}, + body: message + }); + } catch (error) { + if (retries > 0) { + console.log(`Retrying comment update. Attempts remaining: ${retries-1}`); + await new Promise(resolve => setTimeout(resolve, 1000)); + return updateComment(retries - 1); + } + throw error; + } + }; + + try { + await updateComment(); + } catch (error) { + core.setFailed(`Failed to update comment after retries: ${error.message}`); + }.github/workflows/deploy-to-control-plane.yml (1)
107-136
: Add retry mechanism for status updates.The status update could fail due to GitHub API rate limits. Consider adding a retry mechanism.
- name: Update Status - Complete if: always() uses: actions/github-script@v7 with: script: | eval(process.env.GET_CONSOLE_LINK); const isSuccess = '${{ job.status }}' === 'success'; const railsUrl = '${{ steps.deploy.outputs.rails_url }}'; const successMessage = [ '✅ Review app deployed successfully!', '', '🌐 [Rails App](' + railsUrl + ')', '', getConsoleLink(process.env.PR_NUMBER) ].join('\n'); const failureMessage = [ '❌ Review app deployment failed', '', getConsoleLink(process.env.PR_NUMBER) ].join('\n'); - await github.rest.issues.updateComment({ - owner: context.repo.owner, - repo: context.repo.repo, - comment_id: ${{ fromJSON(steps.init-status.outputs.result).commentId }}, - body: isSuccess ? successMessage : failureMessage - }); + const updateStatus = async (retries = 3) => { + try { + await github.rest.issues.updateComment({ + owner: context.repo.owner, + repo: context.repo.repo, + comment_id: ${{ fromJSON(steps.init-status.outputs.result).commentId }}, + body: isSuccess ? successMessage : failureMessage + }); + } catch (error) { + if (retries > 0) { + console.log(`Retrying status update. Attempts remaining: ${retries-1}`); + await new Promise(resolve => setTimeout(resolve, 1000)); + return updateStatus(retries - 1); + } + throw error; + } + }; + + try { + await updateStatus(); + } catch (error) { + core.setFailed(`Failed to update status after retries: ${error.message}`); + }🧰 Tools
🪛 actionlint (1.7.4)
111-111: property "rails_url" is not defined in object type {review_app_url: string}
(expression)
🪛 yamllint (1.35.1)
[error] 113-113: trailing spaces
(trailing-spaces)
[error] 116-116: trailing spaces
(trailing-spaces)
[error] 124-124: trailing spaces
(trailing-spaces)
[error] 130-130: trailing spaces
(trailing-spaces)
[error] 136-136: 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 (4)
.github/workflows/add-comment-on-pr-creation.yml
(1 hunks).github/workflows/delete-review-app.yml
(5 hunks).github/workflows/deploy-to-control-plane.yml
(2 hunks).github/workflows/help-command.yml
(3 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
.github/workflows/help-command.yml
[error] 93-93: trailing spaces
(trailing-spaces)
[error] 97-97: trailing spaces
(trailing-spaces)
[error] 104-104: trailing spaces
(trailing-spaces)
.github/workflows/delete-review-app.yml
[error] 24-24: trailing spaces
(trailing-spaces)
[error] 25-25: trailing spaces
(trailing-spaces)
[error] 27-27: trailing spaces
(trailing-spaces)
[error] 61-61: trailing spaces
(trailing-spaces)
.github/workflows/deploy-to-control-plane.yml
[error] 84-84: trailing spaces
(trailing-spaces)
[error] 113-113: trailing spaces
(trailing-spaces)
[error] 116-116: trailing spaces
(trailing-spaces)
[error] 124-124: trailing spaces
(trailing-spaces)
[error] 130-130: trailing spaces
(trailing-spaces)
🪛 actionlint (1.7.4)
.github/workflows/deploy-to-control-plane.yml
111-111: property "rails_url" is not defined in object type {review_app_url: string}
(expression)
🔇 Additional comments (1)
.github/workflows/help-command.yml (1)
7-11
: Great addition of concurrency control!The concurrency configuration effectively prevents duplicate help command executions and cancels in-progress runs. This is a good practice for GitHub Actions workflows.
PR_URL=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | ||
-H "Accept: application/vnd.github.v3+json" \ | ||
"${{ github.event.issue.pull_request.url }}") | ||
HEAD_REF=$(echo "$PR_URL" | jq -r .head.ref) | ||
echo "ref=$HEAD_REF" >> "$GITHUB_OUTPUT" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add timeout and validation for PR API call.
The curl command should include a timeout to prevent hanging, and the response should be validated.
- PR_URL=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
- -H "Accept: application/vnd.github.v3+json" \
- "${{ github.event.issue.pull_request.url }}")
- HEAD_REF=$(echo "$PR_URL" | jq -r .head.ref)
- echo "ref=$HEAD_REF" >> "$GITHUB_OUTPUT"
+ PR_URL=$(curl --max-time 10 -s -f -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
+ -H "Accept: application/vnd.github.v3+json" \
+ "${{ github.event.issue.pull_request.url }}")
+ if [ $? -ne 0 ]; then
+ echo "Failed to fetch PR details"
+ exit 1
+ fi
+ HEAD_REF=$(echo "$PR_URL" | jq -r .head.ref)
+ if [ -z "$HEAD_REF" ]; then
+ echo "Failed to extract HEAD ref from PR"
+ exit 1
+ fi
+ echo "ref=$HEAD_REF" >> "$GITHUB_OUTPUT"
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
PR_URL=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
"${{ github.event.issue.pull_request.url }}") | |
HEAD_REF=$(echo "$PR_URL" | jq -r .head.ref) | |
echo "ref=$HEAD_REF" >> "$GITHUB_OUTPUT" | |
PR_URL=$(curl --max-time 10 -s -f -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
"${{ github.event.issue.pull_request.url }}") | |
if [ $? -ne 0 ]; then | |
echo "Failed to fetch PR details" | |
exit 1 | |
fi | |
HEAD_REF=$(echo "$PR_URL" | jq -r .head.ref) | |
if [ -z "$HEAD_REF" ]; then | |
echo "Failed to extract HEAD ref from PR" | |
exit 1 | |
fi | |
echo "ref=$HEAD_REF" >> "$GITHUB_OUTPUT" |
- name: Deploy Review App | ||
id: deploy | ||
uses: ./.github/actions/deploy-to-control-plane | ||
with: | ||
app_name: ${{ env.APP_NAME }} | ||
org: ${{ env.CPLN_ORG }} | ||
wait_timeout: 900 | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
wait_timeout: ${{ vars.WAIT_TIMEOUT || 900 }} | ||
env: | ||
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN }} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
The rails_url
output property is indeed missing from the action
The action only defines review_app_url
as an output property. If rails_url
is needed, it should be added to the outputs section in .github/actions/deploy-to-control-plane/action.yml
.
🔗 Analysis chain
Verify rails_url output property.
The static analysis tool indicates that the rails_url
property is not defined in the action's outputs.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Check if the deploy-to-control-plane action defines rails_url output
grep -r "outputs:" .github/actions/deploy-to-control-plane/action.yml
Length of output: 78
Script:
#!/bin/bash
# Check the complete outputs section of the action
grep -A 10 "^outputs:" .github/actions/deploy-to-control-plane/action.yml
Length of output: 323
Deploying to Control Plane... Waiting for deployment to be ready... |
/help |
/help |
/deploy-review-app |
This change is
Summary by CodeRabbit