-
Notifications
You must be signed in to change notification settings - Fork 3
396 lines (322 loc) · 12.4 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
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
name: Run tests
on:
push:
workflow_run:
workflows: Trigger PR sensitive workflows
types: completed
permissions:
actions: read
contents: read
pull-requests: write
jobs:
checkout:
name: Checkout repository
if: |
(
github.event_name == 'push' &&
github.actor != 'dependabot[bot]'
) || (
github.event_name == 'workflow_run' &&
github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.actor != 'dependabot[bot]'
)
runs-on: ubuntu-latest
outputs:
comment_id: ${{ steps.comment.outputs.comment_id }}
number: ${{ steps.pr-info-output.outputs.number }}
sha: ${{ steps.pr-info-output.outputs.sha }}
steps:
- name: Checkout repository
if: ${{ github.event_name == 'push' }}
uses: actions/checkout@v4
with:
submodules: recursive
- name: Get pull request HEAD SHA
if: ${{ github.event_name == 'workflow_run' }}
uses: actions/download-artifact@v4
with:
name: pull-request-info
path: /tmp/
github-token: ${{ github.token }}
run-id: ${{ github.event.workflow_run.id }}
- name: Save info to output
id: pr-info-output
if: ${{ github.event_name == 'workflow_run' }}
run: cat /tmp/pr.txt > $GITHUB_OUTPUT
- name: Checkout pull request directory
if: ${{ github.event_name == 'workflow_run' }}
uses: actions/checkout@v4
with:
ref: ${{ steps.pr-info-output.outputs.sha }}
submodules: recursive
- name: Upload repository
uses: actions/upload-artifact@v4
with:
name: repository
path: .
- name: Create comment
id: comment
if: ${{ github.event_name == 'workflow_run' }}
uses: actions/github-script@v7
with:
retries: 3
script: |
const url = "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}";
const sha = "${{ steps.pr-info-output.outputs.sha }}".substr(0, 7);
const body = `🔄 [Testing workflow #${{ github.run_attempt }}](${url}) of \`${sha}\` is running`;
const response = await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ steps.pr-info-output.outputs.number }},
body: body,
});
core.setOutput("comment_id", response.data.id);
flutter-integration:
name: Client integration test
needs: checkout
runs-on: ubuntu-22.04
env:
ODBC_CONNECTION_STRING: "Driver={ODBC Driver 18 for SQL Server};Server=localhost,1433;Uid=sa;Pwd=Password1234!;Encrypt=yes;TrustServerCertificate=yes;Connection Timeout=30;"
VNPAY_TMN_CODE: ${{ secrets.VNPAY_TMN_CODE }}
VNPAY_SECRET_KEY: ${{ secrets.VNPAY_SECRET_KEY }}
PORT: 8000
strategy:
fail-fast: false
matrix:
resolution: [375x667x24, 1024x768x24, 1920x1080x24]
steps:
- name: Download repository
uses: actions/download-artifact@v4
with:
name: repository
- name: Setup Flutter
uses: subosito/flutter-action@v2
with:
flutter-version: 3.24.3
channel: stable
- name: Install extra apt dependencies
run: |
sudo apt-get update
sudo apt-get install -y ninja-build libgtk-3-dev
- name: View Flutter status
run: |
flutter --version
flutter doctor -v
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: pip install -r dev-requirements.txt
- name: Install and run local SQL server
run: |
chmod +x scripts/sql-server-ubuntu-22.04.sh
scripts/sql-server-ubuntu-22.04.sh
- name: Install ODBC driver 18
run: |
chmod +x scripts/odbc.sh
scripts/odbc.sh
- name: Create sample data
run: python scripts/sample.py
- name: Start API server
run: |
uvicorn main:app --host 0.0.0.0 --port $PORT --log-level warning &
echo $! > /tmp/serverpid.txt
- name: Run integration tests
timeout-minutes: 30
working-directory: app/resident_manager
run: xvfb-run -e /dev/stdout --server-args="-screen 0 ${{ matrix.resolution }}" flutter test integration_test
- name: Stop API server
run: |
kill $(cat /tmp/serverpid.txt)
sleep 5
- name: Collect coverage data
run: coverage combine
- name: Report coverage
run: coverage report -m
- name: Rename coverage report
run: mv .coverage .coverage.flutter-integration
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-flutter-integration-${{ matrix.resolution }}
path: .coverage.flutter-integration
include-hidden-files: true
performance-test:
name: Server performance test
needs: checkout
runs-on: ubuntu-22.04
env:
ODBC_CONNECTION_STRING: "Driver={ODBC Driver 18 for SQL Server};Server=localhost,1433;Uid=sa;Pwd=Password1234!;Encrypt=yes;TrustServerCertificate=yes;Connection Timeout=30;"
VNPAY_TMN_CODE: ${{ secrets.VNPAY_TMN_CODE }}
VNPAY_SECRET_KEY: ${{ secrets.VNPAY_SECRET_KEY }}
PORT: 8000
steps:
- name: Download repository
uses: actions/download-artifact@v4
with:
name: repository
- name: Install extra apt dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential libssl-dev
- name: Fetch cached wrk
id: wrk-cache
uses: actions/cache@v4
with:
key: wrk-ubuntu-latest-${{ hashFiles('extern/wrk') }}
path: extern/wrk/wrk
- name: Build wrk
if: ${{ steps.wrk-cache.outputs.cache-hit != 'true' }}
working-directory: extern/wrk
run: sudo make
- name: Copy wrk to /usr/local/bin
working-directory: extern/wrk
run: sudo cp wrk /usr/local/bin
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: pip install -r dev-requirements.txt
- name: Install and run local SQL server
run: |
chmod +x scripts/sql-server-ubuntu-22.04.sh
scripts/sql-server-ubuntu-22.04.sh
- name: Install ODBC driver 18
run: |
chmod +x scripts/odbc.sh
scripts/odbc.sh
- name: Create sample data
run: python scripts/sample.py
- name: Start API server
run: |
uvicorn main:app --host 0.0.0.0 --port $PORT --log-level warning --workers 12 &
echo $! > /tmp/serverpid.txt
sleep 5
- name: Measure performance
working-directory: scripts/wrk
run: |
config="-t 12 -c 100 -d 30s -R 10000"
command="wrk --script root.lua $config http://localhost:$PORT"
echo "$ $command" > $GITHUB_WORKSPACE/wrk-root.txt
$command | tee --append $GITHUB_WORKSPACE/wrk-root.txt
command="wrk --script api/v1/admin/login.lua $config http://localhost:$PORT/api/v1/admin/login"
echo "$ $command" > $GITHUB_WORKSPACE/wrk-api-v1-admin-login.txt
$command | tee --append $GITHUB_WORKSPACE/wrk-api-v1-admin-login.txt
command="wrk --script api/v1/login.lua $config http://localhost:$PORT/api/v1/login"
echo "$ $command" > $GITHUB_WORKSPACE/wrk-api-v1-login.txt
$command | tee --append $GITHUB_WORKSPACE/wrk-api-v1-login.txt
- name: Stop API server
run: |
kill $(cat /tmp/serverpid.txt)
sleep 5
- name: Upload performance report
uses: actions/upload-artifact@v4
with:
name: wrk
path: wrk-*.txt
python-coverage:
name: Combine coverage reports
needs: flutter-integration
runs-on: ubuntu-latest
steps:
- name: Download repository
uses: actions/download-artifact@v4
with:
name: repository
- name: Download coverage reports
uses: actions/download-artifact@v4
with:
pattern: coverage-*
path: .
merge-multiple: true
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install dependencies
run: pip install -r dev-requirements.txt
- name: Combine coverage reports
run: coverage combine
- name: Report coverage
run: coverage report -m
- name: Save coverage report
run: coverage report -m > textcov.txt
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-txt
path: textcov.txt
- name: Generate HTML coverage report
run: coverage html -d htmlcov
- name: Upload HTML coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-html
path: htmlcov
notification:
name: Comment in pull request
needs: [checkout, flutter-integration, python-coverage, performance-test]
if: ${{ always() && needs.checkout.result == 'success' && github.event_name == 'workflow_run' }}
runs-on: ubuntu-latest
steps:
- name: Download coverage report
if: ${{ needs.python-coverage.result == 'success' }}
uses: actions/download-artifact@v4
with:
name: coverage-txt
- name: Download performance report
if: ${{ needs.performance-test.result == 'success' }}
uses: actions/download-artifact@v4
with:
name: wrk
- name: Update initial comment
uses: actions/github-script@v7
with:
retries: 3
script: |
const fs = require("fs/promises");
const url = "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}";
const sha = "${{ needs.checkout.outputs.sha }}".substr(0, 7);
let body = null;
if (${{ needs.flutter-integration.result == 'success' }}) {
body = `🎉 [All tests #${{ github.run_attempt }}](${url}) of \`${sha}\` passed successfully.`;
if (${{ needs.python-coverage.result == 'success' }}) {
const coverage = await fs.readFile("textcov.txt", { encoding: "utf8" });
const wrapped = `\`\`\`\n${coverage}\`\`\``;
body += `\n<details>\n<summary>Coverage report</summary>\n\n${wrapped}\n\n</details>`;
}
if (${{ needs.performance-test.result == 'success' }}) {
const wrk_root = await fs.readFile("wrk-root.txt", { encoding: "utf8" });
const wrk_api_v1_admin_login = await fs.readFile("wrk-api-v1-admin-login.txt", { encoding: "utf8" });
const wrk_api_v1_login = await fs.readFile("wrk-api-v1-login.txt", { encoding: "utf8" });
const reports = [
`- \`/\`\n\`\`\`\n${wrk_root}\`\`\``,
`- \`/api/v1/admin/login\`\n\`\`\`\n${wrk_api_v1_admin_login}\`\`\``,
`- \`/api/v1/login\`\n\`\`\`\n${wrk_api_v1_login}\`\`\``,
];
const wrapped = reports.join("\n\n");
body += `\n<details>\n<summary>Performance report</summary>\n\n${wrapped}\n\n</details>`;
}
} else {
body = `❌ [One or more tests #${{ github.run_attempt }}](${url}) of \`${sha}\` failed.`;
}
body += "\n\n*Note that this workflow YAML is fetched from the `main` branch.*";
try {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ needs.checkout.outputs.comment_id }},
body: body,
});
} catch (error) {
core.warning(error);
core.warning("Unable to update initial comment, creating a new one.");
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ needs.checkout.outputs.number }},
body: body,
});
}