Skip to content

Commit afdc2e3

Browse files
committed
fix(ci): split billing integration tests into dedicated job with postgres
- Split test-integration into two jobs: one without Postgres (general packages) and test-billing-integration (dedicated for packages/billing with postgres:16-alpine) - Remove redundant include blocks from test and test-integration matrices - Remove .agents from test-integration (was always skipping) - Add fail-fast: false to matrix strategies - Reduce unit test retries from 5 to 3 - Add retry wrapper to db:migrate step - Update billing integration tests to use hardcoded DEFAULT_TEST_DATABASE_URL matching CI postgres container - tests no longer require DATABASE_URL env var to run
1 parent ba4dabb commit afdc2e3

File tree

2 files changed

+725
-662
lines changed

2 files changed

+725
-662
lines changed

.github/workflows/ci.yml

Lines changed: 90 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ jobs:
8181
test:
8282
needs: [build-and-check]
8383
strategy:
84+
fail-fast: false
8485
matrix:
8586
package:
8687
[
@@ -93,15 +94,6 @@ jobs:
9394
sdk,
9495
web,
9596
]
96-
include:
97-
- package: .agents
98-
- package: cli
99-
- package: common
100-
- package: packages/agent-runtime
101-
- package: packages/billing
102-
- package: packages/internal
103-
- package: sdk
104-
- package: web
10597
name: test-${{ matrix.package }}
10698
runs-on: ubuntu-latest
10799
steps:
@@ -147,7 +139,7 @@ jobs:
147139
uses: nick-fields/retry@v3
148140
with:
149141
timeout_minutes: 10
150-
max_attempts: 5
142+
max_attempts: 3
151143
command: |
152144
cd ${{ matrix.package }}
153145
if [ "${{ matrix.package }}" = ".agents" ]; then
@@ -168,31 +160,21 @@ jobs:
168160
# uses: mxschmitt/action-tmate@v3
169161
# timeout-minutes: 15 # optional guard
170162

171-
# Integration tests job
163+
# Integration tests job (packages that don't need a database)
172164
test-integration:
173165
needs: [build-and-check]
174166
strategy:
167+
fail-fast: false
175168
matrix:
176169
package:
177170
[
178-
.agents,
179171
cli,
180172
common,
181173
packages/agent-runtime,
182-
packages/billing,
183174
packages/internal,
184175
sdk,
185176
web,
186177
]
187-
include:
188-
- package: .agents
189-
- package: cli
190-
- package: common
191-
- package: packages/agent-runtime
192-
- package: packages/billing
193-
- package: packages/internal
194-
- package: sdk
195-
- package: web
196178
name: test-integration-${{ matrix.package }}
197179
runs-on: ubuntu-latest
198180
steps:
@@ -241,12 +223,93 @@ jobs:
241223
max_attempts: 3
242224
command: |
243225
cd ${{ matrix.package }}
244-
if [ "${{ matrix.package }}" = ".agents" ]; then
245-
# .agents e2e tests are in e2e/ directory and require real services
246-
# They are skipped in CI - run locally with: bun run test:e2e
247-
echo "Skipping .agents e2e tests in CI (require real services)"
226+
TEST_FILES=$(find src -name '*.integration.test.ts' 2>/dev/null | sort)
227+
if [ -n "$TEST_FILES" ]; then
228+
echo "$TEST_FILES" | xargs -I {} bun test --timeout=60000 {}
229+
else
230+
echo "No integration tests found in ${{ matrix.package }}"
231+
fi
232+
233+
# Billing integration tests (requires PostgreSQL)
234+
# Tests use a hardcoded default DATABASE_URL matching this container config
235+
test-billing-integration:
236+
needs: [build-and-check]
237+
name: test-integration-packages/billing
238+
runs-on: ubuntu-latest
239+
services:
240+
postgres:
241+
image: postgres:16-alpine
242+
env:
243+
POSTGRES_USER: postgres
244+
POSTGRES_PASSWORD: postgres
245+
POSTGRES_DB: testdb
246+
options: >-
247+
--health-cmd pg_isready
248+
--health-interval 10s
249+
--health-timeout 5s
250+
--health-retries 5
251+
ports:
252+
- 5432:5432
253+
steps:
254+
- name: Checkout repository
255+
uses: actions/checkout@v4
256+
257+
- name: Set up Bun
258+
uses: oven-sh/setup-bun@v2
259+
with:
260+
bun-version: '1.3.5'
261+
262+
- name: Cache dependencies
263+
uses: actions/cache@v4
264+
with:
265+
path: |
266+
node_modules
267+
*/node_modules
268+
packages/*/node_modules
269+
key: ${{ runner.os }}-deps-${{ hashFiles('**/bun.lock*') }}
270+
restore-keys: |
271+
${{ runner.os }}-deps-
272+
273+
- name: Install dependencies
274+
run: bun install --frozen-lockfile
275+
276+
- name: Set environment variables
277+
env:
278+
SECRETS_CONTEXT: ${{ toJSON(secrets) }}
279+
run: |
280+
VAR_NAMES=$(bun scripts/generate-ci-env.ts)
281+
echo "$SECRETS_CONTEXT" | jq -r --argjson vars "$VAR_NAMES" '
282+
to_entries | .[] | select(.key as $k | $vars | index($k)) | .key + "=" + .value
283+
' >> $GITHUB_ENV
284+
echo "CODEBUFF_GITHUB_ACTIONS=true" >> $GITHUB_ENV
285+
echo "NEXT_PUBLIC_CB_ENVIRONMENT=test" >> $GITHUB_ENV
286+
echo "NEXT_PUBLIC_INFISICAL_UP=true" >> $GITHUB_ENV
287+
echo "CODEBUFF_GITHUB_TOKEN=${{ secrets.CODEBUFF_GITHUB_TOKEN }}" >> $GITHUB_ENV
288+
289+
- name: Build SDK before integration tests
290+
run: cd sdk && bun run build
291+
292+
- name: Setup database schema
293+
uses: nick-fields/retry@v3
294+
env:
295+
DATABASE_URL: postgresql://postgres:postgres@127.0.0.1:5432/testdb
296+
with:
297+
timeout_minutes: 2
298+
max_attempts: 3
299+
command: cd packages/internal && bun run db:migrate
300+
301+
- name: Run billing integration tests
302+
uses: nick-fields/retry@v3
303+
with:
304+
timeout_minutes: 15
305+
max_attempts: 3
306+
command: |
307+
cd packages/billing
308+
TEST_FILES=$(find src -name '*.integration.test.ts' 2>/dev/null | sort)
309+
if [ -n "$TEST_FILES" ]; then
310+
echo "$TEST_FILES" | xargs -I {} bun test --timeout=60000 {}
248311
else
249-
find src -name '*.integration.test.ts' | sort | xargs -I {} bun test --timeout=60000 {}
312+
echo "No integration tests found in packages/billing"
250313
fi
251314
252315
# E2E tests for web intentionally omitted for now.

0 commit comments

Comments
 (0)