Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
1fe67e2
wip
klagrida Nov 9, 2025
2ecb223
wip
klagrida Nov 9, 2025
af01a50
wip
klagrida Nov 9, 2025
61149ac
wip
klagrida Nov 9, 2025
7f69aee
wip
klagrida Nov 9, 2025
2c3fe77
Fix CI workflow Edge Functions testing
klagrida Nov 9, 2025
5a1fcb8
Fix handle_new_user trigger to prevent login failures
klagrida Nov 9, 2025
54d8bc7
wip
klagrida Nov 9, 2025
176342c
Fix npm run logs command and CI workflow
klagrida Nov 9, 2025
8dc7099
Add migration 00005 to fix handle_new_user trigger
klagrida Nov 9, 2025
88f92bf
Disable trigger during seed to prevent conflicts
klagrida Nov 9, 2025
0a45d17
wip
klagrida Nov 9, 2025
eebb63c
Remove trigger disable/enable from seed script
klagrida Nov 9, 2025
7e4f865
Add debugging output for login failures
klagrida Nov 9, 2025
0e2c301
Add missing required fields to auth.users seed
klagrida Nov 9, 2025
89a9a91
Clean up test files
klagrida Nov 9, 2025
86fc6cc
Add comprehensive logging to CI for debugging
klagrida Nov 9, 2025
85ae569
Improve CI debugging for Edge Functions testing
klagrida Nov 16, 2025
4224a3f
Fix GitHub Actions CI workflow for Edge Functions testing
klagrida Nov 16, 2025
0d4aa8b
Fix auth service timing issue after database reset
klagrida Nov 16, 2025
c726110
Remove non-existent docker/setup-docker-action
klagrida Nov 16, 2025
af310b2
Fix auth.users schema - add missing email_change columns
klagrida Nov 16, 2025
0b74c11
Add remaining missing auth.users columns (recovery_token, phone_chang…
klagrida Nov 16, 2025
ddb6688
Fix password hashing - use PostgreSQL crypt() for bcrypt
klagrida Nov 16, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
213 changes: 194 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ jobs:
with:
node-version: '20'

- name: Set up Docker
uses: docker/setup-docker-action@v3

- uses: supabase/setup-cli@v1
with:
version: latest
Expand Down Expand Up @@ -59,51 +56,229 @@ jobs:
- run: npm run seed
shell: bash

- name: Start Edge Functions
- name: Wait for services to be ready after reset
shell: bash
run: |
# Start functions in background
supabase functions serve &
FUNCTIONS_PID=$!
echo "FUNCTIONS_PID=$FUNCTIONS_PID" >> $GITHUB_ENV
echo "Waiting for all services to stabilize after database reset..."
echo "Database reset restarts auth and other services, need to wait for them to be ready"
sleep 15

# Verify database is ready
echo "Checking database..."
docker exec supabase_db_supabase-template psql -U postgres -d postgres -c "SELECT 1" >/dev/null || {
echo "❌ Database not responding"
exit 1
}
echo "✅ Database is ready"

# Verify auth service is responding
echo "Checking auth service health..."
for i in {1..10}; do
if curl -sf http://127.0.0.1:54321/auth/v1/health >/dev/null 2>&1; then
echo "✅ Auth service is healthy"
break
fi
if [ $i -eq 10 ]; then
echo "❌ Auth service not responding after 10 attempts"
docker logs supabase_auth_supabase-template --tail 50
exit 1
fi
echo "Waiting for auth service... attempt $i/10"
sleep 3
done

# Verify seeded users exist and can be queried
echo "Verifying seeded data..."
USER_COUNT=$(docker exec supabase_db_supabase-template psql -U postgres -d postgres -t -c "SELECT COUNT(*) FROM auth.users WHERE email LIKE '%@example.com'")
echo "Found $USER_COUNT test users"
if [ "$USER_COUNT" -lt 3 ]; then
echo "❌ Expected at least 3 test users, found $USER_COUNT"
exit 1
fi
echo "✅ All services ready and data seeded"

- name: Deploy and verify Edge Functions
shell: bash
run: |
echo "Checking Edge Functions setup..."
ls -la supabase/functions/

# In modern Supabase CLI, functions should be auto-served by 'supabase start'
# However, let's verify the edge-runtime container is running
echo ""
echo "Checking if edge-runtime is running..."
docker ps | grep edge-runtime || echo "⚠️ edge-runtime container not found"

# Check Supabase status for functions
echo ""
echo "Supabase status:"
supabase status

# Wait for functions to be ready
echo "Waiting for Edge Functions to start..."
echo ""
echo "Waiting 10 seconds for Edge Functions to initialize..."
sleep 10

- name: Debug - Check seeded data
shell: bash
run: |
echo "Checking seeded users and profiles..."
STATUS_OUTPUT=$(supabase status)

API_URL=$(echo "$STATUS_OUTPUT" | grep -i "API URL" | head -n1 | awk '{print $NF}')
ANON_KEY=$(echo "$STATUS_OUTPUT" | grep -i "anon key\|publishable" | head -n1 | awk '{print $NF}')

# Fallback
if [ -z "$API_URL" ]; then
API_URL="http://127.0.0.1:54321"
fi

echo "API_URL: $API_URL"
echo "ANON_KEY length: ${#ANON_KEY}"

echo "Checking auth.users count..."
docker exec supabase_db_supabase-template psql -U postgres -d postgres -c "SELECT COUNT(*) as user_count FROM auth.users WHERE email LIKE '%@example.com';" || echo "Failed to query auth.users"

echo "Checking profiles..."
curl -s -H "apikey: $ANON_KEY" "$API_URL/rest/v1/profiles?select=username,is_admin" | jq '.' || echo "Failed to query profiles"

echo "Checking auth.users details (email, confirmed, encrypted_password)..."
docker exec supabase_db_supabase-template psql -U postgres -d postgres -c "SELECT id, email, email_confirmed_at, encrypted_password IS NOT NULL as has_password, is_sso_user FROM auth.users WHERE email LIKE '%@example.com';" || echo "Failed to query user details"

echo "Testing login manually..."
LOGIN_RESPONSE=$(curl -s -w "\nHTTP_CODE:%{http_code}" -X POST "$API_URL/auth/v1/token?grant_type=password" \
-H "apikey: $ANON_KEY" \
-H "Content-Type: application/json" \
-d '{"email":"alice@example.com","password":"password123"}')

echo "Login response:"
echo "$LOGIN_RESPONSE" | head -n -1 | jq '.' || echo "$LOGIN_RESPONSE" | head -n -1
echo "HTTP Status: $(echo "$LOGIN_RESPONSE" | tail -n 1 | cut -d: -f2)"

- name: Verify Edge Functions are ready
shell: bash
run: |
echo "Verifying Edge Functions endpoint..."
# Edge Functions are automatically served by 'supabase start' (via npm run dev)
# Test the actual admin-create-user function

for i in {1..10}; do
RESPONSE=$(curl -s -w "\nHTTP_CODE:%{http_code}" -X POST http://127.0.0.1:54321/functions/v1/admin-create-user \
-H "Content-Type: application/json" \
-d '{}' 2>&1)

HTTP_CODE=$(echo "$RESPONSE" | tail -n 1 | cut -d: -f2)

if [ "$HTTP_CODE" == "401" ] || [ "$HTTP_CODE" == "400" ] || [ "$HTTP_CODE" == "403" ]; then
echo "✅ Edge Functions endpoint is accessible (HTTP $HTTP_CODE - expected for unauthenticated request)"
break
fi

if [ $i -eq 10 ]; then
echo "❌ Edge Functions endpoint not responding after 10 attempts"
echo "Last response:"
echo "$RESPONSE" | head -n -1
echo "HTTP Code: $HTTP_CODE"
exit 1
else
echo "Checking Edge Functions endpoint... attempt $i/10 (HTTP $HTTP_CODE)"
sleep 3
fi
done

- name: Test Edge Functions
shell: bash
run: |
# Get API keys from supabase status
export SUPABASE_URL=$(supabase status | grep "API URL" | awk '{print $3}')
export SUPABASE_ANON_KEY=$(supabase status | grep "anon key" | awk '{print $3}')
# Get API keys from supabase status with better parsing
echo "Getting configuration from Supabase..."
STATUS_OUTPUT=$(supabase status)
echo "$STATUS_OUTPUT"
echo ""

# Extract values using different methods for reliability
export SUPABASE_URL=$(echo "$STATUS_OUTPUT" | grep -i "API URL" | head -n1 | awk '{print $NF}')
export SUPABASE_ANON_KEY=$(echo "$STATUS_OUTPUT" | grep -i "anon key\|publishable" | head -n1 | awk '{print $NF}')

# Fallback: try direct format
if [ -z "$SUPABASE_URL" ]; then
export SUPABASE_URL="http://127.0.0.1:54321"
fi

echo "Testing Edge Functions..."
echo "SUPABASE_URL: $SUPABASE_URL"
echo "SUPABASE_ANON_KEY length: ${#SUPABASE_ANON_KEY}"

# Verify we got the API key
if [ -z "$SUPABASE_ANON_KEY" ] || [ ${#SUPABASE_ANON_KEY} -lt 20 ]; then
echo "❌ Failed to get valid SUPABASE_ANON_KEY from status"
echo "Status output was:"
echo "$STATUS_OUTPUT"
exit 1
fi

# Run tests
deno run --allow-net --allow-env supabase/functions/test-functions.ts
echo "✅ Environment configured, running tests..."
echo ""
echo "=========================================="
echo "Starting Edge Functions Tests"
echo "=========================================="
echo ""

# Run tests with full output
deno run --allow-net --allow-env supabase/functions/test-functions.ts 2>&1 || TEST_EXIT_CODE=$?

echo ""
echo "=========================================="
echo "Test execution completed with exit code: ${TEST_EXIT_CODE:-0}"
echo "=========================================="

if [ ! -z "$TEST_EXIT_CODE" ] && [ "$TEST_EXIT_CODE" != "0" ]; then
echo ""
echo "Tests failed, checking database state..."
docker exec supabase_db_supabase-template psql -U postgres -d postgres -c "SELECT email, created_at, email_confirmed_at FROM auth.users WHERE email LIKE '%@example.com';" || echo "Could not query auth.users"
echo ""
echo "Checking auth logs..."
docker logs supabase_auth_supabase-template 2>&1 | tail -50
echo ""
echo "Checking edge-runtime logs..."
docker logs $(docker ps -q -f name=edge-runtime) 2>&1 | tail -50 || echo "No edge-runtime logs available"
exit $TEST_EXIT_CODE
fi

# Optional: Test database and services health (remove if not needed)
- name: Test database connection and data
shell: bash
run: |
# Get the API URL
# Get the API URL and key
API_URL=$(supabase status | grep "API URL" | awk '{print $3}')
ANON_KEY=$(supabase status | grep "Publishable key" | awk '{print $3}')

# Test API is responding
echo "Testing API endpoint..."
curl -f "$API_URL/rest/v1/" || exit 1
curl -f -H "apikey: $ANON_KEY" "$API_URL/rest/v1/" || exit 1

# Test database has tables (check if profiles table exists)
echo "Testing database tables..."
curl -f "$API_URL/rest/v1/profiles?select=count" || exit 1
curl -f -H "apikey: $ANON_KEY" "$API_URL/rest/v1/profiles?select=count" || exit 1

echo "✅ All services responding and database accessible"

- run: npm run logs
- name: Show logs on failure
if: failure()
shell: bash
run: |
echo "=========================================="
echo "Showing Supabase container logs..."
echo "=========================================="
echo ""
echo "--- Database Logs (last 100 lines) ---"
docker logs supabase_db_supabase-template --tail 100 2>&1 || echo "Could not fetch database logs"
echo ""
echo "--- Kong API Gateway Logs (last 50 lines) ---"
docker logs supabase_kong_supabase-template --tail 50 2>&1 || echo "Could not fetch API gateway logs"
echo ""
echo "--- Auth GoTrue Logs (last 50 lines) ---"
docker logs supabase_auth_supabase-template --tail 50 2>&1 || echo "Could not fetch auth logs"
echo ""
echo "=========================================="

- run: npm run stop
if: always()
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"migrate:prod": "supabase db push",
"diff": "supabase db diff",
"status": "supabase status",
"logs": "supabase logs",
"logs": "docker logs supabase_db_supabase-template --tail 100",
"shell": "supabase db shell",
"types": "supabase gen types typescript --local > types/database.types.ts",
"link": "supabase link"
Expand Down
2 changes: 1 addition & 1 deletion supabase/functions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ This will start all functions at:

### 3. Test Functions

**Get your anon key:**
**Get your publishable key:**
```bash
npm run status
```
Expand Down
4 changes: 2 additions & 2 deletions supabase/functions/TEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ Total: 6 | Passed: 6 | Failed: 0
# 1. Get your API key
npm run status

# Copy the "anon key"
# Copy the "Publishable key"

# 2. Login as admin
curl -X POST 'http://localhost:54321/auth/v1/token?grant_type=password' \
Expand Down Expand Up @@ -198,7 +198,7 @@ See `.github/workflows/ci.yml`:
- name: Test Edge Functions
run: |
export SUPABASE_URL=$(supabase status | grep "API URL" | awk '{print $3}')
export SUPABASE_ANON_KEY=$(supabase status | grep "anon key" | awk '{print $3}')
export SUPABASE_ANON_KEY=$(supabase status | grep "Publishable key" | awk '{print $3}')
deno run --allow-net --allow-env supabase/functions/test-functions.ts
```

Expand Down
6 changes: 6 additions & 0 deletions supabase/functions/import_map.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"imports": {
"supabase": "https://esm.sh/@supabase/supabase-js@2.39.3",
"@supabase/supabase-js": "https://esm.sh/@supabase/supabase-js@2.39.3"
}
}
Loading