-
Notifications
You must be signed in to change notification settings - Fork 15
chore: pre-start Supabase for affected packages in CI #423
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
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #!/bin/bash | ||
| # Prepares Supabase for client package by copying migrations and seed from core. | ||
| # Called automatically by scripts/supabase-start.sh before starting Supabase. | ||
|
|
||
| set -e | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| PKG_DIR="$(dirname "$SCRIPT_DIR")" | ||
|
|
||
| echo "Preparing Supabase for client..." | ||
| mkdir -p "$PKG_DIR/supabase/migrations/" | ||
| rm -f "$PKG_DIR/supabase/migrations/"*.sql | ||
| cp "$PKG_DIR/../core/supabase/migrations/"*.sql "$PKG_DIR/supabase/migrations/" | ||
| cp "$PKG_DIR/../core/supabase/seed.sql" "$PKG_DIR/supabase/" | ||
| echo "Migrations and seed copied from core" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #!/bin/bash | ||
| # Prepares Supabase for edge-worker package by copying migrations and seed from core. | ||
| # Called automatically by scripts/supabase-start.sh before starting Supabase. | ||
|
|
||
| set -e | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| PKG_DIR="$(dirname "$SCRIPT_DIR")" | ||
|
|
||
| echo "Preparing Supabase for edge-worker..." | ||
| mkdir -p "$PKG_DIR/supabase/migrations/" | ||
| rm -f "$PKG_DIR/supabase/migrations/"*.sql | ||
| cp "$PKG_DIR/../core/supabase/migrations/"*.sql "$PKG_DIR/supabase/migrations/" | ||
| cp "$PKG_DIR/../core/supabase/seed.sql" "$PKG_DIR/supabase/" | ||
| echo "Migrations and seed copied from core" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| #!/bin/bash | ||
| # scripts/ci-prestart-supabase.sh | ||
| # | ||
| # Pre-starts Supabase for affected packages in CI. | ||
| # First instance pulls Docker images, rest start in parallel. | ||
| # | ||
| # Usage: ./scripts/ci-prestart-supabase.sh <package1> [package2] ... | ||
| # Example: ./scripts/ci-prestart-supabase.sh core client | ||
| # Example: ./scripts/ci-prestart-supabase.sh edge-worker | ||
| # | ||
| # Env vars: | ||
| # NX_BASE - Base ref for affected check (default: origin/main) | ||
| # NX_HEAD - Head ref for affected check (default: HEAD) | ||
| # | ||
| # Optimization: Supabase start has two slow phases: | ||
| # 1. Docker image pull (~slow first time, then cached) | ||
| # 2. Container startup (~28s even with cached images) | ||
| # This script starts the first instance (pulls images), then starts | ||
| # the rest in parallel to save ~1 minute on CI runs. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| if [ $# -eq 0 ]; then | ||
| echo "Usage: $0 <package1> [package2] ..." | ||
| echo "Example: $0 core client" | ||
| exit 1 | ||
| fi | ||
|
|
||
| SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" | ||
| BASE=${NX_BASE:-origin/main} | ||
| HEAD=${NX_HEAD:-HEAD} | ||
|
|
||
| # Map packages to their directories | ||
| declare -A PKG_DIRS=( | ||
| ["core"]="pkgs/core" | ||
| ["client"]="pkgs/client" | ||
| ["edge-worker"]="pkgs/edge-worker" | ||
| ["cli"]="pkgs/cli" | ||
| ) | ||
|
|
||
| # Get all affected projects with supabase:ci-marker target | ||
| AFFECTED=$(pnpm nx show projects --affected -t supabase:ci-marker --base="$BASE" --head="$HEAD" 2>/dev/null || echo "") | ||
|
|
||
| # Filter to only packages specified as arguments | ||
| DIRS=() | ||
| for pkg in "$@"; do | ||
| if [ -z "${PKG_DIRS[$pkg]:-}" ]; then | ||
| echo "Warning: Unknown package '$pkg', skipping" | ||
| continue | ||
| fi | ||
| if echo "$AFFECTED" | grep -q "^${pkg}$"; then | ||
| DIRS+=("${PKG_DIRS[$pkg]}") | ||
| echo "Package '$pkg' is affected" | ||
| else | ||
| echo "Package '$pkg' is not affected, skipping" | ||
| fi | ||
| done | ||
|
|
||
| if [ ${#DIRS[@]} -eq 0 ]; then | ||
| echo "No affected packages need Supabase" | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "Starting Supabase for: ${DIRS[*]}" | ||
|
|
||
| LOGDIR=$(mktemp -d) | ||
| trap "rm -rf $LOGDIR" EXIT | ||
|
|
||
| # First one pulls Docker images (must complete before others) | ||
| echo "::group::Starting ${DIRS[0]} (pulling Docker images)" | ||
| if ! "$SCRIPT_DIR/supabase-start-locked.sh" "${DIRS[0]}" 2>&1 | tee "$LOGDIR/first.log"; then | ||
| echo "::endgroup::" | ||
| echo "::error::Failed to start ${DIRS[0]}" | ||
| exit 1 | ||
| fi | ||
| echo "::endgroup::" | ||
|
|
||
| # Rest in parallel (images cached, ~28s each but concurrent) | ||
| if [ ${#DIRS[@]} -gt 1 ]; then | ||
| REMAINING=$((${#DIRS[@]} - 1)) | ||
| echo "Starting $REMAINING more instance(s) in parallel..." | ||
|
|
||
| PIDS=() | ||
| for dir in "${DIRS[@]:1}"; do | ||
| name=$(basename "$dir") | ||
| "$SCRIPT_DIR/supabase-start-locked.sh" "$dir" > "$LOGDIR/$name.log" 2>&1 & | ||
| PIDS+=("$!:$dir:$name") | ||
| done | ||
|
|
||
| FAILED=0 | ||
| for entry in "${PIDS[@]}"; do | ||
| pid=${entry%%:*} | ||
| rest=${entry#*:} | ||
| dir=${rest%%:*} | ||
| name=${rest#*:} | ||
| if ! wait "$pid"; then | ||
| echo "::error::Failed to start $dir" | ||
| echo "::group::$name log" | ||
| cat "$LOGDIR/$name.log" | ||
| echo "::endgroup::" | ||
| FAILED=1 | ||
| else | ||
| echo ":: $dir started" | ||
| fi | ||
| done | ||
|
|
||
| if [ $FAILED -eq 1 ]; then | ||
| exit 1 | ||
| fi | ||
| fi | ||
|
|
||
| echo "All Supabase instances started" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The wildcard
*.sqlwill cause the script to fail if no SQL migration files exist in the core package. Since the script usesset -e, thecpcommand will exit with an error when the wildcard doesn't match any files, breaking the CI pipeline.Fix: Add a check before copying or use a glob pattern that won't fail:
Or use
shopt -s nullglobto make unmatched globs expand to nothing.Spotted by Graphite Agent

Is this helpful? React 👍 or 👎 to let us know.