contract-tests.yml•2.86 kB
name: Contract Tests
on:
pull_request:
paths:
- 'src/**'
- 'codegen.yml'
- 'package.json'
- '.github/workflows/contract-tests.yml'
push:
branches: [main]
jobs:
contract-tests:
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout MCP repo
uses: actions/checkout@v5
- name: Checkout backend repo
uses: actions/checkout@v5
with:
repository: bbernstein/lacylights-node
path: backend
- name: Build backend Docker image
working-directory: backend
run: docker build -t lacylights-backend:test .
- name: Start backend container
run: |
docker run -d \
--name backend \
-p 4000:4000 \
-e DATABASE_URL="file:/app/test-contract.db" \
-e ARTNET_ENABLED=false \
-e NON_INTERACTIVE=true \
-e SKIP_FIXTURE_IMPORT=true \
--health-cmd="node dist/healthcheck.js" \
--health-interval=5s \
--health-timeout=3s \
--health-retries=10 \
lacylights-backend:test
- name: Wait for backend to be healthy
run: |
echo "Waiting for backend container to be healthy..."
for i in {1..30}; do
if [ "$(docker inspect -f '{{.State.Health.Status}}' backend)" == "healthy" ]; then
echo "Backend is healthy!"
exit 0
fi
echo "Attempt $i/30: Backend not healthy yet (status: $(docker inspect -f '{{.State.Health.Status}}' backend 2>/dev/null || echo 'unknown')), waiting..."
sleep 2
done
echo "Backend failed to become healthy within 60 seconds"
echo "Container logs:"
docker logs backend
exit 1
- name: Initialize database
run: |
echo "Creating database schema..."
docker exec --user root backend npx prisma db push --accept-data-loss
echo "Database initialized successfully"
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '18'
cache: 'npm'
- name: Install MCP dependencies
run: npm ci
- name: Run GraphQL codegen
env:
GRAPHQL_ENDPOINT: http://localhost:4000/graphql
run: npm run codegen
- name: Run contract tests
env:
GRAPHQL_ENDPOINT: http://localhost:4000/graphql
run: npm run test:contracts
- name: Stop backend container
if: always()
run: |
docker stop backend || true
docker rm backend || true
- name: Upload test results
if: always()
uses: actions/upload-artifact@v5
with:
name: contract-test-results
path: coverage/
retention-days: 7