fix: update CI workflow test to match per-crate cargo test steps #17
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy API | |
| on: | |
| push: | |
| branches: [main] | |
| paths: | |
| - 'apps/api/**' | |
| - 'packages/contract/**' | |
| - 'packages/db/**' | |
| - 'packages/config/**' | |
| - 'fly.toml' | |
| - 'package.json' | |
| - 'bun.lock' | |
| - '.github/workflows/deploy-api.yml' | |
| workflow_dispatch: | |
| inputs: | |
| stage: | |
| description: Deployment stage | |
| required: true | |
| default: dev | |
| type: choice | |
| options: | |
| - dev | |
| - production | |
| concurrency: | |
| group: deploy-api-${{ inputs.stage || 'production' }} | |
| cancel-in-progress: false | |
| jobs: | |
| check: | |
| name: Typecheck & Test | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - run: bun install --frozen-lockfile | |
| - name: Build dependencies | |
| run: bun run --filter @sandchest/contract build && bun run --filter @sandchest/db build | |
| - name: Typecheck API | |
| run: bun run --filter @sandchest/api typecheck | |
| - name: Test API | |
| run: bun run --filter @sandchest/api test | |
| env: | |
| DATABASE_URL: mysql://test:test@localhost:3306/test | |
| BETTER_AUTH_SECRET: test-secret-for-ci-only-not-real | |
| RESEND_API_KEY: re_test_000000000000000000000000 | |
| migrate: | |
| name: Run Database Migrations | |
| needs: check | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 5 | |
| environment: production | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: oven-sh/setup-bun@v2 | |
| with: | |
| bun-version: latest | |
| - run: bun install --frozen-lockfile | |
| - name: Validate secrets | |
| run: | | |
| if [ -z "$DATABASE_URL" ]; then | |
| echo "::error::DATABASE_URL secret is not set. Add it to repo Settings → Secrets or the 'production' environment." | |
| exit 1 | |
| fi | |
| echo "DATABASE_URL is set (${#DATABASE_URL} chars)" | |
| env: | |
| DATABASE_URL: ${{ secrets.DATABASE_URL }} | |
| - name: Run database migrations | |
| run: bun run db:migrate:run | |
| env: | |
| DATABASE_URL: ${{ secrets.DATABASE_URL }} | |
| deploy: | |
| name: Deploy to Fly.io | |
| needs: migrate | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 15 | |
| environment: production | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: superfly/flyctl-actions/setup-flyctl@master | |
| - name: Validate Fly secrets | |
| run: | | |
| SECRETS=$(flyctl secrets list -a sandchest-api --json | jq -r '.[].Name') | |
| MISSING="" | |
| for name in DATABASE_URL BETTER_AUTH_SECRET RESEND_API_KEY REDIS_URL ADMIN_API_TOKEN; do | |
| if ! echo "$SECRETS" | grep -qx "$name"; then | |
| MISSING="$MISSING $name" | |
| fi | |
| done | |
| if [ -n "$MISSING" ]; then | |
| echo "::error::Missing Fly secrets:$MISSING" | |
| echo "Fix: flyctl secrets set -a sandchest-api NAME=value" | |
| exit 1 | |
| fi | |
| echo "All required secrets are set" | |
| env: | |
| FLY_ACCESS_TOKEN: ${{ secrets.FLY_ACCESS_TOKEN }} | |
| - name: Deploy to Fly.io | |
| run: flyctl deploy --remote-only | |
| env: | |
| FLY_ACCESS_TOKEN: ${{ secrets.FLY_ACCESS_TOKEN }} | |
| - name: Verify deployment | |
| run: | | |
| sleep 10 | |
| flyctl status -a sandchest-api | |
| env: | |
| FLY_ACCESS_TOKEN: ${{ secrets.FLY_ACCESS_TOKEN }} |