-
Notifications
You must be signed in to change notification settings - Fork 1
207 lines (164 loc) · 6.9 KB
/
Copy pathci-cd.yml
File metadata and controls
207 lines (164 loc) · 6.9 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
name: CI/CD Workflow
on:
push:
branches: [main]
pull_request:
branches: [main]
jobs:
test-backend:
defaults:
run:
working-directory: ./backend
runs-on: ubuntu-latest
env:
DATABASE_URL: postgresql://test_user:test_password@localhost:5432/test_db
DATABASE_ENGINE: django.db.backends.postgresql
DATABASE_NAME: test_db
DATABASE_USER: test_user
DATABASE_PASSWORD: test_pw
DATABASE_HOST: test_host
DATABASE_PORT: test_port
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
EMAIL_HOST: localhost
EMAIL_PORT: 1025
EMAIL_HOST_USER: ''
EMAIL_HOST_PASSWORD: ''
services:
redis:
image: redis
ports:
- 6379:6379
options: >- #verify the service is up and running properly before your tests begin.
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
postgres:
image: postgres
env:
POSTGRES_DB: test_db
POSTGRES_USER: test_user
POSTGRES_PASSWORD: test_password
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
mailhog:
image: mailhog/mailhog
ports:
- 1025:1025
- 8025:8025
steps:
- uses: actions/checkout@v4 #Clones repo into the GitHub Actions runner => without it => cannot access code
- name: Set Up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Cache Dependencies
uses: actions/cache@v4
with:
path: ~/.cache/pip #~ is home directory of virtual environment (runner) where this code is executed => path by default
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} #hashFiles: Changes if dependencies change
restore-keys: | #Fallback keys to use if exact match isn't found
${{ runner.os }}-pip-
${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}-
- name: Install Python Dependencies
run: pip install -r requirements.txt
- name: Check Migration
run: python manage.py makemigrations --check --dry-run #Prevents forgetting to create or commit migration files => especially when Supabase require consistent schema
#checking if you have any pending model changes that require migrations, but not actually applying those migrations to any database => can use with test database
- name: Run Django Unit Test
run: python manage.py test toast_tutor.tests.units
- name: Verify Django Build
run: python manage.py collectstatic --noinput --dry-run
test-frontend:
defaults:
run:
working-directory: ./frontend
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set Up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm' #caching is already integrated directly into the actions/setup-node action => dont need separate cache step like Django
cache-dependency-path: package-lock.json
- name: Install dependencies
run: npm ci #clean unecessary dependencies, look at package-locj.json and install exactly what we need
# - name: Run React test
# run: npm test -- --watchAll=false #allow Jest (React testing framework run once, not need to wait until file change/ CI hang indefinitely (may leads to timeout))
- name: Check Linting
run: npm run lint
- name: Build Vite
run: npm run build #verifies Vite code can be compiled for production
integration-tests:
needs: [test-backend, test-frontend]
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./backend
env:
DATABASE_URL: postgresql://test_user:test_password@localhost:5432/test_db
DATABASE_ENGINE: django.db.backends.postgresql
DATABASE_NAME: test_db
DATABASE_USER: test_user
DATABASE_PASSWORD: test_pw
DATABASE_HOST: test_host
DATABASE_PORT: test_port
SUPABASE_URL: ${{ secrets.SUPABASE_URL }}
SUPABASE_KEY: ${{ secrets.SUPABASE_KEY }}
EMAIL_HOST: localhost
EMAIL_PORT: 1025
EMAIL_HOST_USER: ''
EMAIL_HOST_PASSWORD: ''
services:
redis:
image: redis
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
postgres:
image: postgres
env:
POSTGRES_DB: test_db
POSTGRES_USER: test_user
POSTGRES_PASSWORD: test_password
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
mailhog:
image: mailhog/mailhog
ports:
- 1025:1025
- 8025:8025
steps:
- uses: actions/checkout@v4
- name: Set Up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Cache Dependencies
uses: actions/cache@v4
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}-
- name: Install Python Dependencies
run: pip install -r requirements.txt
- name: Run API/Integration Tests
run: python manage.py test toast_tutor.tests.apis