-
Notifications
You must be signed in to change notification settings - Fork 384
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
Github actions fixes #618
Github actions fixes #618
Conversation
Caution Review failedThe pull request is closed. WalkthroughThe pull request introduces changes to GitHub Actions workflows and scripts related to deploying and managing review applications. Key modifications include adding a step to validate required secrets, restructuring the deployment workflow to respond only to issue comments and push events, and enhancing error handling in the deployment scripts. New steps have been added to provide status updates during deployment, and existing steps have been modified for clarity and functionality. Changes
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (5)
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 (
|
Deploying to Control Plane... Waiting for deployment to be ready... |
/deploy-review-app |
Deployment complete for PR #618, commit 34603d8 |
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: 1
🧹 Nitpick comments (3)
.github/actions/deploy-to-control-plane/scripts/deploy.sh (1)
40-44
: Consider adding URL format validation.The RAILS_URL extraction could benefit from a more strict validation to ensure the URL matches the expected format.
# Extract app URL from deployment output RAILS_URL=$(grep -oP 'https://rails-[^[:space:]]*\.cpln\.app(?=\s|$)' "$TEMP_OUTPUT" | head -n1) +if ! [[ "$RAILS_URL" =~ ^https://rails-[a-zA-Z0-9-]+\.cpln\.app$ ]]; then + echo "❌ Invalid app URL format: $RAILS_URL" + exit 1 +fi if [ -z "$RAILS_URL" ]; then.github/workflows/delete-review-app.yml (1)
Line range hint
96-114
: Remove trailing whitespace.There's a trailing space on line 97.
-eval(process.env.GET_CONSOLE_LINK); +eval(process.env.GET_CONSOLE_LINK);.github/workflows/deploy-to-control-plane.yml (1)
23-25
: Remove trailing spaces in conditions.There are trailing spaces in the conditional statements.
- github.event_name == 'issue_comment' && - github.event.issue.pull_request && + github.event_name == 'issue_comment' && + github.event.issue.pull_request && github.event.comment.body == '/deploy-review-app'🧰 Tools
🪛 yamllint (1.35.1)
[error] 23-23: trailing spaces
(trailing-spaces)
[error] 24-24: trailing spaces
(trailing-spaces)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (6)
.github/actions/deploy-to-control-plane/action.yml
(1 hunks).github/actions/deploy-to-control-plane/scripts/deploy.sh
(2 hunks).github/workflows/add-comment-on-pr-creation.yml
(1 hunks).github/workflows/delete-review-app.yml
(4 hunks).github/workflows/deploy-to-control-plane.yml
(1 hunks).github/workflows/help-command.yml
(2 hunks)
✅ Files skipped from review due to trivial changes (1)
- .github/workflows/add-comment-on-pr-creation.yml
🧰 Additional context used
🪛 yamllint (1.35.1)
.github/workflows/delete-review-app.yml
[error] 97-97: trailing spaces
(trailing-spaces)
.github/workflows/deploy-to-control-plane.yml
[error] 23-23: trailing spaces
(trailing-spaces)
[error] 24-24: trailing spaces
(trailing-spaces)
🔇 Additional comments (4)
.github/actions/deploy-to-control-plane/scripts/deploy.sh (2)
34-38
: LGTM! Good error handling improvements.The deployment command now has proper error handling with timeout and clear error messaging.
47-59
: LGTM! Robust workload readiness check.The implementation includes:
- Clear timeout handling
- Differentiation between timeout and other failures
- Comprehensive error output
.github/workflows/help-command.yml (1)
Line range hint
34-55
: LGTM! Clear and consistent command documentation.The help message is well-structured and accurately reflects the updated command names.
.github/workflows/delete-review-app.yml (1)
Line range hint
63-89
: LGTM! Well-structured workflow URL handling.The implementation provides clear workflow URLs and proper error handling.
- name: Setup Control Plane App If It Doesn't Exist | ||
shell: bash | ||
run: | | ||
if ! cpflow exists -a ${{ inputs.app_name }} ; then | ||
echo " Setting up new Control Plane app for app ${{ inputs.app_name }}..." | ||
cpflow setup-app -a ${{ inputs.app_name }} | ||
fi |
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.
🛠️ Refactor suggestion
Add error handling for the setup-app command.
The setup command should include error handling to ensure the app is created successfully.
if ! cpflow exists -a ${{ inputs.app_name }} ; then
echo " Setting up new Control Plane app for app ${{ inputs.app_name }}..."
- cpflow setup-app -a ${{ inputs.app_name }}
+ if ! cpflow setup-app -a ${{ inputs.app_name }}; then
+ echo "❌ Failed to set up Control Plane app"
+ exit 1
+ fi
fi
📝 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.
- name: Setup Control Plane App If It Doesn't Exist | |
shell: bash | |
run: | | |
if ! cpflow exists -a ${{ inputs.app_name }} ; then | |
echo " Setting up new Control Plane app for app ${{ inputs.app_name }}..." | |
cpflow setup-app -a ${{ inputs.app_name }} | |
fi | |
- name: Setup Control Plane App If It Doesn't Exist | |
shell: bash | |
run: | | |
if ! cpflow exists -a ${{ inputs.app_name }} ; then | |
echo " Setting up new Control Plane app for app ${{ inputs.app_name }}..." | |
if ! cpflow setup-app -a ${{ inputs.app_name }}; then | |
echo "❌ Failed to set up Control Plane app" | |
exit 1 | |
fi | |
fi |
/destroy-review-app |
✅ Deployment complete for PR #618, commit c8500cd |
❌ Deployment failed for PR #618, commit d256c0c |
✅ Deployment complete for PR #618, commit ef88016 |
🚀 Deploying to Control Plane... ⏳ Waiting for deployment to be ready... |
/help |
Available Commands
|
❌ Deployment failed for PR #618, commit 1917948 |
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: 3
🧹 Nitpick comments (6)
.github/actions/deploy-to-control-plane/scripts/deploy.sh (2)
43-48
: Consider enhancing deployment error messages.While the error handling is good, consider making the error messages more specific to help diagnose deployment failures more quickly.
if ! timeout "${WAIT_TIMEOUT}" cpflow deploy-image -a "$APP_NAME" --run-release-phase --org "$CPLN_ORG" --verbose 2>&1 | tee "$TEMP_OUTPUT"; then - echo "❌ Deployment failed" + if [ $? -eq 124 ]; then + echo "❌ Deployment timed out after ${WAIT_TIMEOUT} seconds" + else + echo "❌ Deployment failed with exit code $?" + fi echo "Full output:" cat "$TEMP_OUTPUT" exit 1 fi
50-57
: Consider adding URL format validation.While the URL extraction works, consider adding validation to ensure the extracted URL matches the expected format.
RAILS_URL=$(grep -oP 'https://rails-[^[:space:]]*\.cpln\.app(?=\s|$)' "$TEMP_OUTPUT" | head -n1) if [ -z "$RAILS_URL" ]; then echo "❌ Failed to get app URL from deployment output" echo "Full output:" cat "$TEMP_OUTPUT" exit 1 +elif ! [[ "$RAILS_URL" =~ ^https://rails-[a-zA-Z0-9-]+\.cpln\.app$ ]]; then + echo "❌ Extracted URL does not match expected format: $RAILS_URL" + exit 1 fi.github/workflows/delete-review-app.yml (1)
Line range hint
63-89
: Consider extracting workflow URL logic to a reusable action.The workflow URL generation logic is duplicated across multiple workflow files. Consider extracting it to a reusable composite action.
Example structure:
# .github/actions/get-workflow-url/action.yml name: 'Get Workflow URL' description: 'Gets the URL for the current workflow run' outputs: url: description: 'The workflow URL' runs: using: "composite" steps: - uses: actions/github-script@v7 with: script: | async function getWorkflowUrl(runId) { // Current implementation... } const url = await getWorkflowUrl(context.runId); core.setOutput('url', url);.github/actions/deploy-to-control-plane/action.yml (2)
47-108
: Add error handling for GitHub API calls.While the workflow URL retrieval has good error handling, the deployment creation and comment creation could benefit from try-catch blocks to handle potential API failures gracefully.
const comment = await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: process.env.PR_NUMBER, body: ' Initializing deployment...' -}); +}).catch(error => { + core.error(`Failed to create comment: ${error.message}`); + throw error; +}); const deployment = await github.rest.repos.createDeployment({ owner: context.repo.owner, repo: context.repo.repo, ref: context.sha, environment: 'review', auto_merge: false, required_contexts: [] -}); +}).catch(error => { + core.error(`Failed to create deployment: ${error.message}`); + throw error; +});🧰 Tools
🪛 yamllint (1.35.1)
[error] 54-54: trailing spaces
(trailing-spaces)
[error] 73-73: trailing spaces
(trailing-spaces)
[error] 76-76: trailing spaces
(trailing-spaces)
[error] 81-81: trailing spaces
(trailing-spaces)
[error] 84-84: trailing spaces
(trailing-spaces)
[error] 92-92: trailing spaces
(trailing-spaces)
[error] 104-104: trailing spaces
(trailing-spaces)
154-196
: Well-structured status updates with consistent formatting!The status updates provide excellent visibility into the deployment process. Consider adding error handling for the status update API calls to ensure users are informed even if updates fail.
🧰 Tools
🪛 yamllint (1.35.1)
[error] 167-167: trailing spaces
(trailing-spaces)
[error] 190-190: trailing spaces
(trailing-spaces)
.github/workflows/deploy-to-control-plane.yml (1)
9-11
: Consider using pattern matching for branch exclusions.The branch exclusion could be more maintainable using a pattern.
branches-ignore: - - main # Don't run on main branch pushes - - master # Don't run on master branch pushes + - '{main,master}' # Don't run on production branches
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
.github/actions/deploy-to-control-plane/action.yml
(1 hunks).github/actions/deploy-to-control-plane/scripts/deploy.sh
(2 hunks).github/workflows/delete-review-app.yml
(5 hunks).github/workflows/deploy-to-control-plane.yml
(5 hunks)
🧰 Additional context used
🪛 yamllint (1.35.1)
.github/workflows/deploy-to-control-plane.yml
[error] 27-27: trailing spaces
(trailing-spaces)
[error] 28-28: trailing spaces
(trailing-spaces)
[error] 84-84: trailing spaces
(trailing-spaces)
[error] 85-85: trailing spaces
(trailing-spaces)
[error] 86-86: trailing spaces
(trailing-spaces)
[error] 97-97: trailing spaces
(trailing-spaces)
[error] 98-98: trailing spaces
(trailing-spaces)
[error] 99-99: trailing spaces
(trailing-spaces)
[error] 116-116: trailing spaces
(trailing-spaces)
[error] 117-117: trailing spaces
(trailing-spaces)
[error] 118-118: trailing spaces
(trailing-spaces)
[error] 124-124: trailing spaces
(trailing-spaces)
[error] 125-125: trailing spaces
(trailing-spaces)
[error] 126-126: trailing spaces
(trailing-spaces)
[error] 153-153: trailing spaces
(trailing-spaces)
[error] 160-160: trailing spaces
(trailing-spaces)
[error] 161-161: trailing spaces
(trailing-spaces)
[error] 162-162: trailing spaces
(trailing-spaces)
[error] 186-186: trailing spaces
(trailing-spaces)
[error] 187-187: trailing spaces
(trailing-spaces)
[error] 188-188: trailing spaces
(trailing-spaces)
[error] 194-194: trailing spaces
(trailing-spaces)
[error] 195-195: trailing spaces
(trailing-spaces)
[error] 196-196: trailing spaces
(trailing-spaces)
[error] 207-207: trailing spaces
(trailing-spaces)
[error] 208-208: trailing spaces
(trailing-spaces)
[error] 209-209: trailing spaces
(trailing-spaces)
[error] 235-235: trailing spaces
(trailing-spaces)
[error] 236-236: trailing spaces
(trailing-spaces)
[error] 237-237: trailing spaces
(trailing-spaces)
[error] 265-265: trailing spaces
(trailing-spaces)
.github/actions/deploy-to-control-plane/action.yml
[error] 38-38: trailing spaces
(trailing-spaces)
[error] 54-54: trailing spaces
(trailing-spaces)
[error] 73-73: trailing spaces
(trailing-spaces)
[error] 76-76: trailing spaces
(trailing-spaces)
[error] 81-81: trailing spaces
(trailing-spaces)
[error] 84-84: trailing spaces
(trailing-spaces)
[error] 92-92: trailing spaces
(trailing-spaces)
[error] 104-104: trailing spaces
(trailing-spaces)
[error] 128-128: trailing spaces
(trailing-spaces)
[error] 167-167: trailing spaces
(trailing-spaces)
[error] 190-190: trailing spaces
(trailing-spaces)
[error] 218-218: trailing spaces
(trailing-spaces)
[error] 229-229: trailing spaces
(trailing-spaces)
[error] 231-231: trailing spaces
(trailing-spaces)
[error] 242-242: trailing spaces
(trailing-spaces)
[error] 250-250: trailing spaces
(trailing-spaces)
.github/workflows/delete-review-app.yml
[error] 97-97: trailing spaces
(trailing-spaces)
🪛 actionlint (1.7.4)
.github/workflows/deploy-to-control-plane.yml
51-51: shellcheck reported issue in this script: SC2086:info:4:34: Double quote to prevent globbing and word splitting
(shellcheck)
51-51: shellcheck reported issue in this script: SC2086:info:5:68: Double quote to prevent globbing and word splitting
(shellcheck)
51-51: shellcheck reported issue in this script: SC2086:info:6:25: Double quote to prevent globbing and word splitting
(shellcheck)
65-65: shellcheck reported issue in this script: SC2086:info:1:54: Double quote to prevent globbing and word splitting
(shellcheck)
65-65: shellcheck reported issue in this script: SC2086:info:2:88: Double quote to prevent globbing and word splitting
(shellcheck)
74-74: shellcheck reported issue in this script: SC2086:info:5:27: Double quote to prevent globbing and word splitting
(shellcheck)
88-88: shellcheck reported issue in this script: SC2086:info:2:60: Double quote to prevent globbing and word splitting
(shellcheck)
88-88: shellcheck reported issue in this script: SC2086:info:3:59: Double quote to prevent globbing and word splitting
(shellcheck)
120-120: shellcheck reported issue in this script: SC2086:info:1:85: Double quote to prevent globbing and word splitting
(shellcheck)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: Process-Deployment-Command
🔇 Additional comments (10)
.github/actions/deploy-to-control-plane/scripts/deploy.sh (3)
Line range hint
4-22
: Well-structured environment validation!Good practices implemented:
- Early validation of required environment variables
- Default timeout with numeric validation
- Clear error messages
32-39
: Robust Docker image build implementation!Good practices implemented:
- Secure use of
mktemp
for temporary file- Proper cleanup with trap
- Comprehensive error handling with build output capture
59-70
: Well-implemented workload readiness check!Good practices implemented:
- Clear differentiation between timeout and other failures
- Proper exit code handling
- Good use of timeout with bash -c
.github/workflows/delete-review-app.yml (2)
Line range hint
29-42
: Good security practice with secrets validation!Well-implemented validation of required secrets before proceeding with deletion.
Line range hint
136-157
: Well-structured status updates!Good practices implemented:
- Clear success/failure differentiation
- Helpful links to logs and resources
- Good use of conditional messaging
🧰 Tools
🪛 yamllint (1.35.1)
[error] 144-144: trailing spaces
(trailing-spaces)
.github/actions/deploy-to-control-plane/action.yml (4)
29-42
: Great addition of early secret validation!The validation step for required secrets is a good security practice that fails fast and provides clear error messages.
🧰 Tools
🪛 yamllint (1.35.1)
[error] 38-38: trailing spaces
(trailing-spaces)
198-206
: Clean deployment configuration with good separation of concerns!The deployment step is well-structured with:
- Externalized deployment logic
- Proper environment variable handling
- Configurable timeout
207-257
: Excellent error handling and status reporting!The final status update provides comprehensive information with:
- Both success and failure handling
- GitHub deployment status updates
- Clear and informative messages
🧰 Tools
🪛 yamllint (1.35.1)
[error] 218-218: trailing spaces
(trailing-spaces)
[error] 229-229: trailing spaces
(trailing-spaces)
[error] 231-231: trailing spaces
(trailing-spaces)
[error] 242-242: trailing spaces
(trailing-spaces)
[error] 250-250: trailing spaces
(trailing-spaces)
136-152
: 🛠️ Refactor suggestionAdd error handling for app creation.
While the template application has error handling, the app creation step should also include error handling.
if ! cpflow exists -a ${{ inputs.app_name }} ; then echo "📦 Setting up new Control Plane app..." - cpflow setup-app -a ${{ inputs.app_name }} + if ! cpflow setup-app -a ${{ inputs.app_name }}; then + echo "❌ Failed to create Control Plane app" + exit 1 + fi fiLikely invalid or redundant comment.
.github/workflows/deploy-to-control-plane.yml (1)
234-247
: Well-structured deployment configuration!The deployment step is well-organized with:
- Proper use of composite action
- Secure handling of secrets
- Configurable timeout with fallback
🧰 Tools
🪛 yamllint (1.35.1)
[error] 235-235: trailing spaces
(trailing-spaces)
[error] 236-236: trailing spaces
(trailing-spaces)
[error] 237-237: trailing spaces
(trailing-spaces)
- name: Check if Review App Exists | ||
id: check-app | ||
if: github.event_name == 'push' && steps.get-pr.outputs.has_pr == 'true' | ||
env: | ||
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN }} | ||
run: | | ||
if ! cpflow exists -a ${{ env.APP_NAME }}; then | ||
echo "No review app exists for this PR" | ||
exit 0 | ||
fi | ||
echo "app_exists=true" >> $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.
🛠️ Refactor suggestion
Add error handling for Control Plane CLI command.
The app existence check should handle potential CLI failures.
-if ! cpflow exists -a ${{ env.APP_NAME }}; then
+if ! cpflow exists -a "${{ env.APP_NAME }}" 2>/dev/null; then
echo "No review app exists for this PR"
exit 0
+elif [ $? -gt 1 ]; then
+ echo "❌ Failed to check if app exists"
+ exit 1
fi
-echo "app_exists=true" >> $GITHUB_OUTPUT
+echo "app_exists=true" >> "$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.
- name: Check if Review App Exists | |
id: check-app | |
if: github.event_name == 'push' && steps.get-pr.outputs.has_pr == 'true' | |
env: | |
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN }} | |
run: | | |
if ! cpflow exists -a ${{ env.APP_NAME }}; then | |
echo "No review app exists for this PR" | |
exit 0 | |
fi | |
echo "app_exists=true" >> $GITHUB_OUTPUT | |
- name: Check if Review App Exists | |
id: check-app | |
if: github.event_name == 'push' && steps.get-pr.outputs.has_pr == 'true' | |
env: | |
CPLN_TOKEN: ${{ secrets.CPLN_TOKEN }} | |
run: | | |
if ! cpflow exists -a "${{ env.APP_NAME }}" 2>/dev/null; then | |
echo "No review app exists for this PR" | |
exit 0 | |
elif [ $? -gt 1 ]; then | |
echo "❌ Failed to check if app exists" | |
exit 1 | |
fi | |
echo "app_exists=true" >> "$GITHUB_OUTPUT" |
🧰 Tools
🪛 actionlint (1.7.4)
74-74: shellcheck reported issue in this script: SC2086:info:5:27: Double quote to prevent globbing and word splitting
(shellcheck)
- name: Get PR Number for Push Event | ||
if: github.event_name == 'push' | ||
id: get-pr | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
missing_secrets=() | ||
for secret in "CPLN_TOKEN" "CPLN_ORG"; do | ||
if [ -z "${!secret}" ]; then | ||
missing_secrets+=("$secret") | ||
fi | ||
done | ||
|
||
if [ ${#missing_secrets[@]} -ne 0 ]; then | ||
echo "Required secrets are not set: ${missing_secrets[*]}" | ||
exit 1 | ||
# Get PR number from branch | ||
PR_NUMBER=$(gh pr list --head ${{ github.ref_name }} --json number --jq '.[0].number') | ||
if [ -n "$PR_NUMBER" ]; then | ||
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV | ||
echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-$PR_NUMBER" >> $GITHUB_ENV | ||
echo "has_pr=true" >> $GITHUB_OUTPUT | ||
else | ||
echo "No PR found for this branch" | ||
exit 0 | ||
fi | ||
|
||
- name: Setup Environment | ||
uses: ./.github/actions/setup-environment | ||
- name: Set PR Number for Comment Event | ||
if: github.event_name == 'issue_comment' | ||
run: | | ||
echo "PR_NUMBER=${{ github.event.issue.number }}" >> $GITHUB_ENV | ||
echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-${{ github.event.issue.number }}" >> $GITHUB_ENV | ||
|
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.
🛠️ Refactor suggestion
Add error handling and fix shell script quoting.
The PR number handling could be improved with better shell scripting practices.
# Get PR number from branch
-PR_NUMBER=$(gh pr list --head ${{ github.ref_name }} --json number --jq '.[0].number')
+PR_NUMBER=$(gh pr list --head "${{ github.ref_name }}" --json number --jq '.[0].number') || {
+ echo "Failed to get PR number"
+ exit 1
+}
if [ -n "$PR_NUMBER" ]; then
- echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
- echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-$PR_NUMBER" >> $GITHUB_ENV
+ {
+ echo "PR_NUMBER=${PR_NUMBER}" >> "$GITHUB_ENV"
+ echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-${PR_NUMBER}" >> "$GITHUB_ENV"
+ } || {
+ echo "Failed to set environment variables"
+ exit 1
+ }
echo "has_pr=true" >> $GITHUB_OUTPUT
else
echo "No PR found for this branch"
exit 0
fi
📝 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.
- name: Get PR Number for Push Event | |
if: github.event_name == 'push' | |
id: get-pr | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
missing_secrets=() | |
for secret in "CPLN_TOKEN" "CPLN_ORG"; do | |
if [ -z "${!secret}" ]; then | |
missing_secrets+=("$secret") | |
fi | |
done | |
if [ ${#missing_secrets[@]} -ne 0 ]; then | |
echo "Required secrets are not set: ${missing_secrets[*]}" | |
exit 1 | |
# Get PR number from branch | |
PR_NUMBER=$(gh pr list --head ${{ github.ref_name }} --json number --jq '.[0].number') | |
if [ -n "$PR_NUMBER" ]; then | |
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV | |
echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-$PR_NUMBER" >> $GITHUB_ENV | |
echo "has_pr=true" >> $GITHUB_OUTPUT | |
else | |
echo "No PR found for this branch" | |
exit 0 | |
fi | |
- name: Setup Environment | |
uses: ./.github/actions/setup-environment | |
- name: Set PR Number for Comment Event | |
if: github.event_name == 'issue_comment' | |
run: | | |
echo "PR_NUMBER=${{ github.event.issue.number }}" >> $GITHUB_ENV | |
echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-${{ github.event.issue.number }}" >> $GITHUB_ENV | |
- name: Get PR Number for Push Event | |
if: github.event_name == 'push' | |
id: get-pr | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
# Get PR number from branch | |
PR_NUMBER=$(gh pr list --head "${{ github.ref_name }}" --json number --jq '.[0].number') || { | |
echo "Failed to get PR number" | |
exit 1 | |
} | |
if [ -n "$PR_NUMBER" ]; then | |
{ | |
echo "PR_NUMBER=${PR_NUMBER}" >> "$GITHUB_ENV" | |
echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-${PR_NUMBER}" >> "$GITHUB_ENV" | |
} || { | |
echo "Failed to set environment variables" | |
exit 1 | |
} | |
echo "has_pr=true" >> $GITHUB_OUTPUT | |
else | |
echo "No PR found for this branch" | |
exit 0 | |
fi | |
- name: Set PR Number for Comment Event | |
if: github.event_name == 'issue_comment' | |
run: | | |
echo "PR_NUMBER=${{ github.event.issue.number }}" >> $GITHUB_ENV | |
echo "APP_NAME=qa-react-webpack-rails-tutorial-pr-${{ github.event.issue.number }}" >> $GITHUB_ENV |
🧰 Tools
🪛 actionlint (1.7.4)
51-51: shellcheck reported issue in this script: SC2086:info:4:34: Double quote to prevent globbing and word splitting
(shellcheck)
51-51: shellcheck reported issue in this script: SC2086:info:5:68: Double quote to prevent globbing and word splitting
(shellcheck)
51-51: shellcheck reported issue in this script: SC2086:info:6:25: Double quote to prevent globbing and word splitting
(shellcheck)
65-65: shellcheck reported issue in this script: SC2086:info:1:54: Double quote to prevent globbing and word splitting
(shellcheck)
65-65: shellcheck reported issue in this script: SC2086:info:2:88: Double quote to prevent globbing and word splitting
(shellcheck)
- name: Update Status - Success | ||
if: success() | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
eval(process.env.GET_CONSOLE_LINK); | ||
|
||
const prNumber = process.env.PR_NUMBER; | ||
const appUrl = process.env.REVIEW_APP_URL; | ||
const workflowUrl = process.env.WORKFLOW_URL; | ||
const isSuccess = '${{ job.status }}' === 'success'; | ||
|
||
// Create GitHub deployment status | ||
const deploymentStatus = { | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
deployment_id: ${{ fromJSON(steps.init-deployment.outputs.result).deploymentId }}, | ||
state: isSuccess ? 'success' : 'failure', | ||
environment_url: isSuccess ? appUrl : undefined, | ||
log_url: workflowUrl, | ||
environment: 'review' | ||
}; | ||
|
||
await github.rest.repos.createDeploymentStatus(deploymentStatus); | ||
|
||
// Define messages based on deployment status | ||
const successMessage = [ | ||
' Deployment complete for PR #' + prNumber + ', commit ' + '${{ env.COMMIT_HASH }}', | ||
'', | ||
' [Review App for PR #' + prNumber + '](' + appUrl + ')', | ||
'', | ||
' [View Completed Action Build and Deploy Logs](' + workflowUrl + ')', | ||
'✅ Deployment successful!', | ||
'', | ||
getConsoleLink(prNumber) | ||
].join('\n'); | ||
|
||
const failureMessage = [ | ||
' Deployment failed for PR #' + prNumber + ', commit ' + '${{ env.COMMIT_HASH }}', | ||
'🌐 Review app is ready at: ${{ env.REVIEW_APP_URL }}', | ||
'', | ||
' [View Deployment Logs with Errors](' + workflowUrl + ')', | ||
'📝 [View App Logs](' + process.env.WORKFLOW_URL + ')', | ||
'', | ||
getConsoleLink(prNumber) | ||
getConsoleLink(process.env.PR_NUMBER) | ||
].join('\n'); | ||
|
||
// Update the existing comment | ||
await github.rest.issues.updateComment({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
comment_id: process.env.COMMENT_ID, | ||
body: isSuccess ? successMessage : failureMessage | ||
body: successMessage |
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.
🛠️ Refactor suggestion
Add failure status update handler.
While success status is well handled, consider adding a failure handler to provide clear error feedback.
+ - name: Update Status - Failure
+ if: failure()
+ uses: actions/github-script@v7
+ with:
+ script: |
+ eval(process.env.GET_CONSOLE_LINK);
+
+ const failureMessage = [
+ '❌ Deployment failed!',
+ '',
+ '📝 [View Error Logs](' + process.env.WORKFLOW_URL + ')',
+ '',
+ getConsoleLink(process.env.PR_NUMBER)
+ ].join('\n');
+
+ await github.rest.issues.updateComment({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ comment_id: process.env.COMMENT_ID,
+ body: failureMessage
+ });
📝 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.
- name: Update Status - Success | |
if: success() | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
eval(process.env.GET_CONSOLE_LINK); | |
const prNumber = process.env.PR_NUMBER; | |
const appUrl = process.env.REVIEW_APP_URL; | |
const workflowUrl = process.env.WORKFLOW_URL; | |
const isSuccess = '${{ job.status }}' === 'success'; | |
// Create GitHub deployment status | |
const deploymentStatus = { | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
deployment_id: ${{ fromJSON(steps.init-deployment.outputs.result).deploymentId }}, | |
state: isSuccess ? 'success' : 'failure', | |
environment_url: isSuccess ? appUrl : undefined, | |
log_url: workflowUrl, | |
environment: 'review' | |
}; | |
await github.rest.repos.createDeploymentStatus(deploymentStatus); | |
// Define messages based on deployment status | |
const successMessage = [ | |
' Deployment complete for PR #' + prNumber + ', commit ' + '${{ env.COMMIT_HASH }}', | |
'', | |
' [Review App for PR #' + prNumber + '](' + appUrl + ')', | |
'', | |
' [View Completed Action Build and Deploy Logs](' + workflowUrl + ')', | |
'✅ Deployment successful!', | |
'', | |
getConsoleLink(prNumber) | |
].join('\n'); | |
const failureMessage = [ | |
' Deployment failed for PR #' + prNumber + ', commit ' + '${{ env.COMMIT_HASH }}', | |
'🌐 Review app is ready at: ${{ env.REVIEW_APP_URL }}', | |
'', | |
' [View Deployment Logs with Errors](' + workflowUrl + ')', | |
'📝 [View App Logs](' + process.env.WORKFLOW_URL + ')', | |
'', | |
getConsoleLink(prNumber) | |
getConsoleLink(process.env.PR_NUMBER) | |
].join('\n'); | |
// Update the existing comment | |
await github.rest.issues.updateComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
comment_id: process.env.COMMENT_ID, | |
body: isSuccess ? successMessage : failureMessage | |
body: successMessage | |
- name: Update Status - Success | |
if: success() | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
eval(process.env.GET_CONSOLE_LINK); | |
const successMessage = [ | |
'✅ Deployment successful!', | |
'', | |
'🌐 Review app is ready at: ${{ env.REVIEW_APP_URL }}', | |
'', | |
'📝 [View App Logs](' + process.env.WORKFLOW_URL + ')', | |
'', | |
getConsoleLink(process.env.PR_NUMBER) | |
].join('\n'); | |
await github.rest.issues.updateComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
comment_id: process.env.COMMENT_ID, | |
body: successMessage | |
- name: Update Status - Failure | |
if: failure() | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
eval(process.env.GET_CONSOLE_LINK); | |
const failureMessage = [ | |
'❌ Deployment failed!', | |
'', | |
'📝 [View Error Logs](' + process.env.WORKFLOW_URL + ')', | |
'', | |
getConsoleLink(process.env.PR_NUMBER) | |
].join('\n'); | |
await github.rest.issues.updateComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
comment_id: process.env.COMMENT_ID, | |
body: failureMessage | |
}); |
🧰 Tools
🪛 yamllint (1.35.1)
[error] 265-265: trailing spaces
(trailing-spaces)
🚀 Deploying to Control Plane... ⏳ Waiting for deployment to be ready... |
/help |
❌ Deployment failed for PR #618, commit d688a87 |
/help |
Available Commands
|
🚀 Deploying to Control Plane... ⏳ Waiting for deployment to be ready... |
✅ Deployment successful! 🌐 Review app is ready at: |
🚀 Deploying to Control Plane... ⏳ Waiting for deployment to be ready... |
/help |
Available Commands
|
❌ Review app for PR #618 failed to be deleted |
✅ Deployment successful! 🌐 Review app is ready at: |
This change is
Summary by CodeRabbit
Release Notes
New Features
Workflow Updates
Improvements