Skip to content

Fix Review App Deletion Workflows #639

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

Merged
merged 10 commits into from
Apr 29, 2025
Merged

Conversation

Judahmeek
Copy link
Collaborator

@Judahmeek Judahmeek commented Apr 27, 2025

This change is Reviewable

Summary by CodeRabbit

  • New Features
    • Introduced a GitHub Action for deleting Control Plane applications, with safeguards to prevent deletion of critical environments.
  • Chores
    • Updated workflows to use the new delete action and corrected environment variable usage.
    • Removed unused cleanup steps and simplified input parameters for improved reliability.
    • Enhanced deployment workflows to exit early when deployment is disabled and streamlined conditional checks.

Copy link

coderabbitai bot commented Apr 27, 2025

"""

Walkthrough

A new GitHub Action, "Delete Control Plane App," has been introduced to automate the deletion of Control Plane applications and their resources. This action uses a Bash script that validates input, prevents deletion of critical environments, checks for the application's existence, and deletes it if found. Workflow files have been updated to use this new action and script, with adjustments to environment variable handling and removal of unused parameters. The nightly workflow was streamlined by removing explicit stale PR fetching and per-PR deletion logic in favor of a single cleanup command. Deployment workflow improvements include an early exit if deployment is disabled and removal of redundant conditional checks.

Changes

File(s) Change Summary
.github/actions/delete-control-plane-app/action.yml
.github/actions/delete-control-plane-app/delete-app.sh
Introduced a new composite GitHub Action and accompanying Bash script to delete Control Plane applications, with safety checks and improved input validation.
.github/workflows/delete-review-app.yml Fixed environment variable validation syntax, simplified comment body, updated action inputs to use correct org variable, and removed unused parameters and unconditional run condition.
.github/workflows/nightly-remove-stale-review-apps.yml Removed "Get Stale PRs" step and per-PR deletion loop; replaced with a single cpflow cleanup-stale-apps -a "qa-react-webpack-rails-tutorial" --yes command; removed cleanup-images step.
.github/workflows/deploy-to-control-plane-review-app.yml Added early exit if deployment is disabled, simplified deployment conditionals by removing redundant DO_DEPLOY checks, and updated deployment comment content.

Sequence Diagram(s)

sequenceDiagram
    participant Workflow
    participant DeleteAction
    participant DeleteScript
    participant ControlPlane

    Workflow->>DeleteAction: Trigger Delete Control Plane App
    DeleteAction->>DeleteScript: Run delete-app.sh with APP_NAME, CPLN_ORG
    DeleteScript->>DeleteScript: Validate inputs and safety checks
    alt App name is safe
        DeleteScript->>ControlPlane: cpflow exists APP_NAME CPLN_ORG
        alt App exists
            DeleteScript->>ControlPlane: cpflow delete APP_NAME CPLN_ORG --force
            ControlPlane-->>DeleteScript: Deletion result
        else App does not exist
            DeleteScript-->>Workflow: Print warning, exit
        end
    else App name contains "production" or "staging"
        DeleteScript-->>Workflow: Print error, exit
    end
    DeleteScript-->>Workflow: Print confirmation or error
Loading

Suggested reviewers

  • justin808

Poem

In the warren of workflows, a new path appears,
To clean up our apps and allay any fears.
With scripts that are careful, and checks that are wise,
No "production" or "staging" will meet their demise!
Nightly the bunnies will hop through and sweep,
Keeping the Control Plane garden tidy and neat.
🐇✨
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2ad243c and 7440108.

📒 Files selected for processing (1)
  • .github/actions/delete-control-plane-app/delete-app.sh (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/actions/delete-control-plane-app/delete-app.sh
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: deploy
  • GitHub Check: test (22.x, 3.3.4)
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

Hi 👋 Here are the commands available for this PR:

  • /deploy-review-app: 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.

Copy link

🚀 Quick Review App Commands

Welcome! Here are the commands you can use in this PR:

/deploy-review-app

Deploy your PR branch for testing

/delete-review-app

Remove the review app when done

/help

Show detailed instructions, environment setup, and configuration options.


Copy link

@coderabbitai coderabbitai bot left a 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 (1)
.github/actions/delete-control-plane-app/delete-app.sh (1)

8-8: Consider enabling stricter error handling
Using set -e is good, but adding -u and -o pipefail helps catch unset variables and failures in pipelines.
Apply this diff:

-set -e
+set -euo pipefail
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9894731 and 3352e90.

📒 Files selected for processing (4)
  • .github/actions/delete-control-plane-app/action.yml (1 hunks)
  • .github/actions/delete-control-plane-app/delete-app.sh (1 hunks)
  • .github/workflows/delete-review-app.yml (2 hunks)
  • .github/workflows/nightly-remove-stale-review-apps.yml (1 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/delete-review-app.yml

148-148: input "org" is not defined in action "Delete Control Plane App" defined at "./.github/actions/delete-control-plane-app". available inputs are "app_name", "cpln_org"

(action)

🔇 Additional comments (7)
.github/actions/delete-control-plane-app/delete-app.sh (4)

11-12: Environment variable validation is clear and robust
Using parameter expansion with an error message ensures the script fails fast if required variables are missing.


15-20: Safety check prevents deleting critical environments
The case-insensitive grep for “production” or “staging” is an effective guardrail. Error messages are sent to stderr for visibility.


23-27: Graceful handling when the application does not exist
Checking existence first and exiting with status 0 avoids unnecessary errors in CI runs.


30-34: Deletion logic handles failures appropriately
The conditional deletion with error reporting on failure is well-structured.

.github/workflows/nightly-remove-stale-review-apps.yml (1)

51-51: Explicitly setting the organization variable
Assigning CPLN_ORG=${{ vars.CPLN_ORG_STAGING }} here aligns with how the delete script expects CPLN_ORG.

.github/actions/delete-control-plane-app/action.yml (2)

4-11: Composite action inputs are well-defined
Accepting app_name and cpln_org covers the necessary parameters for deletion.


12-21: Runs block correctly invokes the deletion script
Using github.action_path ensures the script is executed from the correct location.

Copy link

github-actions bot commented Apr 28, 2025

✅ Deployment complete for PR #639, commit 3100c84

🚀 Review App for PR #639
🎮 Control Plane Console

📋 View Completed Action Build and Deploy Logs

Copy link

github-actions bot commented Apr 29, 2025

✅ Deployment complete for PR #639, commit 3b8ab76

🚀 Review App for PR #639
🎮 Control Plane Console

📋 View Completed Action Build and Deploy Logs

Copy link

@coderabbitai coderabbitai bot left a 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 (2)
.github/actions/delete-control-plane-app/delete-app.sh (2)

8-9: Enhance script robustness with pipefail and undefined variable checks
It's best practice to add set -o pipefail and set -u alongside set -e to catch failures in pipelines and unset variables.

Proposed diff:

-set -e
+set -euo pipefail

38-39: Consider adding explicit exit code at the end
While a trailing echo returns 0 by default, an explicit exit 0 can improve clarity.

Proposed diff:

 echo "✅ Successfully deleted application: $APP_NAME"
+exit 0
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3100c84 and 3b8ab76.

📒 Files selected for processing (2)
  • .github/actions/delete-control-plane-app/delete-app.sh (1 hunks)
  • .github/workflows/delete-review-app.yml (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/delete-review-app.yml
🧰 Additional context used
🪛 Shellcheck (0.10.0)
.github/actions/delete-control-plane-app/delete-app.sh

[error] 13-13: ${$x} is invalid. For expansion, use ${x}. For indirection, use arrays, ${!x} or (for sh) eval.

(SC2298)


[error] 14-14: ${$x} is invalid. For expansion, use ${x}. For indirection, use arrays, ${!x} or (for sh) eval.

(SC2298)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: deploy
  • GitHub Check: test (22.x, 3.3.4)
🔇 Additional comments (3)
.github/actions/delete-control-plane-app/delete-app.sh (3)

16-22: Safety check for critical environments is solid
The grep-based guard prevents deletion of any app containing “production” or “staging” (case-insensitive), which is a good safeguard.


25-29: Handle non-existent apps gracefully
Exiting with status 0 when the app doesn’t exist is appropriate to avoid false failures in workflows.


31-36: Robust error handling on deletion
Checking the exit status of cpflow delete and exiting with an error code on failure ensures the Action fails fast if deletion does not succeed.

Copy link

github-actions bot commented Apr 29, 2025

✅ Deployment complete for PR #639, commit 3d45555

🚀 Review App for PR #639
🎮 Control Plane Console

📋 View Completed Action Build and Deploy Logs

Copy link

@coderabbitai coderabbitai bot left a 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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3b8ab76 and 3d45555.

📒 Files selected for processing (3)
  • .github/actions/delete-control-plane-app/delete-app.sh (1 hunks)
  • .github/workflows/deploy-to-control-plane-review-app.yml (2 hunks)
  • .github/workflows/nightly-remove-stale-review-apps.yml (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • .github/workflows/nightly-remove-stale-review-apps.yml
  • .github/actions/delete-control-plane-app/delete-app.sh
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: deploy
  • GitHub Check: test (22.x, 3.3.4)
🔇 Additional comments (1)
.github/workflows/deploy-to-control-plane-review-app.yml (1)

205-205: Removal of console link from initial comment is intentional
Dropping the CONSOLE_LINK here aligns with the new streamlined startup message. Subsequent status updates still include the console URL once it’s available.


- name: Setup Control Plane App if Not Existing
if: env.DO_DEPLOY == 'true' && env.APP_EXISTS == 'false'
if: env.APP_EXISTS == 'false'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Include DO_DEPLOY guard in the app setup condition
Right now the setup step only checks APP_EXISTS, so it can still run when deployments are disabled. It’s safer to combine both flags:

if: env.APP_EXISTS == 'false' && env.DO_DEPLOY != 'false'

This ensures that a new app is only provisioned when we explicitly want to deploy.

Comment on lines +184 to +186
if [[ "${{ env.DO_DEPLOY }}" == "false" ]]; then
exit 0
fi
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Early-exit logic does not skip subsequent steps as intended
The exit 0 inside the Validate Deployment Request step only terminates that shell script—it does not prevent the rest of the job from executing. As a result, even when DO_DEPLOY is "false", all downstream steps will still run.

To properly gate the workflow, consider emitting a step output (e.g., echo "do_deploy=${DO_DEPLOY}" >> $GITHUB_OUTPUT in the validate script) and then adding:

if: steps.validate.outputs.do_deploy == 'true'

to every subsequent step. This ensures that all deployment steps are truly skipped when DO_DEPLOY is disabled.

Copy link

github-actions bot commented Apr 29, 2025

✅ Deployment complete for PR #639, commit 8487edc

🚀 Review App for PR #639
🎮 Control Plane Console

📋 View Completed Action Build and Deploy Logs

Copy link

github-actions bot commented Apr 29, 2025

✅ Deployment complete for PR #639, commit 7de811b

🚀 Review App for PR #639
🎮 Control Plane Console

📋 View Completed Action Build and Deploy Logs

Copy link

github-actions bot commented Apr 29, 2025

✅ Review app for PR #639 was successfully deleted

View Completed Delete Logs

Control Plane Organization

Copy link

github-actions bot commented Apr 29, 2025

✅ Deployment complete for PR #639, commit 2ad243c

🚀 Review App for PR #639
🎮 Control Plane Console

📋 View Completed Action Build and Deploy Logs

@Judahmeek
Copy link
Collaborator Author

/delete-review-app

Copy link

github-actions bot commented Apr 29, 2025

✅ Review app for PR #639 was successfully deleted

View Completed Delete Logs

Control Plane Organization

Copy link

github-actions bot commented Apr 29, 2025

🚀 Deploying to Control Plane...

⏳ Waiting for deployment to be ready...

📝 View Deploy Logs

🎮 Control Plane Console

@github-actions github-actions bot requested a deployment to review-app April 29, 2025 21:39 In progress
Copy link

github-actions bot commented Apr 29, 2025

✅ Review app for PR #639 was successfully deleted

View Completed Delete Logs

Control Plane Organization

Copy link

github-actions bot commented Apr 29, 2025

✅ Deployment complete for PR #639, commit 7440108

🚀 Review App for PR #639
🎮 Control Plane Console

📋 View Completed Action Build and Deploy Logs

@Judahmeek Judahmeek merged commit 9ed72f0 into master Apr 29, 2025
8 of 9 checks passed
@Judahmeek Judahmeek deleted the judahmeek/delete-review-app branch April 29, 2025 21:53
Copy link

github-actions bot commented Apr 29, 2025

✅ Review app for PR #639 was successfully deleted

View Completed Delete Logs

Control Plane Organization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant