Skip to content

Commit e061930

Browse files
committed
fix(ci): align supabase worktree env in tests
1 parent 925c0b4 commit e061930

5 files changed

Lines changed: 36 additions & 16 deletions

File tree

.github/workflows/tests.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,18 +63,20 @@ jobs:
6363
version: latest
6464
- name: Show Supabase CLI version
6565
run: supabase --version
66+
- name: Configure worktree Supabase env
67+
run: ./scripts/with-worktree-supabase-env.sh --print-env >> "$GITHUB_ENV"
6668
- name: Run Supabase Start
67-
run: supabase start -x imgproxy,studio,mailpit,realtime,postgres-meta,supavisor,studio,logflare,vector,realtime
69+
run: ./scripts/with-worktree-supabase-env.sh supabase start -x imgproxy,studio,mailpit,realtime,postgres-meta,supavisor,studio,logflare,vector,realtime
6870
- name: Run Supabase Test DB
69-
run: supabase test db
71+
run: ./scripts/with-worktree-supabase-env.sh supabase test db
7072
- name: Lint SQL
71-
run: supabase db lint -s public --fail-on warning
73+
run: ./scripts/with-worktree-supabase-env.sh supabase db lint -s public --fail-on warning
7274
- uses: JarvusInnovations/background-action@2428e7b970a846423095c79d43f759abf979a635 # v1
7375
name: Bootstrap Edge server
7476
with:
75-
run: supabase functions serve &
77+
run: ./scripts/with-worktree-supabase-env.sh supabase functions serve &
7678
wait-on: |
77-
http-get://127.0.0.1:54321/functions/v1/ok
79+
http-get://127.0.0.1:${{ env.SUPABASE_API_PORT }}/functions/v1/ok
7880
# IMPORTANT: to use environment variables in wait-on, you must use this form: ${{ env.VAR }}
7981
# See wait-on section below for all resource types and prefixes
8082

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,14 @@ This repository uses `./scripts/with-worktree-supabase-env.sh bunx supabase ...`
321321
for Supabase commands so each git worktree gets isolated Docker project and
322322
port assignments.
323323

324+
You can use the shorthand `bun run supabase:local -- <supabase-command>` for the
325+
same behavior. Examples:
326+
327+
```bash
328+
bun run supabase:local -- start
329+
bun run supabase:local -- db reset
330+
```
331+
324332
#### Start Supabase DB Locally
325333

326334
Start the Supabase DB:

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@
114114
"deploy:cloudflare_env:plugin_me:prod": "bunx wrangler secret bulk internal/cloudflare/.env.prod --config cloudflare_workers/plugin/wrangler.jsonc --env=prod_me",
115115
"deploy:cloudflare_env:plugin_hk:prod": "bunx wrangler secret bulk internal/cloudflare/.env.prod --config cloudflare_workers/plugin/wrangler.jsonc --env=prod_hk",
116116
"deploy:cloudflare_env:plugin_jp:prod": "bunx wrangler secret bulk internal/cloudflare/.env.prod --config cloudflare_workers/plugin/wrangler.jsonc --env=prod_jp",
117-
"deploy:supabase:prod": "./scripts/with-worktree-supabase-env.sh bunx supabase functions deploy --project-ref xvwzpoazmxkqosrdewyv",
118-
"deploy:supabase:preprod": "./scripts/with-worktree-supabase-env.sh bunx supabase functions deploy --project-ref aucsybvnhavogdmzwtcw",
119-
"deploy:supabase_env:prod": "./scripts/with-worktree-supabase-env.sh bunx supabase secrets set --project-ref xvwzpoazmxkqosrdewyv --env-file internal/cloudflare/.env.prod",
120-
"deploy:supabase_env:preprod": "./scripts/with-worktree-supabase-env.sh bunx supabase secrets set --project-ref aucsybvnhavogdmzwtcw --env-file internal/cloudflare/.env.preprod",
121-
"deploy:supabase_env:dev": "./scripts/with-worktree-supabase-env.sh bunx supabase secrets set --project-ref aucsybvnhavogdmzwtcw --env-file internal/cloudflare/.env.alpha",
117+
"deploy:supabase:prod": "bunx supabase functions deploy --project-ref xvwzpoazmxkqosrdewyv",
118+
"deploy:supabase:preprod": "bunx supabase functions deploy --project-ref aucsybvnhavogdmzwtcw",
119+
"deploy:supabase_env:prod": "bunx supabase secrets set --project-ref xvwzpoazmxkqosrdewyv --env-file internal/cloudflare/.env.prod",
120+
"deploy:supabase_env:preprod": "bunx supabase secrets set --project-ref aucsybvnhavogdmzwtcw --env-file internal/cloudflare/.env.preprod",
121+
"deploy:supabase_env:dev": "bunx supabase secrets set --project-ref aucsybvnhavogdmzwtcw --env-file internal/cloudflare/.env.alpha",
122122
"size": "bunx vite-bundle-visualizer",
123123
"sentry:sourcemaps": "_SENTRY_RELEASE=$(sentry-cli releases propose-version) && sentry-cli releases new $_SENTRY_RELEASE --org=forgr-cu --project=capgo-cloudflare && sentry-cli sourcemaps upload --org=forgr-cu --project=capgo-cloudflare --release=$_SENTRY_RELEASE --strip-prefix 'cloudflare_workers/api/dist/..' cloudflare_workers/api/dist",
124124
"postdeploy:cloudflare:api:prod": "bun run sentry:sourcemaps"

