-
Notifications
You must be signed in to change notification settings - Fork 1
161 lines (136 loc) · 4.89 KB
/
deploy-server.yml
File metadata and controls
161 lines (136 loc) · 4.89 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
name: Deploy Server
on:
push:
branches: [main]
paths:
- 'packages/server/**'
- 'packages/shared/**'
- 'packages/mindcache/**'
- '.github/workflows/deploy-server.yml'
workflow_dispatch:
inputs:
skip_migrations:
description: 'Skip database migrations'
required: false
default: false
type: boolean
# Ensure only one deployment runs at a time
concurrency:
group: deploy-production
cancel-in-progress: false
jobs:
# First, ensure CI passes before deploying
ci-check:
runs-on: ubuntu-latest
name: Verify CI Status
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9.15.0
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile --ignore-scripts
- name: Cache Turborepo
uses: actions/cache@v4
with:
path: .turbo
key: turbo-${{ runner.os }}-node20-${{ github.ref_name }}-${{ github.sha }}
restore-keys: |
turbo-${{ runner.os }}-node20-${{ github.ref_name }}-
turbo-${{ runner.os }}-node20-main-
- name: Run TypeScript check
run: pnpm exec tsc --noEmit
- name: Run linter
run: pnpm run lint
- name: Run tests
run: pnpm test
- name: Build project
run: pnpm run build
env:
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: pk_test_dummy-key-for-ci-build
CLERK_SECRET_KEY: sk_test_dummy-key-for-ci-build
deploy:
runs-on: ubuntu-latest
name: Deploy to Cloudflare Workers
needs: [ci-check] # Only deploy if CI passes!
# Optional: Add environment protection for extra safety
# environment:
# name: production
# url: https://mindcache-api-production.dh7777777.workers.dev
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install pnpm
uses: pnpm/action-setup@v4
with:
version: 9.15.0
- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile --ignore-scripts
- name: Build shared package
run: pnpm --filter @mindcache/shared build
- name: Build mindcache SDK
run: pnpm --filter mindcache build
- name: Check for pending migrations
id: check_migrations
if: ${{ !inputs.skip_migrations }}
working-directory: packages/server
run: |
PENDING=$(pnpm db:migrations:list 2>&1 || true)
if echo "$PENDING" | grep -q "No migrations to apply"; then
echo "has_pending=false" >> $GITHUB_OUTPUT
echo "✅ No pending migrations"
else
echo "has_pending=true" >> $GITHUB_OUTPUT
echo "⚠️ Pending migrations detected"
fi
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- name: Apply database migrations
if: steps.check_migrations.outputs.has_pending == 'true' && !inputs.skip_migrations
working-directory: packages/server
run: pnpm db:migrate
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- name: Deploy to Cloudflare Workers
working-directory: packages/server
run: pnpm run deploy
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
- name: Deployment Summary
run: |
echo "## 🚀 Deployment Complete" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Server deployed to:** https://mindcache-api-production.dh7777777.workers.dev" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY
echo "**Triggered by:** ${{ github.actor }}" >> $GITHUB_STEP_SUMMARY
# Optional: Run smoke tests after deployment
smoke-test:
runs-on: ubuntu-latest
name: Post-deployment smoke test
needs: deploy
steps:
- name: Health check
run: |
# Simple health check - adjust URL as needed
HTTP_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://mindcache-api-production.dh7777777.workers.dev/health || echo "000")
if [ "$HTTP_STATUS" = "200" ] || [ "$HTTP_STATUS" = "404" ]; then
echo "✅ Server is responding (HTTP $HTTP_STATUS)"
else
echo "⚠️ Server returned HTTP $HTTP_STATUS"
fi