-
Notifications
You must be signed in to change notification settings - Fork 1
291 lines (251 loc) · 8.04 KB
/
tests.yml
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
name: Unit tests
on:
push:
branches: [ master ]
paths-ignore:
- 'scripts/**'
- '.github/workflows/dokku.yml'
- 'Procfile'
- 'Dockerfile'
pull_request:
jobs:
js-tests:
defaults:
run:
working-directory: web
name: Web app tests
runs-on: ubuntu-latest
container: node:18-bullseye
# Service containers to run with `container-job`
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres:12.4
# Provide the password for postgres
env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
# Docker Hub image
image: redis
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
# Force https use since ssh does not work
- run: 'git config --global url."https://github.com/".insteadOf ssh://git@github.com/'
- run: 'git config --global url."https://".insteadOf ssh://'
- uses: pnpm/action-setup@v2
with:
version: 8
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'pnpm'
cache-dependency-path: pnpm-lock.yaml
- name: Install deps
run: |
pnpm install --frozen-lockfile
cd .. && pnpm install --frozen-lockfile
- name: Initialize database
run: cd .. && pnpm migrate:up && pnpm migrate:test
- name: Run vitest and generate coverage
run: pnpm test:ci
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3.1.4
with:
flags: frontend
name: Frontend coverage
env:
DB_HOST: postgres
DB_PORT: 5432
DB_NAME: postgres
DB_NAME_TEST: postgres
DB_USER: postgres
PGPASSWORD: postgres
ELASTIC_NODE: http://localhost:9200
REDIS_URL: redis:6379
DEBUG: debug,session-*,auth-info
TZ: UTC
LEVEL: silent
SKIP_POSTINSTALL: true
IS_CI: true
python-tests:
name: Scraper tests
runs-on: ubuntu-latest
container: python:3.10-buster
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres:12.4
# Provide the password for postgres
env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.1
env:
discovery.type: single-node
options: >-
--health-cmd "curl http://localhost:9200/_cluster/health"
--health-interval 10s
--health-timeout 5s
--health-retries 10
ports:
- 9200:9200
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v2
with:
version: 8
- uses: actions/setup-node@v3.6.0
with:
node-version: '18'
cache: 'pnpm'
- name: Setup poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: 1.5.1
- name: Install dependencies
run: poetry install --with dev
- name: Lint with flake8
run: |
python -m pip install --upgrade pip
pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 src --count --select=E9,F63,F7,F82 --show-source --statistics --exclude **/mangaplus_pb2.py*
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 src --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --exclude **/mangaplus_pb2.py*
- name: Type checks with mypy
run: poetry run mypy --config-file mypy.ini ./src
- name: Install db migration dependencies
run: pnpm install --frozen-lockfile --ignore-scripts
- name: Test with pytest
run: poetry run pytest --cov=./src --cov-report=xml src
- name: Uninstall coveragepy
run: poetry run pip uninstall -y coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3.1.4
with:
flags: scraper
name: Scraper coverage
files: './coverage/coverage.xml'
env:
DB_HOST: postgres
DB_PORT: 5432
DB_NAME: postgres
DB_NAME_TEST: postgres
DB_USER: postgres
PGPASSWORD: postgres
DB_PASSWORD: postgres
NO_TEMP_DB: TRUE
ELASTIC_TEST_HOST: elasticsearch
ELASTIC_TEST_PORT: 9200
e2e-tests:
defaults:
run:
working-directory: web
name: Cypress E2E tests
runs-on: ubuntu-latest
container:
image: cypress/browsers:node16.13.0-chrome95-ff94
options: --user 1001
# Service containers to run with `container-job`
services:
# Label used to access the service container
postgres:
# Docker Hub image
image: postgres:12.4
# Provide the password for postgres
env:
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
# Docker Hub image
image: redis
# Set health checks to wait until redis has started
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
# Force https use since ssh does not work
- run: 'git config --global url."https://github.com/".insteadOf ssh://git@github.com/'
- run: 'git config --global url."https://".insteadOf ssh://'
- uses: pnpm/action-setup@v2
with:
version: 8
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'pnpm'
cache-dependency-path: pnpm-lock.yaml
- name: Install deps
run: cd .. && pnpm install --frozen-lockfile
- name: Initialize database
run: cd .. && pnpm migrate:up && pnpm migrate:test
- name: Persist Next.js build cache
uses: actions/cache@v3
with:
path: ${{ github.workspace }}/web/.next/cache
# Generate a new cache whenever packages or source files change.
key: nextjs-${{ hashFiles('pnpm-lock.yaml') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
nextjs-${{ hashFiles('pnpm-lock.yaml') }}-
- uses: cypress-io/github-action@v5.8.1
with:
browser: chrome
working-directory: ./web
build: pnpm cross-env NODE_ENV=production pnpm build-nyc
start: pnpm cross-env NODE_ENV=production pnpm start-coverage
wait-on: 'http://localhost:3000'
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3.1.4
with:
flags: E2E
name: E2E coverage
env:
DB_HOST: postgres
DB_PORT: 5432
DB_NAME: postgres
DB_NAME_TEST: postgres
DB_USER: postgres
PGPASSWORD: postgres
ELASTIC_NODE: http://localhost:9200
NEXTAUTH_URL: 'http://localhost:3000'
NEXTAUTH_SECRET: secret
REDIS_URL: redis:6379
DEBUG: debug,session-*,auth-info
TZ: UTC
LEVEL: silent
SKIP_POSTINSTALL: true
IS_CI: true
LOGIN_RETRY_COUNT: 3
CYPRESS: true
# need at least one oauth provider or next-auth crashes
DISCORD_CLIENT_ID: test
DISCORD_CLIENT_SECRET: test