scripts/start-cloudflare-workers.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ GREEN='\033[0;32m'
1515
YELLOW='\033[1;33m'
1616
NC='\033[0m' # No Color
1717

18-
SUPABASE_CLI="${ROOT_DIR}/scripts/with-worktree-supabase-env.sh bunx supabase"
18+
SUPABASE_CLI=("${ROOT_DIR}/scripts/with-worktree-supabase-env.sh" bunx supabase)
1919

2020
# Extract a single variable from `supabase status -o env`, preserving any '=' in values (JWT padding).
2121
get_supabase_status_var() {
@@ -38,7 +38,7 @@ else
3838
echo -e "${YELLOW}Warning: ${BASE_ENV_FILE} not found - starting with empty base env${NC}"
3939
fi
4040

41-
SUPA_ENV="$(${SUPABASE_CLI} status -o env 2>/dev/null || true)"
41+
SUPA_ENV="$("${SUPABASE_CLI[@]}" status -o env 2>/dev/null || true)"
4242
SUPABASE_URL_FROM_STATUS="$(get_supabase_status_var 'API_URL')"
4343
# Supabase CLI has historically emitted either SERVICE_ROLE_KEY/ANON_KEY or SECRET_KEY/PUBLISHABLE_KEY.
4444
SUPABASE_SERVICE_ROLE_KEY_FROM_STATUS="$(get_supabase_status_var 'SERVICE_ROLE_KEY|SECRET_KEY')"

scripts/with-worktree-supabase-env.sh

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,29 @@
22

33
set -euo pipefail
44

5+
for cmd in cksum awk tr sed cut; do
6+
if ! command -v "${cmd}" >/dev/null 2>&1; then
7+
echo "Missing required command: ${cmd}" >&2
8+
exit 1
9+
fi
10+
done
11+
512
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
613
WORKTREE_NAME="$(basename "${ROOT_DIR}")"
714

15+
WORKTREE_HASH_DEC="$(printf '%s' "${ROOT_DIR}" | cksum | awk '{ print $1 }')"
16+
WORKTREE_HASH_HEX="$(printf '%x' "${WORKTREE_HASH_DEC}")"
17+
WORKTREE_HASH_SHORT="$(printf '%s' "${WORKTREE_HASH_HEX}" | cut -c1-6)"
18+
819
SLUG="$(printf '%s' "${WORKTREE_NAME}" | tr '[:upper:]' '[:lower:]' | tr -cs 'a-z0-9' '-' | sed -E 's/^-+//; s/-+$//')"
920
if [ -z "${SLUG}" ]; then
10-
SLUG="worktree"
21+
SLUG="worktree-${WORKTREE_HASH_SHORT}"
1122
fi
1223

13-
WORKTREE_HASH_DEC="$(printf '%s' "${ROOT_DIR}" | cksum | awk '{ print $1 }')"
14-
WORKTREE_HASH_HEX="$(printf '%x' "${WORKTREE_HASH_DEC}")"
15-
WORKTREE_HASH_SHORT="$(printf '%s' "${WORKTREE_HASH_HEX}" | cut -c1-6)"
1624
SLUG_SHORT="$(printf '%s' "${SLUG}" | cut -c1-20)"
1725

26+
# Reserve a 20-port block per worktree to keep room for additional local services
27+
# without renumbering existing allocations.
1828
SLOT=$((WORKTREE_HASH_DEC % 600))
1929
BASE_PORT=$((42000 + SLOT * 20))
2030

0 commit comments

Comments
 (0)