-
Notifications
You must be signed in to change notification settings - Fork 915
fix(scripts): improve workspace setup/teardown reliability #333
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -10,6 +10,13 @@ success() { echo -e "${GREEN}✓${NC} $1"; } | |||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| echo "🚀 Setting up Superset workspace..." | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Load root .env for this script (provides NEON_PROJECT_ID, etc.) | ||||||||||||||||||||||||||||
| if [ -n "$SUPERSET_ROOT_PATH" ] && [ -f "$SUPERSET_ROOT_PATH/.env" ]; then | ||||||||||||||||||||||||||||
| set -a | ||||||||||||||||||||||||||||
| source "$SUPERSET_ROOT_PATH/.env" | ||||||||||||||||||||||||||||
| set +a | ||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Check dependencies | ||||||||||||||||||||||||||||
| command -v bun &> /dev/null || error "Bun not installed. Install from https://bun.sh" | ||||||||||||||||||||||||||||
| command -v neonctl &> /dev/null || error "Neon CLI not installed. Run: npm install -g neonctl" | ||||||||||||||||||||||||||||
|
|
@@ -24,38 +31,48 @@ echo "📥 Installing dependencies..." | |||||||||||||||||||||||||||
| bun install | ||||||||||||||||||||||||||||
| success "Dependencies installed" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Link direnv config from root repo if it exists | ||||||||||||||||||||||||||||
| if [ -n "$SUPERSET_ROOT_PATH" ] && [ -f "$SUPERSET_ROOT_PATH/.envrc" ]; then | ||||||||||||||||||||||||||||
| echo "🔧 Linking .envrc..." | ||||||||||||||||||||||||||||
| ln -sf "$SUPERSET_ROOT_PATH/.envrc" .envrc | ||||||||||||||||||||||||||||
| # Create .envrc for direnv | ||||||||||||||||||||||||||||
| if [ ! -f .envrc ]; then | ||||||||||||||||||||||||||||
| echo "🔧 Creating .envrc..." | ||||||||||||||||||||||||||||
| cat > .envrc << 'ENVRC' | ||||||||||||||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||||||||||||||
| dotenv .env | ||||||||||||||||||||||||||||
| ENVRC | ||||||||||||||||||||||||||||
| if command -v direnv &> /dev/null; then | ||||||||||||||||||||||||||||
| direnv allow | ||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||
| success "direnv configured" | ||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Create Neon branch for this workspace | ||||||||||||||||||||||||||||
| echo "🗄️ Creating Neon branch..." | ||||||||||||||||||||||||||||
| # Create or get Neon branch for this workspace | ||||||||||||||||||||||||||||
| WORKSPACE_NAME="${SUPERSET_WORKSPACE_NAME:-$(basename "$PWD")}" | ||||||||||||||||||||||||||||
| NEON_OUTPUT=$(neonctl branches create \ | ||||||||||||||||||||||||||||
| --project-id "$NEON_PROJECT_ID" \ | ||||||||||||||||||||||||||||
| --name "$WORKSPACE_NAME" \ | ||||||||||||||||||||||||||||
| --output json) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Parse connection strings from create output | ||||||||||||||||||||||||||||
| BRANCH_ID=$(echo "$NEON_OUTPUT" | jq -r '.branch.id') | ||||||||||||||||||||||||||||
| DIRECT_URL=$(echo "$NEON_OUTPUT" | jq -r '.connection_uris[0].connection_uri') | ||||||||||||||||||||||||||||
| POOLER_HOST=$(echo "$NEON_OUTPUT" | jq -r '.connection_uris[0].connection_parameters.pooler_host') | ||||||||||||||||||||||||||||
| PASSWORD=$(echo "$NEON_OUTPUT" | jq -r '.connection_uris[0].connection_parameters.password') | ||||||||||||||||||||||||||||
| ROLE=$(echo "$NEON_OUTPUT" | jq -r '.connection_uris[0].connection_parameters.role') | ||||||||||||||||||||||||||||
| DATABASE=$(echo "$NEON_OUTPUT" | jq -r '.connection_uris[0].connection_parameters.database') | ||||||||||||||||||||||||||||
| POOLED_URL="postgresql://${ROLE}:${PASSWORD}@${POOLER_HOST}/${DATABASE}?sslmode=require" | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| cat >> .env << EOF | ||||||||||||||||||||||||||||
| NEON_BRANCH_ID=$BRANCH_ID | ||||||||||||||||||||||||||||
| DATABASE_URL=$POOLED_URL | ||||||||||||||||||||||||||||
| DATABASE_URL_UNPOOLED=$DIRECT_URL | ||||||||||||||||||||||||||||
| EOF | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Check if branch already exists | ||||||||||||||||||||||||||||
| EXISTING_BRANCH=$(neonctl branches list --project-id "$NEON_PROJECT_ID" --output json | jq -r ".[] | select(.name == \"$WORKSPACE_NAME\") | .id") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if [ -n "$EXISTING_BRANCH" ]; then | ||||||||||||||||||||||||||||
| echo "🗄️ Using existing Neon branch..." | ||||||||||||||||||||||||||||
| BRANCH_ID="$EXISTING_BRANCH" | ||||||||||||||||||||||||||||
| # Get connection strings for existing branch | ||||||||||||||||||||||||||||
| DIRECT_URL=$(neonctl connection-string "$EXISTING_BRANCH" --project-id "$NEON_PROJECT_ID") | ||||||||||||||||||||||||||||
| POOLED_URL=$(neonctl connection-string "$EXISTING_BRANCH" --project-id "$NEON_PROJECT_ID" --pooled) | ||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||
| echo "🗄️ Creating Neon branch..." | ||||||||||||||||||||||||||||
| NEON_OUTPUT=$(neonctl branches create \ | ||||||||||||||||||||||||||||
| --project-id "$NEON_PROJECT_ID" \ | ||||||||||||||||||||||||||||
| --name "$WORKSPACE_NAME" \ | ||||||||||||||||||||||||||||
| --output json) | ||||||||||||||||||||||||||||
| BRANCH_ID=$(echo "$NEON_OUTPUT" | jq -r '.branch.id') | ||||||||||||||||||||||||||||
| # Get connection strings for new branch | ||||||||||||||||||||||||||||
| DIRECT_URL=$(neonctl connection-string "$BRANCH_ID" --project-id "$NEON_PROJECT_ID") | ||||||||||||||||||||||||||||
| POOLED_URL=$(neonctl connection-string "$BRANCH_ID" --project-id "$NEON_PROJECT_ID" --pooled) | ||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| # Copy root .env and override with branch-specific values | ||||||||||||||||||||||||||||
| cp "$SUPERSET_ROOT_PATH/.env" .env | ||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing validation and error handling for root .env copy. Line 72 copies the root .env without checking if the source file exists or if the copy succeeds. If SUPERSET_ROOT_PATH is unset or the file doesn't exist, cp will fail silently (partially, due to +[ -f "$SUPERSET_ROOT_PATH/.env" ] || error "Source .env not found at $SUPERSET_ROOT_PATH/.env"
cp "$SUPERSET_ROOT_PATH/.env" .env
+[ -f .env ] || error "Failed to copy .env to workspace"📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
| sed -i '' "s|^DATABASE_URL=.*|DATABASE_URL=$POOLED_URL|" .env | ||||||||||||||||||||||||||||
| sed -i '' "s|^DATABASE_URL_UNPOOLED=.*|DATABASE_URL_UNPOOLED=$DIRECT_URL|" .env | ||||||||||||||||||||||||||||
| echo "NEON_BRANCH_ID=$BRANCH_ID" >> .env | ||||||||||||||||||||||||||||
|
Comment on lines
+71
to
+75
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: sed -i '' is not portable; environment variable values may break sed patterns. Two issues here:
📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| success "Neon branch created: $WORKSPACE_NAME" | ||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent success message for branch reuse vs. creation. Line 77 always prints "Neon branch created: $WORKSPACE_NAME" even when an existing branch is reused (line 54). This is misleading. Update the message to reflect the actual action: +if [ "$EXISTING_BRANCH" != "" ]; then
+ success "Neon branch reused: $WORKSPACE_NAME"
+else
success "Neon branch created: $WORKSPACE_NAME"
+fiOr move the success message into each branch of the if/else block. 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||
| echo "✨ Done!" | ||||||||||||||||||||||||||||
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.
Root .env loading requires validation of SUPERSET_ROOT_PATH.
The script attempts to source
$SUPERSET_ROOT_PATH/.envbut does not validate that the path is absolute or that the file exists with correct permissions. If SUPERSET_ROOT_PATH is unset or malformed, the load silently skips, yet the script later assumes variables like NEON_PROJECT_ID are available. Consider adding explicit validation:This ensures the root .env is always available and fails fast with a clear error message.
🤖 Prompt for AI Agents