generated from LearningInfiniTensor/exam-grading
-
Notifications
You must be signed in to change notification settings - Fork 0
532 lines (478 loc) · 18 KB
/
test.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
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
name: GitHub Classroom Workflow
on:
push:
branches: [ main ]
paths-ignore:
- 'README.md'
pull_request:
branches: [ main ]
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
TZ: Asia/Shanghai # 设置时区
ENCODED_API_URL: "aHR0cHM6Ly9hcGkubGVhcm5pbmdjYW1wLmNuL3dlYi9hcGkvY291cnNlUmFuay9jcmVhdGVCeVRoaXJk"
jobs:
initialize:
name: Initialize Submodules and Check for Experiments
runs-on: ubuntu-latest
outputs:
run_rustlings: ${{ steps.check.outputs.run_rustlings }}
run_cxx: ${{ steps.check.outputs.run_cxx }}
run_test: ${{ steps.check.outputs.run_test }}
api_url: ${{ steps.decode_api_url.outputs.url }}
<<<<<<< HEAD
=======
run_project1: ${{ steps.check.outputs.run_project1 }}
run_project2: ${{ steps.check.outputs.run_project2 }}
>>>>>>> template/main
steps:
- uses: actions/checkout@v3
with:
submodules: recursive # 初始化和更新子模块
- name: Decode API URL
id: decode_api_url
run: |
echo "url=$(echo "$ENCODED_API_URL" | base64 --decode)" >> "$GITHUB_OUTPUT"
- name: Check for Rustlings, C++ Experiments and Other Submodules
id: check
run: |
if [ -d "rustlings" ]; then
echo "::set-output name=run_rustlings::true"
else
echo "::set-output name=run_rustlings::false"
fi
if [ -d "learning-cxx" ]; then
echo "::set-output name=run_cxx::true"
else
echo "::set-output name=run_cxx::false"
fi
if [ -d "exams" ]; then
echo "::set-output name=run_test::true"
else
echo "::set-output name=run_test::false"
fi
<<<<<<< HEAD
=======
if [ -d "TinyInfiniTensor" ]; then
echo "::set-output name=run_project1::true"
else
echo "::set-output name=run_project1::false"
fi
if [ -d "learning-lm-rs" ]; then
echo "::set-output name=run_project2::true"
else
echo "::set-output name=run_project2::false"
fi
>>>>>>> template/main
rustlings:
name: Rustlings Autograding
needs: initialize
if: ${{ needs.initialize.outputs.run_rustlings == 'true' }}
runs-on: ubuntu-latest
outputs:
details: ${{ steps.autograding.outputs.details }}
points: ${{ steps.autograding.outputs.points}}
env:
API_URL: ${{ needs.initialize.outputs.api_url }}
steps:
- uses: actions/checkout@v3
with:
submodules: 'true'
- name: Set up Rust environment
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: Install rustlings
run: |
cargo install --force rustlings
rustlings --version
- name: Copy exercises directory to project root
run: cp -r rustlings/exercises .
- name: Run tests for rustlings
run: cargo test --test cicv --verbose
continue-on-error: true
- uses: yfblock/os-autograding@master
id: autograding
with:
outputFile: .github/result/rust_result.json
- name: Generate summary JSON for Rustlings
run: |
outfile=".github/result/rust_result.json"
summary_file=".github/result/rustlings_summary.json"
# 提取需要的值
total_exercations=$(jq '.statistics.total_exercations' $outfile)
total_succeeds=$(jq '.statistics.total_succeeds' $outfile)
github_user="${{ github.actor }}"
# 生成新的 JSON 内容
new_json=$(jq -n \
--arg channel "github" \
--argjson courseId 1700 \
--arg ext "aaa" \
--arg name "$github_user" \
--argjson score "$total_succeeds" \
--argjson totalScore "$total_exercations" \
'{channel: $channel, courseId: $courseId, ext: $ext, name: $name, score: $score, totalScore: $totalScore}')
# 保存新的 JSON 文件
echo "$new_json" > $summary_file
# 打印新的 JSON 文件到终端
cat $summary_file
- name: Post summary JSON to remote API
run: |
summary_file=".github/result/rustlings_summary.json"
# 发送 POST 请求
curl -X POST "$API_URL" \
-H "accept: application/json;charset=utf-8" \
-H "Content-Type: application/json" \
-d "$(cat $summary_file)" \
-v
cxx:
name: C++ Autograding
needs: initialize
if: ${{ needs.initialize.outputs.run_cxx == 'true' }}
runs-on: ubuntu-latest
outputs:
details: ${{ steps.autograding.outputs.details }}
points: ${{ steps.autograding.outputs.points}}
env:
API_URL: ${{ needs.initialize.outputs.api_url }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
submodules: 'true'
- name: Install xmake
uses: xmake-io/github-action-setup-xmake@v1
with:
xmake-version: latest
- name: Run tests and save output
run: |
(xmake && xmake run summary) | tee test_output.txt
working-directory: learning-cxx
continue-on-error: true
- name: Parse test results and generate JSON for C++
run: |
outfile="test_output.txt"
summary_file="./../.github/result/cxx_result.json"
# 获取最后一行信息并进行处理
info_line=$(tail -n 1 $outfile | sed 's/\x1b\[[0-9;]*m//g')
# 提取通过题数和总题目数量
total_succeeds=$(echo $info_line | cut -d' ' -f1 | cut -d'/' -f1)
total_exercises=$(echo $info_line | cut -d' ' -f1 | cut -d'/' -f2)
# 提取题目状态字符串
status_string=$(echo $info_line | cut -d' ' -f2 | tr -d '[]')
# 初始化总失败数
total_failures=$((total_exercises - total_succeeds))
# 遍历状态字符串并更新 JSON 中的 result 字段
for (( i=0; i<${#status_string}; i++ )); do
exercise_name=$(printf "exercise%02d" $i)
current_char=${status_string:$i:1}
if [[ $current_char == "#" ]]; then
result="true"
else
result="false"
fi
# 直接修改 JSON 文件中的相应字段
jq --arg name "$exercise_name" --arg result "$result" '.exercises |= map(if .name == $name then .result = ($result | test("true")) else . end)' $summary_file > tmp.json && mv tmp.json $summary_file
done
# 更新统计信息
jq --argjson succeeds "$total_succeeds" --argjson failures "$total_failures" '.statistics.total_succeeds = $succeeds | .statistics.total_failures = $failures' $summary_file > tmp.json && mv tmp.json $summary_file
# 打印新的 JSON 文件到终端
cat $summary_file
working-directory: learning-cxx
continue-on-error: true
- uses: yfblock/os-autograding@master
id: autograding
with:
outputFile: .github/result/cxx_result.json
- name: Generate summary JSON for CXX
run: |
outfile=".github/result/cxx_result.json"
summary_file=".github/result/cxx_summary.json"
# 提取需要的值
total_exercations=$(jq '.statistics.total_exercations' $outfile)
total_succeeds=$(jq '.statistics.total_succeeds' $outfile)
cxx_user="${{ github.actor }}"
# 生成新的 JSON 内容
new_json=$(jq -n \
--arg channel "github" \
--argjson courseId 1699 \
--arg ext "aaa" \
--arg name "$cxx_user" \
--argjson score "$total_succeeds" \
--argjson totalScore "$total_exercations" \
'{channel: $channel, courseId: $courseId, ext: $ext, name: $name, score: $score, totalScore: $totalScore}')
# 保存新的 JSON 文件
echo "$new_json" > $summary_file
# 打印新的 JSON 文件到终端
cat $summary_file
- name: Post summary JSON to remote API
run: |
summary_file=".github/result/cxx_summary.json"
# 发送 POST 请求
curl -X POST "$API_URL" \
-H "accept: application/json;charset=utf-8" \
-H "Content-Type: application/json" \
-d "$(cat $summary_file)" \
-v
test:
name: Test Job for Other Submodules
needs: initialize
if: ${{ needs.initialize.outputs.run_test == 'true' }}
runs-on: ubuntu-latest
env:
API_URL: ${{ needs.initialize.outputs.api_url }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
submodules: 'true'
- name: Post summary JSON to remote API
run: |
curl -X POST "$API_URL" \
-H "accept: application/json;charset=utf-8" \
-H "Content-Type: application/json" \
-d '{
"channel": "github",
"courseId": 1698,
"ext": "aaa",
"name": "${{ github.actor }}",
"score": 1,
"totalScore": 23
}' \
-v
<<<<<<< HEAD
=======
TinyInfiniTensor:
name: TinyInfiniTensor Autograding
needs: initialize
if: ${{ needs.initialize.outputs.run_project1 == 'true' }}
runs-on: ubuntu-latest
outputs:
details: ${{ steps.autograding.outputs.details }}
points: ${{ steps.autograding.outputs.points}}
env:
API_URL: ${{ needs.initialize.outputs.api_url }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
submodules: recursive
- name: Build TinyInfiniTensor
run: |
make
working-directory: TinyInfiniTensor
continue-on-error: false
- name: Run tests for TinyInfiniTensor
id: run_tests
run: |
make test-cpp | tee test_output.txt
working-directory: TinyInfiniTensor
continue-on-error: true
- name: Parse test results and generate JSON for TinyInfiniTensor
run: |
test_output="test_output.txt"
json_file="./../.github/result/TinyInfiniTensor_result.json"
test_list=(
"test_allocator"
"test_graph"
"test_cast"
"test_clip"
"test_concat"
"test_element_wise"
"test_matmul"
"test_transpose"
"test_nativecpu_concat"
"test_nativecpu_elementwise"
"test_nativecpu_transpose"
)
# 初始化计数器
total_exercations=0
total_succeeds=0
total_failures=0
exercises_json="[]"
# 解析输出
while read -r line; do
if [[ "$line" =~ ^[0-9]+/[0-9]+[[:space:]]+Test[[:space:]]+#[0-9]+:[[:space:]]+([a-zA-Z_]+).+(Passed|Failed).*$ ]]; then
test_name="${BASH_REMATCH[1]}"
test_result="${BASH_REMATCH[2]}"
for element in "${test_list[@]}"; do
if [[ "$element" == "$test_name" ]]; then
# 计数
total_exercations=$((total_exercations + 1))
if [[ $test_result == "Failed" ]]; then
exercises_json=$(echo "$exercises_json" | jq --arg name "$test_name" --argjson result false '. + [{name: $name, result: $result}]')
total_failures=$((total_failures + 1))
else
exercises_json=$(echo "$exercises_json" | jq --arg name "$test_name" --argjson result true '. + [{name: $name, result: $result}]')
total_succeeds=$((total_succeeds + 1))
fi
fi
done
fi
done < "$test_output"
# 生成最终 JSON
final_json=$(jq -n \
--argjson exercises "$exercises_json" \
--arg user_name "null" \
--argjson total_exercations "$total_exercations" \
--argjson total_succeeds "$total_succeeds" \
--argjson total_failures "$total_failures" \
--argjson total_time 3 \
'{exercises: $exercises, user_name: $user_name, statistics: {total_exercations: $total_exercations, total_succeeds: $total_succeeds, total_failures: $total_failures, total_time: $total_time}}')
# 保存到 JSON 文件
echo "$final_json" > "$json_file"
# 打印新的 JSON 文件到终端
cat $json_file
working-directory: TinyInfiniTensor
continue-on-error: true
- uses: yfblock/os-autograding@master
id: autograding
with:
outputFile: .github/result/TinyInfiniTensor_result.json
- name: Generate summary JSON for TinyInfiniTensor
run: |
outfile=".github/result/TinyInfiniTensor_result.json"
summary_file=".github/result/TinyInfiniTensor_summary.json"
# 提取需要的值
total_exercations=$(jq '.statistics.total_exercations' $outfile)
total_succeeds=$(jq '.statistics.total_succeeds' $outfile)
pr1_user="${{ github.actor }}"
new_json=$(jq -n \
--arg channel "github" \
--argjson courseId 1701 \
--arg ext "aaa" \
--arg name "$pr1_user" \
--argjson score "$total_succeeds" \
--argjson totalScore "$total_exercations" \
'{channel: $channel, courseId: $courseId, ext: $ext, name: $name, score: $score, totalScore: $totalScore}')
echo "$new_json" > $summary_file
cat $summary_file
- name: Post summary JSON for TinyInfiniTensor
run: |
summary_file=".github/result/TinyInfiniTensor_summary.json"
curl -X POST "$API_URL" \
-H "accept: application/json;charset=utf-8" \
-H "Content-Type: application/json" \
-d "$(cat $summary_file)" \
-v
learning-lm-rs:
name: learning-lm-rs Autograding
needs: initialize
if: ${{ needs.initialize.outputs.run_project2 == 'true' }}
runs-on: ubuntu-latest
outputs:
details: ${{ steps.autograding.outputs.details }}
points: ${{ steps.autograding.outputs.points}}
env:
API_URL: ${{ needs.initialize.outputs.api_url }}
steps:
- uses: actions/checkout@v3
with:
submodules: 'true'
- name: Set up Rust environment for learning-lm-rs
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: Build learning-lm-rs
run: |
cargo build --verbose
working-directory: learning-lm-rs
continue-on-error: false
- name: Run tests for learning-lm-rs
id: run_tests
run: |
cargo test --verbose | tee test_output.txt
working-directory: learning-lm-rs
continue-on-error: true
- name: Parse test results and generate JSON for learning-lm-rs
run: |
test_output="test_output.txt"
json_file="./../.github/result/learning-lm-rs_result.json"
test_list=(
"model::test_mlp"
"operators::test_rms_norm"
"operators::test_matmul_transb"
"operators::test_silu"
"model::test_load_safetensors"
)
# 初始化计数器
total_exercations=0
total_succeeds=0
total_failures=0
exercises_json="["
# 从测试输出中提取测试结果
while IFS= read -r line; do
if [[ $line =~ test\ (.+)\ \.\.\.\ (FAILED|ok) ]]; then
test_name="${BASH_REMATCH[1]}"
test_result="${BASH_REMATCH[2]}"
for element in "${test_list[@]}"; do
if [[ "$element" == "$test_name" ]]; then
# 计数
total_exercations=$((total_exercations + 1))
if [[ $test_result == "FAILED" ]]; then
exercises_json+="$(jq -n --arg name "$test_name" --argjson result false '{name: $name, result: $result}'),"
total_failures=$((total_failures + 1))
else
exercises_json+="$(jq -n --arg name "$test_name" --argjson result true '{name: $name, result: $result}'),"
total_succeeds=$((total_succeeds + 1))
fi
fi
done
fi
done < "$test_output"
# 去掉最后一个逗号并闭合 JSON 数组
exercises_json="${exercises_json%,}]"
# 生成最终 JSON
final_json=$(jq -n \
--argjson exercises "$exercises_json" \
--arg user_name "null" \
--argjson total_exercations "$total_exercations" \
--argjson total_succeeds "$total_succeeds" \
--argjson total_failures "$total_failures" \
--argjson total_time 3 \
'{exercises: $exercises, user_name: $user_name, statistics: {total_exercations: $total_exercations, total_succeeds: $total_succeeds, total_failures: $total_failures, total_time: $total_time}}')
# 保存到 JSON 文件
echo "$final_json" > "$json_file"
# 打印新的 JSON 文件到终端
cat $json_file
working-directory: learning-lm-rs
continue-on-error: true
- uses: yfblock/os-autograding@master
id: autograding
with:
outputFile: .github/result/learning-lm-rs_result.json
- name: Generate summary JSON for learning-lm-rs
run: |
outfile=".github/result/learning-lm-rs_result.json"
summary_file=".github/result/learning-lm-rs_summary.json"
# 提取需要的值
total_exercations=$(jq '.statistics.total_exercations' $outfile)
total_succeeds=$(jq '.statistics.total_succeeds' $outfile)
pr2_user="${{ github.actor }}"
# 生成新的 JSON 内容
new_json=$(jq -n \
--arg channel "github" \
--argjson courseId 1703 \
--arg ext "aaa" \
--arg name "$pr2_user" \
--argjson score "$total_succeeds" \
--argjson totalScore "$total_exercations" \
'{channel: $channel, courseId: $courseId, ext: $ext, name: $name, score: $score, totalScore: $totalScore}')
# 保存新的 JSON 文件
echo "$new_json" > $summary_file
# 打印新的 JSON 文件到终端
cat $summary_file
- name: Post summary JSON for learning-lm-rs
run: |
summary_file=".github/result/learning-lm-rs_summary.json"
# 发送 POST 请求
curl -X POST "$API_URL" \
-H "accept: application/json;charset=utf-8" \
-H "Content-Type: application/json" \
-d "$(cat $summary_file)" \
-v
>>>>>>> template/main