-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclassroom.yml
More file actions
209 lines (174 loc) · 8.12 KB
/
Copy pathclassroom.yml
File metadata and controls
209 lines (174 loc) · 8.12 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
name: GitHub Classroom Workflow
on: [push, pull_request]
jobs:
setup:
name: Loading data
runs-on: ubuntu-22.04
outputs:
matrix: ${{ steps.load.outputs.matrix }}
steps:
- uses: actions/checkout@v4
- id: load
name: Load data
run: |
file_datetime=$(date --date="$(grep -P '^.+\d\d\d\d$' ScoresCodingTotal.txt | tail -1 )" +"%Y%m%d%H%M%S")
current_timestamp=$(date -d -30min +"%Y%m%d%H%M%S")
echo "Last grading: $file_datetime"
echo "Current time: $current_timestamp"
if [[ "$file_datetime" =~ ^[0-9]{14}$ && ! "$file_datetime" =~ ^[0-9]{8}000000$ ]]; then
if [ "$current_timestamp" -le "$file_datetime" ]; then
echo "You are submitting too frequently."
echo "The auto grader does not work this way."
echo "Please do not abuse it."
echo "Ignore Submission."
gh run cancel ${{ github.run_id }} --repo ${{ github.repository }} --force
exit 1
fi
fi
# Read 'config.json' file
data=$(cat .github/workflows/config.json | tr '\n' ' ' | tr '\r' ' ')
echo "matrix=$data" >> $GITHUB_OUTPUT
testing:
name: Grading Q${{ matrix.q_num }}
needs: setup
continue-on-error: true
runs-on: ubuntu-22.04
timeout-minutes: 3
strategy:
matrix:
q_num: ${{ fromJSON(needs.setup.outputs.matrix).q_nums }}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
repository: ${{ fromJSON(needs.setup.outputs.matrix).grader_repo }}
path: 'coding_grader'
- name: Normalize Bazel compatibility
run: |
echo "8.4.2" > .bazelversion
python3 - <<'PY'
import re
from pathlib import Path
RULES_CC_LOAD = 'load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")'
CC_RULES = ("cc_binary(", "cc_library(", "cc_test(")
CC_LIBRARY_BLOCK = re.compile(r'cc_library\(\n.*?^\)', flags=re.MULTILINE | re.DOTALL)
def ensure_cpplib_alwayslink(text):
def add_alwayslink(match):
block = match.group(0)
if not re.search(r'name\s*=\s*"CPPLib"', block) or 'alwayslink' in block:
return block
lines = block.splitlines(keepends=True)
insert_at = next((i for i, line in enumerate(lines) if 'visibility' in line), len(lines) - 1)
lines.insert(insert_at, ' alwayslink = True,\n')
return ''.join(lines)
return CC_LIBRARY_BLOCK.sub(add_alwayslink, text)
def set_bazel_dep(text, dep_name, replacement):
dep_pattern = re.compile(
r'\n?bazel_dep\(\s*name\s*=\s*"' + re.escape(dep_name) + r'".*?\)\s*\n?',
flags=re.DOTALL,
)
text = dep_pattern.sub('\n', text)
return text.rstrip() + '\n' + replacement + '\n'
def normalize_module(root):
module_file = root / "MODULE.bazel"
if not module_file.exists():
return
text = module_file.read_text()
text = set_bazel_dep(text, "rules_cc", 'bazel_dep(name = "rules_cc", version = "0.2.8")')
text = set_bazel_dep(
text,
"googletest",
'bazel_dep(name = "googletest", version = "1.17.0.bcr.2", repo_name = "com_google_googletest")',
)
module_file.write_text(text)
def normalize_build(build_file):
text = build_file.read_text()
if not any(rule in text for rule in CC_RULES):
return
if "@rules_cc//cc:defs.bzl" in text:
text = re.sub(
r'^load\("@rules_cc//cc:defs\.bzl".*\)\n\n?',
RULES_CC_LOAD + "\n\n",
text,
count=1,
flags=re.MULTILINE)
else:
text = RULES_CC_LOAD + "\n\n" + text
text = text.replace('@googletest//', '@com_google_googletest//')
text = ensure_cpplib_alwayslink(text)
build_file.write_text(text)
root = Path(".")
normalize_module(root)
for pattern in ("files/*/BUILD", "coding_grader/*/BUILD"):
for build_file in root.glob(pattern):
normalize_build(build_file)
PY
- name: Generate high-precision timestamp
run: echo "TIMESTAMP=$(date +%Y%m%d-%H%M%S-%3N)" >> $GITHUB_ENV
- name: Clear previous test result
if: always()
run: echo "" > Q${{ matrix.q_num }}res_.txt
- name: Test Q${{ matrix.q_num }}
if: always()
run: |
cp files/${{ matrix.q_num }}/q.cc coding_grader/${{ matrix.q_num }}/ || echo "No q.h found, skipping..."
echo "--------- Student Test ---------"
bazel run --config=asan --enable_workspace --ui_event_filters=-info,-stdout,-stderr //files/${{ matrix.q_num }}:student_test
if [ $? -ne 0 ] ; then exit 1; fi
echo "--------- Grader Test ---------"
bazel run --config=asan --enable_workspace --ui_event_filters=-info,-stdout,-stderr //coding_grader/${{ matrix.q_num }}:grader_test 2>&1 | tee Q${{ matrix.q_num }}res.txt
grep "OK" Q${{ matrix.q_num }}res.txt > Q${{ matrix.q_num }}res_.txt
- name: Delete existing artifact (if any)
run: |
ARTIFACT_NAME="Q${{ matrix.q_num }}res_.txt"
RESPONSE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/actions/runs/${{ github.run_id }}/artifacts")
ARTIFACT_ID=$(echo "$RESPONSE" | jq -r --arg name "$ARTIFACT_NAME" '.artifacts | select(.!=null) | map(select(.name==$name)) | .[0].id // empty')
if [[ -n "$ARTIFACT_ID" && "$ARTIFACT_ID" != "null" ]]; then
echo "Deleting existing artifact: $ARTIFACT_NAME (ID: $ARTIFACT_ID)"
curl -X DELETE -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts/$ARTIFACT_ID"
else
echo "No existing artifact found with name: $ARTIFACT_NAME"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload result for Q${{ matrix.q_num }}
if: always()
uses: actions/upload-artifact@v4
with:
name: Q${{ matrix.q_num }}res_.txt
path: Q${{ matrix.q_num }}res_.txt
retention-days: 1
collecting-result:
name: Collecting result
needs: [testing, setup]
runs-on: ubuntu-22.04
timeout-minutes: 3
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v4
with:
repository: 'ee538/AutoGradingScript'
path: 'grading_script'
- uses: actions/checkout@v4
with:
repository: ${{ fromJSON(needs.setup.outputs.matrix).grader_repo }}
path: 'coding_grader'
- name: Download all subscore artifacts
uses: actions/download-artifact@v4
with:
path: downloaded-subscores
- name: Organize the total score (coding questions)
if: always()
run: |
mkdir -p grades
mv downloaded-subscores/*/* grades/
python grading_script/coding_grades_total.py 2>&1 | tee ScoresCodingTotal.txt
TZ='America/Los_Angeles' date >> ScoresCodingTotal.txt
rm -rf grades coding_grader
git config --global user.email "ee538.autograder@gmail.com"
git config --global user.name "AutograderEE538"
git add ScoresCodingTotal.txt
git commit -m "Add autograding results"
git push origin HEAD:main -f