forked from OlaGreat/NovaSupport
-
Notifications
You must be signed in to change notification settings - Fork 0
105 lines (91 loc) · 2.8 KB
/
Copy pathbackend.yml
File metadata and controls
105 lines (91 loc) · 2.8 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
name: Backend CI
on:
pull_request:
paths:
- "backend/**"
- ".github/workflows/backend.yml"
push:
branches:
- main
paths:
- "backend/**"
- ".github/workflows/backend.yml"
jobs:
backend:
name: Backend checks
runs-on: ubuntu-latest
defaults:
run:
working-directory: backend
services:
postgres:
image: postgres:16
env:
POSTGRES_DB: novasupport_test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U postgres -d novasupport_test"
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
DATABASE_URL: postgresql://postgres:postgres@127.0.0.1:5432/novasupport_test
DIRECT_URL: postgresql://postgres:postgres@127.0.0.1:5432/novasupport_test
NODE_ENV: test
SKIP_HORIZON_VALIDATION: "true"
steps:
- name: Check out repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: npm
cache-dependency-path: backend/package-lock.json
- name: Install backend dependencies
run: npm ci
- name: Generate Prisma client
run: npm run db:generate
- name: Validate Prisma schema
run: npx prisma validate
- name: Apply database migrations
run: npm run db:migrate:deploy
- name: Validate database migrations
run: |
set +e
DRIFT=$(npx prisma migrate diff \
--from-schema-datamodel prisma/schema.prisma \
--to-migrations prisma/migrations \
--shadow-database-url "$DATABASE_URL" \
--exit-code 2>&1)
DRIFT_EXIT=$?
set -e
echo "::group::Schema drift diff output"
echo "$DRIFT"
echo "::endgroup::"
if [ $DRIFT_EXIT -ne 0 ]; then
echo ""
echo "============================================"
echo " ❌ MIGRATION VALIDATION FAILED"
echo "============================================"
echo ""
echo " Drift detected — see diff output above."
echo ""
echo " To fix: create a new migration:"
echo " cd backend"
echo " npx prisma migrate dev --name describe_your_changes"
echo ""
exit 1
fi
echo "✅ Schema and migrations are in sync."
env:
DATABASE_URL: ${{ env.DATABASE_URL }}
- name: Run backend tests
run: npm run test
- name: Build backend
run: npm run build