Skip to content

Commit 06113e6

Browse files
committed
fix(ci): add PostgreSQL for packages/internal integration tests
- Add test-internal-integration job with PostgreSQL container - Remove packages/internal from test-integration matrix (it now needs DB) - Remove CI skip condition from advisory-lock.integration.test.ts
1 parent cf082fc commit 06113e6

File tree

2 files changed

+93
-9
lines changed

2 files changed

+93
-9
lines changed

.github/workflows/ci.yml

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ jobs:
171171
cli,
172172
common,
173173
packages/agent-runtime,
174-
packages/internal,
175174
sdk,
176175
web,
177176
]
@@ -318,4 +317,92 @@ jobs:
318317
echo "No integration tests found in packages/billing"
319318
fi
320319
320+
# Internal package integration tests (requires PostgreSQL for advisory lock tests)
321+
# DATABASE_URL is set at job level to override any secrets injection
322+
test-internal-integration:
323+
needs: [build-and-check]
324+
name: test-integration-packages/internal
325+
runs-on: ubuntu-latest
326+
env:
327+
DATABASE_URL: postgresql://postgres:postgres@127.0.0.1:5432/testdb
328+
services:
329+
postgres:
330+
image: postgres:16-alpine
331+
env:
332+
POSTGRES_USER: postgres
333+
POSTGRES_PASSWORD: postgres
334+
POSTGRES_DB: testdb
335+
options: >-
336+
--health-cmd pg_isready
337+
--health-interval 10s
338+
--health-timeout 5s
339+
--health-retries 5
340+
ports:
341+
- 5432:5432
342+
steps:
343+
- name: Checkout repository
344+
uses: actions/checkout@v4
345+
346+
- name: Set up Bun
347+
uses: oven-sh/setup-bun@v2
348+
with:
349+
bun-version: '1.3.5'
350+
351+
- name: Cache dependencies
352+
uses: actions/cache@v4
353+
with:
354+
path: |
355+
node_modules
356+
*/node_modules
357+
packages/*/node_modules
358+
key: ${{ runner.os }}-deps-${{ hashFiles('**/bun.lock*') }}
359+
restore-keys: |
360+
${{ runner.os }}-deps-
361+
362+
- name: Install dependencies
363+
run: bun install --frozen-lockfile
364+
365+
- name: Set environment variables
366+
env:
367+
SECRETS_CONTEXT: ${{ toJSON(secrets) }}
368+
run: |
369+
VAR_NAMES=$(bun scripts/generate-ci-env.ts)
370+
echo "$SECRETS_CONTEXT" | jq -r --argjson vars "$VAR_NAMES" '
371+
to_entries | .[] | select(.key as $k | $vars | index($k)) | .key + "=" + .value
372+
' >> $GITHUB_ENV
373+
echo "CODEBUFF_GITHUB_ACTIONS=true" >> $GITHUB_ENV
374+
echo "NEXT_PUBLIC_CB_ENVIRONMENT=test" >> $GITHUB_ENV
375+
echo "NEXT_PUBLIC_INFISICAL_UP=true" >> $GITHUB_ENV
376+
echo "CODEBUFF_GITHUB_TOKEN=${{ secrets.CODEBUFF_GITHUB_TOKEN }}" >> $GITHUB_ENV
377+
378+
- name: Build SDK before integration tests
379+
run: cd sdk && bun run build
380+
381+
# Override any DATABASE_URL injected from secrets with our test container URL
382+
- name: Override DATABASE_URL for test container
383+
run: echo "DATABASE_URL=postgresql://postgres:postgres@127.0.0.1:5432/testdb" >> $GITHUB_ENV
384+
385+
- name: Setup database schema
386+
uses: nick-fields/retry@v3
387+
env:
388+
DATABASE_URL: postgresql://postgres:postgres@127.0.0.1:5432/testdb
389+
with:
390+
timeout_minutes: 2
391+
max_attempts: 3
392+
command: cd packages/internal && bun run db:migrate
393+
394+
- name: Run internal integration tests
395+
uses: nick-fields/retry@v3
396+
with:
397+
timeout_minutes: 15
398+
max_attempts: 3
399+
command: |
400+
cd packages/internal
401+
TEST_FILES=$(find src -name '*.integration.test.ts' 2>/dev/null | sort)
402+
if [ -n "$TEST_FILES" ]; then
403+
echo "$TEST_FILES" | xargs -I {} bun test --timeout=60000 {}
404+
else
405+
echo "No integration tests found in packages/internal"
406+
fi
407+
321408
# E2E tests for web intentionally omitted for now.

packages/internal/src/db/__tests__/advisory-lock.integration.test.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,11 @@ const DEFAULT_TEST_DATABASE_URL =
5454
'postgresql://postgres:postgres@127.0.0.1:5432/testdb'
5555
const TEST_DATABASE_URL = process.env.DATABASE_URL || DEFAULT_TEST_DATABASE_URL
5656

57-
// Skip tests if:
58-
// 1. Running in GitHub Actions CI (which doesn't have a real Postgres for packages/internal)
59-
// 2. DATABASE_URL is not configured locally and RUN_INTEGRATION_TESTS is not set
60-
// Note: CI injects DATABASE_URL as a secret, but there's no actual database running
61-
// for packages/internal integration tests (only packages/billing has Postgres in CI)
62-
const SKIP_INTEGRATION_TESTS =
63-
process.env.CODEBUFF_GITHUB_ACTIONS === 'true' ||
64-
(!process.env.DATABASE_URL && !process.env.RUN_INTEGRATION_TESTS)
57+
// Skip tests if DATABASE_URL is not configured and RUN_INTEGRATION_TESTS is not set.
58+
// In CI, the test-internal-integration job provides a PostgreSQL container and sets DATABASE_URL.
59+
// Locally, you can either set DATABASE_URL or RUN_INTEGRATION_TESTS=true.
60+
const SKIP_INTEGRATION_TESTS =
61+
!process.env.DATABASE_URL && !process.env.RUN_INTEGRATION_TESTS
6562

6663
// Create test database connection
6764
let testClient: ReturnType<typeof postgres> | null = null

0 commit comments

Comments
 (0)