-
Notifications
You must be signed in to change notification settings - Fork 1
109 lines (91 loc) · 2.66 KB
/
deploy-api.yml
File metadata and controls
109 lines (91 loc) · 2.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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: 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 }}