Skip to content

refactor: modularize setup and teardown scripts for resilience#527

Merged
Kitenite merged 1 commit into
mainfrom
update-setup-script
Dec 28, 2025
Merged

refactor: modularize setup and teardown scripts for resilience#527
Kitenite merged 1 commit into
mainfrom
update-setup-script

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented Dec 28, 2025

Summary

  • Restructured .superset/setup.sh and .superset/teardown.sh so each step runs as an independent function
  • If one step fails, subsequent steps still execute instead of aborting early
  • Added summary report at the end showing all failed/skipped steps

Test plan

  • Ran setup.sh - all 6 steps passed
  • Ran teardown.sh - all 4 steps passed
  • Test with missing dependency (e.g., uninstall neonctl) to verify other steps still run

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Enhanced setup and teardown scripts with colorized, user-friendly output.
    • Improved error reporting now aggregates all missing dependencies and reports them together.
    • Added detailed summary reports showing completed, failed, and skipped steps at the end of each operation.

✏️ Tip: You can customize this high-level summary in your review settings.

Restructured both scripts so each step runs as an independent function.
If one step fails, subsequent steps still execute. A summary at the end
reports all failed/skipped steps.

Changes:
- Removed `set -e` to prevent early exit on errors
- Extracted 6 setup steps: load env, check deps, install deps, setup Neon, start Electric, write .env
- Extracted 4 teardown steps: load env, check deps, stop Electric, delete Neon
- Added failure tracking with summary report at script end
- Script exits non-zero only after all steps complete if any failed

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 28, 2025

📝 Walkthrough

Walkthrough

The setup and teardown scripts are refactored from monolithic flows into modular, step-based architectures with structured error tracking. Both scripts now execute sequential steps (environment loading, dependency checking, service configuration), accumulate failures in arrays, and emit consolidated summary reports at completion.

Changes

Cohort / File(s) Summary
Setup script refactoring
‵.superset/setup.sh‵
Introduced 8 new functions implementing step-based orchestration: step_load_env, step_check_dependencies, step_install_dependencies, step_setup_neon_branch, step_start_electric, step_write_env, print_summary, and internal tracking utilities. Added FAILED_STEPS/SKIPPED_STEPS arrays, color constants (YELLOW), and helper functions (error, success, warn). Main flow now sequences steps, tracks failures, and emits final summary instead of early exit on first error.
Teardown script refactoring
‵.superset/teardown.sh‵
Implemented 8 new functions with non-fatal step tracking: step_load_env, step_check_dependencies, step_stop_electric, step_delete_neon_branch, main, print_summary, step_failed, step_skipped. Replaced hard-fail logic with event-driven, failure-accumulating flow. Added color constants and consolidated teardown summary output reporting skipped and failed steps.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Poem

🐰 Scripts now hop in ordered steps, no rushing to the door,
Each phase tracked with care and flair, reporting final score,
Setup, teardown—both refactored neat—with colors bright and clear,
A modular ballet of tasks completes the setup year! 🎉

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the key changes and testing, but does not follow the provided template structure with Type of Change, Related Issues, and other required sections. Restructure the description to match the template: add Type of Change section (mark 'Refactor'), Related Issues section, and ensure all template sections are present.
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: refactoring setup and teardown scripts to be more modular and resilient.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch update-setup-script

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@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: 0

🧹 Nitpick comments (2)
.superset/setup.sh (2)

250-258: Consider using an underscore to indicate an intentionally unused loop variable.

The static analysis tool flags i as unused (SC2034). While this is a false positive for a retry loop, you can silence it by using _ as the loop variable.

🔎 Suggested fix
-  for i in {1..30}; do
+  for _ in {1..30}; do

328-366: step_skipped helper is defined but never used.

The step_skipped function and SKIPPED_STEPS array are defined but never populated. Consider either removing them if not needed, or implementing skip logic for steps that depend on failed prerequisites.

For example, you could skip dependent steps when prerequisites fail:

  # Step 5: Start Electric SQL
+  if [ -z "${DIRECT_URL:-}" ]; then
+    step_skipped "Start Electric SQL (Neon branch not available)"
+  elif ! step_start_electric; then
-  if ! step_start_electric; then
    step_failed "Start Electric SQL"
  fi
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5be2468 and 3496743.

📒 Files selected for processing (2)
  • .superset/setup.sh
  • .superset/teardown.sh
🧰 Additional context used
🧬 Code graph analysis (1)
.superset/teardown.sh (1)
.superset/setup.sh (5)
  • error (14-14)
  • success (15-15)
  • warn (16-16)
  • step_load_env (60-80)
  • step_check_dependencies (85-115)
🪛 Shellcheck (0.11.0)
.superset/setup.sh

[warning] 252-252: i appears unused. Verify use (or export if used externally).

(SC2034)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: Deploy Docs
  • GitHub Check: Deploy Marketing
  • GitHub Check: Deploy API
  • GitHub Check: Deploy Admin
  • GitHub Check: Deploy Web
  • GitHub Check: Build
🔇 Additional comments (13)
.superset/setup.sh (7)

1-16: LGTM! Well-structured initialization with clear color definitions and helper functions.

The removal of set -e in favor of set -uo pipefail aligns with the PR objective of continuing execution after step failures while still catching unset variables and pipeline errors.


28-55: LGTM! Clean summary implementation with proper exit code handling.

The print_summary function correctly reports both skipped and failed steps, and returns non-zero only when failures occurred via the [ ${#FAILED_STEPS[@]} -eq 0 ] idiom.


60-80: LGTM! Proper environment loading with appropriate guards.

The function validates both the path variable and file existence before sourcing, and correctly uses set -a to auto-export variables.


85-115: LGTM! Good approach to aggregate all missing dependencies before reporting.

This provides better UX by informing users of all missing tools in a single pass rather than failing on each one sequentially.


120-135: LGTM!

The function defensively checks for bun availability before attempting installation.


140-202: LGTM! Comprehensive Neon branch setup with idempotent behavior.

The function correctly handles both existing and new branches, captures command output for error reporting, and exports the necessary variables for subsequent steps.


277-323: LGTM! Defensive .env writing with conditional variable appending.

The function correctly checks each variable before writing to avoid appending empty values, and properly handles the copy operation failure.

.superset/teardown.sh (6)

1-55: LGTM! Consistent structure with setup.sh for step tracking and summary reporting.

The initialization, helper functions, and print_summary implementation mirror the setup script, providing a consistent user experience.


60-75: LGTM! Correct behavior for teardown context.

Unlike setup which loads from SUPERSET_ROOT_PATH/.env, teardown correctly loads from the workspace's local .env file that was created during setup.


80-102: LGTM! Appropriate dependency subset for teardown.

The teardown script correctly checks only for neonctl and docker, which are the only tools needed for its operations.


107-134: LGTM! Idempotent container cleanup with graceful handling.

The function correctly handles both existing and already-removed containers, using warn for the latter case while still returning success. This is appropriate teardown behavior.


139-168: LGTM! Idempotent branch deletion with proper validation.

The function validates required environment variables before attempting deletion and handles the "already deleted" case gracefully.


173-201: LGTM! Consistent main execution flow with setup.sh.

The teardown main function follows the same pattern as setup, executing all steps and accumulating failures before printing the summary.

Same note as setup.sh: step_skipped is defined but unused. Consider removing it for consistency, or implementing skip logic for dependent steps.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Dec 28, 2025

🧹 Preview Cleanup Complete

The following preview resources have been cleaned up:

  • ✅ Neon database branch
  • ✅ Electric Fly.io app

Thank you for your contribution! 🎉

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