forked from jwentong/wireless-coding-equalization-exp
-
Notifications
You must be signed in to change notification settings - Fork 0
146 lines (131 loc) · 4.21 KB
/
grading.yml
File metadata and controls
146 lines (131 loc) · 4.21 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
name: 自动评分系统
on:
pull_request_target:
types: [opened, synchronize, reopened]
push:
branches:
- main
workflow_dispatch:
permissions:
contents: read
pull-requests: write
issues: write
jobs:
grading:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: 检出代码
uses: actions/checkout@v4.2.2
with:
ref: ${{ github.event.pull_request.head.sha || github.sha }}
- name: 设置Python环境
uses: actions/setup-python@v5.6.0
with:
python-version: '3.11'
- name: 安装依赖
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: 运行环境测试
continue-on-error: true
run: python src/test_environment.py
- name: 运行Part 1测试
continue-on-error: true
run: |
python -m pytest grading/test_part1_coding.py -v --tb=short > part1_result.txt 2>&1
cat part1_result.txt
- name: 运行Part 2测试
continue-on-error: true
run: |
python -m pytest grading/test_part2_equalization.py -v --tb=short > part2_result.txt 2>&1
cat part2_result.txt
- name: 检查实验报告
continue-on-error: true
run: |
python grading/check_report.py > report_result.txt 2>&1
cat report_result.txt
- name: 代码质量检查
continue-on-error: true
run: |
python -m pylint src/part1_channel_coding.py src/part2_equalization.py --score=y > pylint_result.txt 2>&1 || true
cat pylint_result.txt
- name: 计算总评分
run: |
python grading/calculate_grade.py > grade_result.txt 2>&1
cat grade_result.txt
- name: 上传评分报告
if: always()
uses: actions/upload-artifact@v4.6.2
with:
name: grading-report-${{ github.event.pull_request.user.login || github.actor }}
if-no-files-found: warn
path: |
grade_report.json
grade_result.txt
part1_result.txt
part2_result.txt
report_result.txt
pylint_result.txt
results/*.png
- name: 写入评分摘要
if: always()
run: |
echo "## 🤖 自动评分结果" >> $GITHUB_STEP_SUMMARY
if [ -f grade_result.txt ]; then
echo '```' >> $GITHUB_STEP_SUMMARY
cat grade_result.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
else
echo "评分报告未生成,请查看前序步骤日志。" >> $GITHUB_STEP_SUMMARY
fi
- name: 评论PR
if: github.event_name == 'pull_request_target'
continue-on-error: true
uses: actions/github-script@v7.0.1
with:
script: |
const fs = require('fs');
const readFile = (path, maxLength) => {
try {
return fs.readFileSync(path, 'utf8').substring(0, maxLength);
} catch (error) {
return `${path} 未生成,请查看 Actions 日志。`;
}
};
const student = context.payload.pull_request.user.login;
const comment = [
'## 🤖 自动评分结果',
'',
`**提交者**: @${student}`,
'',
'```',
readFile('grade_result.txt', 4000),
'```',
'',
'<details><summary>Part 1 测试详情</summary>',
'',
'```',
readFile('part1_result.txt', 2000),
'```',
'</details>',
'',
'<details><summary>Part 2 测试详情</summary>',
'',
'```',
readFile('part2_result.txt', 2000),
'```',
'</details>',
'',
'完整评分报告可在 Actions Artifacts 中下载。'
].join('\n');
try {
await github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: comment
});
} catch (error) {
core.warning(`PR评论失败:${error.message}。评分结果已写入 Actions Summary,并上传到 Artifacts。`);
}