-
Notifications
You must be signed in to change notification settings - Fork 0
348 lines (293 loc) · 12.1 KB
/
Copy pathci-deploy.yml
File metadata and controls
348 lines (293 loc) · 12.1 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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
name: CI/CD
on:
push:
branches: [main, develop]
tags:
- 'v*'
pull_request:
branches: [main, develop]
permissions:
contents: write
jobs:
# ============================================
# CI Jobs - Run on all pushes and PRs
# ============================================
lint-and-typecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Extract version from STATE.md
run: node scripts/extract-version.cjs
env:
GIT_TAG: ${{ github.ref_name }}
- name: Build packages
run: pnpm build:packages
- name: Typecheck
run: pnpm typecheck
build-apk:
runs-on: ubuntu-latest
needs: [lint-and-typecheck]
if: (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) && github.event_name == 'push' && needs.lint-and-typecheck.result == 'success'
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'pnpm'
- name: Cache Gradle
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: gradle-${{ hashFiles('apps/android/android/gradle/wrapper/gradle-wrapper.properties') }}
restore-keys: gradle-
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Extract version from STATE.md
id: version
run: |
VERSION=$(node scripts/extract-version.cjs)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "build_number=${{ github.run_number }}" >> $GITHUB_OUTPUT
echo "git_sha=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
env:
BUILD_NUMBER: ${{ github.run_number }}
GIT_SHA: ${{ github.sha }}
GIT_TAG: ${{ github.ref_name }}
- name: Build packages
run: pnpm build:packages
- name: Expo prebuild
working-directory: apps/android
run: npx expo prebuild --platform android --clean
env:
EXPO_PUBLIC_SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
EXPO_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY }}
EXPO_PUBLIC_GOOGLE_WEB_CLIENT_ID: ${{ secrets.GOOGLE_WEB_CLIENT_ID }}
- name: Decode keystore
run: echo "${{ secrets.ANDROID_KEYSTORE_BASE64 }}" | base64 --decode > apps/android/android/app/release.keystore
- name: Build release APK
working-directory: apps/android/android
run: ./gradlew app:assembleRelease -PversionCode=${{ github.run_number }} -PversionName=${{ steps.version.outputs.version }}
env:
ANDROID_KEYSTORE_PASSWORD: ${{ secrets.ANDROID_KEYSTORE_PASSWORD }}
ANDROID_KEY_ALIAS: ${{ secrets.ANDROID_KEY_ALIAS }}
ANDROID_KEY_PASSWORD: ${{ secrets.ANDROID_KEY_PASSWORD }}
EXPO_PUBLIC_SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
EXPO_PUBLIC_SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY }}
EXPO_PUBLIC_GOOGLE_WEB_CLIENT_ID: ${{ secrets.GOOGLE_WEB_CLIENT_ID }}
- name: Rename APK
run: cp apps/android/android/app/build/outputs/apk/release/app-release.apk lumio.apk
- name: Rename APK with version
run: mv lumio.apk "lumio-v${{ steps.version.outputs.version }}+${{ github.run_number }}.${GITHUB_SHA::7}.apk"
- name: Upload APK artifact
uses: actions/upload-artifact@v4
with:
name: lumio-apk-v${{ steps.version.outputs.version }}-build${{ github.run_number }}
path: lumio-v*.apk
retention-days: 30
create-release:
runs-on: ubuntu-latest
needs: [build-apk]
if: (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) && github.event_name == 'push' && needs.build-apk.result == 'success'
steps:
- name: Download APK artifact
uses: actions/download-artifact@v4
with:
name: lumio-apk-v${{ needs.build-apk.outputs.version }}-build${{ github.run_number }}
- name: Prepare short SHA
id: sha
run: echo "short=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
- name: Rename APK to lumio.apk
run: mv lumio-v*.apk lumio.apk
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ needs.build-apk.outputs.version }}
name: v${{ needs.build-apk.outputs.version }}
body: "Lumio v${{ needs.build-apk.outputs.version }} - Build #${{ github.run_number }} (${{ steps.sha.outputs.short }})"
files: lumio.apk
make_latest: true
draft: false
prerelease: false
# ============================================
# Deploy Jobs - Only on push to main
# ============================================
deploy-landing:
runs-on: ubuntu-latest
needs: [lint-and-typecheck]
if: (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) && github.event_name == 'push' && needs.lint-and-typecheck.result == 'success'
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Extract version from STATE.md
id: version
run: |
VERSION=$(node scripts/extract-version.cjs)
echo "version=$VERSION" >> $GITHUB_OUTPUT
env:
GIT_TAG: ${{ github.ref_name }}
- name: Inject version into landing page
run: |
SHORT_SHA=${GITHUB_SHA::7}
DISPLAY_VERSION="${{ steps.version.outputs.version }}+${{ github.run_number }}.${SHORT_SHA}"
sed -i "s/__LUMIO_VERSION__/${DISPLAY_VERSION}/g" apps/landing/index.html
- name: Deploy to DigitalOcean
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.DO_HOST }}
username: ${{ secrets.DO_USERNAME }}
key: ${{ secrets.DO_SSH_KEY }}
source: 'apps/landing/*'
target: '/var/www/lumio'
strip_components: 2
- name: Reload Nginx
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.DO_HOST }}
username: ${{ secrets.DO_USERNAME }}
key: ${{ secrets.DO_SSH_KEY }}
script: sudo systemctl reload nginx
deploy-deck-builder:
runs-on: ubuntu-latest
needs: [lint-and-typecheck]
if: (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) && github.event_name == 'push' && needs.lint-and-typecheck.result == 'success'
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- uses: pnpm/action-setup@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
cache: 'pnpm'
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Extract version from STATE.md
id: version
run: |
VERSION=$(node scripts/extract-version.cjs)
echo "version=$VERSION" >> $GITHUB_OUTPUT
env:
GIT_TAG: ${{ github.ref_name }}
- name: Build packages
run: pnpm build:packages
- name: Run deck-builder tests
run: pnpm --filter @lumio/deck-builder test
- name: Build deck-builder
run: pnpm --filter @lumio/deck-builder build
env:
VITE_SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
VITE_SUPABASE_ANON_KEY: ${{ secrets.SUPABASE_ANON_KEY }}
- name: Inject version into index.html
run: |
SHORT_SHA=${GITHUB_SHA::7}
DISPLAY_VERSION="${{ steps.version.outputs.version }}+${{ github.run_number }}.${SHORT_SHA}"
sed -i "s/__LUMIO_VERSION__/${DISPLAY_VERSION}/g" apps/deck-builder/dist/index.html
- name: Deploy to DigitalOcean
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.DO_HOST }}
username: ${{ secrets.DO_USERNAME }}
key: ${{ secrets.DO_SSH_KEY }}
source: 'apps/deck-builder/dist/*'
target: '/var/www/deck-lumio'
strip_components: 3
- name: Reload Nginx
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.DO_HOST }}
username: ${{ secrets.DO_USERNAME }}
key: ${{ secrets.DO_SSH_KEY }}
script: sudo systemctl reload nginx
deploy-migrations:
runs-on: ubuntu-latest
needs: [lint-and-typecheck]
if: (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) && github.event_name == 'push' && needs.lint-and-typecheck.result == 'success'
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- uses: supabase/setup-cli@v1
with:
version: latest
- name: Link Supabase project
run: supabase link --project-ref ${{ secrets.SUPABASE_PROJECT_REF }}
env:
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
- name: Backup database
if: ${{ vars.ENABLE_DB_BACKUP == 'true' }}
run: |
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
supabase db dump --data-only -f "db_backup_${TIMESTAMP}.sql"
echo "Backup created: db_backup_${TIMESTAMP}.sql"
env:
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
SUPABASE_DB_PASSWORD: ${{ secrets.SUPABASE_DB_PASSWORD }}
- name: Upload backup artifact
if: ${{ vars.ENABLE_DB_BACKUP == 'true' }}
uses: actions/upload-artifact@v4
with:
name: db-backup-${{ github.run_number }}
path: db_backup_*.sql
retention-days: 30
- name: Run database migrations
run: supabase db push
env:
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
deploy-functions:
runs-on: ubuntu-latest
needs: [deploy-migrations]
if: (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')) && github.event_name == 'push' && needs.deploy-migrations.result == 'success'
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Extract version from STATE.md
id: version
run: |
VERSION=$(node scripts/extract-version.cjs)
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "build_number=${{ github.run_number }}" >> $GITHUB_OUTPUT
echo "git_sha=${GITHUB_SHA::7}" >> $GITHUB_OUTPUT
echo "build_date=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_OUTPUT
echo "Deploying Edge Functions - Version: $VERSION, Build: ${{ github.run_number }}, SHA: ${GITHUB_SHA::7}"
env:
GIT_TAG: ${{ github.ref_name }}
- uses: supabase/setup-cli@v1
with:
version: latest
- name: Deploy Edge Functions
run: |
supabase functions deploy git-sync --no-verify-jwt --project-ref ${{ secrets.SUPABASE_PROJECT_REF }}
supabase functions deploy docora-webhook --no-verify-jwt --project-ref ${{ secrets.SUPABASE_PROJECT_REF }}
supabase functions deploy llm-proxy --no-verify-jwt --project-ref ${{ secrets.SUPABASE_PROJECT_REF }}
supabase functions deploy question-generator --no-verify-jwt --project-ref ${{ secrets.SUPABASE_PROJECT_REF }}
supabase functions deploy study-planner --project-ref ${{ secrets.SUPABASE_PROJECT_REF }}
supabase functions deploy version --project-ref ${{ secrets.SUPABASE_PROJECT_REF }}
supabase functions deploy deck-commit --no-verify-jwt --project-ref ${{ secrets.SUPABASE_PROJECT_REF }}
env:
SUPABASE_ACCESS_TOKEN: ${{ secrets.SUPABASE_ACCESS_TOKEN }}
LUMIO_VERSION: ${{ steps.version.outputs.version }}
BUILD_NUMBER: ${{ steps.version.outputs.build_number }}
GIT_SHA: ${{ steps.version.outputs.git_sha }}
BUILD_DATE: ${{ steps.version.outputs.build_date }}