-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yml
More file actions
215 lines (183 loc) · 5.64 KB
/
Copy pathTaskfile.yml
File metadata and controls
215 lines (183 loc) · 5.64 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
# ---------------------------------------------------------------------------
# KNJudge task runner (https://taskfile.dev)
#
# task list every task
# task up bring the whole stack up with Docker Compose
# task check everything CI runs, in the order CI runs it
#
# Every task here is the same command CI runs. That is the point: if `task
# check` passes locally, the pipeline has nothing new to tell you, and when it
# fails you reproduce it with one word rather than by reading a YAML file.
# ---------------------------------------------------------------------------
version: '3'
vars:
COMPOSE: docker compose -f infra/docker/compose.yaml
MONGO_IMAGE: mongo:7
TEST_DB: knjudge-test
env:
NODE_ENV: development
tasks:
default:
desc: List the available tasks
silent: true
cmds:
- task --list
# -- development ---------------------------------------------------------
install:
desc: Install dependencies exactly as the lockfile pins them
cmds:
- npm ci
sources:
- package.json
- package-lock.json
generates:
- node_modules/.package-lock.json
dev:
desc: Run the API with a file watcher
deps: [install]
cmds:
- npm run dev
worker:
desc: Run a judge worker against a local API
deps: [install]
cmds:
- npm run worker
mongo:up:
desc: Start a single-node MongoDB replica set for local work
status:
- docker inspect -f '{{`{{.State.Running}}`}}' knjudge-mongo 2>/dev/null | grep -q true
cmds:
- docker run -d --name knjudge-mongo -p 27017:27017 {{.MONGO_IMAGE}} mongod --replSet rs0 --bind_ip_all
- sleep 6
- >-
docker exec knjudge-mongo mongosh --quiet --eval
"try { rs.status().ok } catch (e) { rs.initiate({_id:'rs0',members:[{_id:0,host:'127.0.0.1:27017'}]}).ok }"
- sleep 4
mongo:down:
desc: Stop and remove the local MongoDB container
cmds:
- docker rm -f knjudge-mongo
ignore_error: true
migrate:
desc: Apply pending migrations
deps: [install]
cmds:
- npm run migrate
migrate:status:
desc: Show which migrations have run
cmds:
- npm run migrate:status
provision:
desc: 'Fill the database with the catalogue and a cohort (SCALE=demo|lab|faculty)'
deps: [install]
cmds:
- ./scripts/provision.sh --scale {{.SCALE | default "lab"}}
provision:reset:
desc: Drop everything and provision from scratch
cmds:
- ASSUME_YES=yes ./scripts/provision.sh --reset --scale {{.SCALE | default "lab"}}
test:
desc: Unit and integration tests
deps: [install, mongo:up]
env:
MONGODB_URI_TEST: mongodb://127.0.0.1:27017/{{.TEST_DB}}?replicaSet=rs0&directConnection=true
cmds:
- npm test
test:unit:
desc: Unit tests only — no database needed
deps: [install]
cmds:
- npm run test:unit
test:e2e:
desc: End-to-end tests in a real browser
deps: [install, mongo:up]
env:
MONGODB_URI_TEST: mongodb://127.0.0.1:27017/knjudge-e2e?replicaSet=rs0&directConnection=true
cmds:
- npx playwright test
verify:
desc: Check the routes, the docs and the assertion catalogue agree
deps: [install]
cmds:
- npm run verify
verify:fleet:
desc: Two real workers against a real API — registration, judging, recovery
deps: [install, mongo:up]
env:
MONGODB_URI_TEST: mongodb://127.0.0.1:27017/knjudge-fleet?replicaSet=rs0&directConnection=true
cmds:
- npm run verify:fleet
verify:responsive:
desc: Measure every page at seven widths for horizontal overflow
deps: [install, mongo:up]
env:
MONGODB_URI_TEST: mongodb://127.0.0.1:27017/knjudge-responsive?replicaSet=rs0&directConnection=true
cmds:
- npm run verify:responsive
check:
desc: Everything CI runs, in the same order
cmds:
- task: lint
- task: verify
- task: test
- task: verify:fleet
- task: test:e2e
- task: verify:responsive
lint:
desc: ESLint and Stylelint
deps: [install]
cmds:
- npm run lint
build:
desc: Build the API and worker images
cmds:
- '{{.COMPOSE}} build'
up:
desc: Bring the whole stack up (add SCALE_WORKERS=4 for more judges)
cmds:
- '{{.COMPOSE}} up -d --build --scale worker={{.SCALE_WORKERS | default 2}}'
- task: wait
- echo "KNJudge is on http://localhost:4000"
wait:
desc: Block until the API reports healthy
cmds:
- |
for attempt in $(seq 1 60); do
if curl -fsS http://localhost:4000/api/health >/dev/null 2>&1; then
echo "api healthy after ${attempt}s"; exit 0
fi
sleep 1
done
echo "api did not become healthy in 60s" >&2
{{.COMPOSE}} logs --tail 40 api >&2
exit 1
down:
desc: Tear the stack down, keeping the database volume
cmds:
- '{{.COMPOSE}} down'
clean:
desc: Tear the stack down and delete the database volume
prompt: This deletes the Compose database volume. Continue?
cmds:
- '{{.COMPOSE}} down -v'
logs:
desc: Follow the stack's logs
cmds:
- '{{.COMPOSE}} logs -f --tail 100'
smoke:
desc: Probe a running deployment (BASE_URL=https://…)
cmds:
- BASE_URL={{.BASE_URL | default "http://localhost:4000"}} npm run smoke
media:
desc: Recapture every screenshot and demo recording
deps: [install]
cmds:
- node scripts/capture-demo.js
media:shots:
desc: Recapture the screenshots only (much faster)
cmds:
- node scripts/capture-demo.js --no-gif
diagrams:
desc: Re-render the architecture diagrams
cmds:
- npm run diagrams