generated from kappsegla/classroom
-
Notifications
You must be signed in to change notification settings - Fork 68
227 lines (199 loc) · 7.29 KB
/
classroom.yml
File metadata and controls
227 lines (199 loc) · 7.29 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
216
217
218
219
220
221
222
223
224
225
226
227
name: Autograding Tests
on:
push:
branches:
- main
repository_dispatch:
concurrency:
group: autograding-${{ github.ref }}
cancel-in-progress: true
permissions:
checks: write
actions: read
contents: read
pull-requests: write
jobs:
run-autograding-tests:
name: AI-Powered Feedback and Autograding
runs-on: ubuntu-latest
env:
OPENROUTER_MODEL: ${{ vars.OPENROUTER_MODEL }}
SYSTEM_PROMPT: ${{ vars.SYSTEM_PROMPT }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Read assignment instructions
id: instructions
run: |
# Reads the content of the README.md file into an output variable.
# The `EOF` marker is used to handle multi-line file content.
echo "instructions=$(cat README.md | sed 's/\"/\\\"/g' | sed 's/$/\\n/' | tr -d '\n' | sed 's/\\n/\\\\n/g')" >> $GITHUB_OUTPUT
- name: Read source code
id: source_code
run: |
{
echo 'source_code<<EOF'
find src/main/java -type f -name "*.java" | while read -r file; do
echo "=== File: $file ==="
cat "$file"
echo
done
echo 'EOF'
} >> "$GITHUB_OUTPUT"
- name: Read test code
id: test_code
run: |
{
echo 'test_code<<EOF'
if [ -d "src/test/java" ]; then
find src/test/java -type f -name "*.java" | while read -r file; do
echo "=== File: $file ==="
cat "$file"
echo
done
else
echo "No test code found."
fi
echo 'EOF'
} >> "$GITHUB_OUTPUT"
- name: Generate AI Feedback
id: ai_feedback
run: |
# This step sends the collected data to the OpenRouter API.
INSTRUCTIONS=$(jq -Rs . <<'EOF'
${{ steps.instructions.outputs.instructions }}
EOF
)
SOURCE_CODE=$(jq -Rs . <<'EOF'
${{ steps.source_code.outputs.source_code }}
EOF
)
TEST_CODE=$(jq -Rs . <<'EOF'
${{ steps.test_code.outputs.test_code }}
EOF
)
if [ -z "$INSTRUCTIONS" ] || [ -z "$SOURCE_CODE" ] || [ -z "$TEST_CODE" ]; then
echo "Error: One or more required variables are not set."
exit 1
fi
# Assigning to USER_CONTENT with variable expansion
PAYLOAD="Please provide feedback on the following Java assignment.
--- Assignment Instructions ---
${INSTRUCTIONS}
--- Source files ---
${SOURCE_CODE}
--- Test files ---
${TEST_CODE}"
JSON_CONTENT=$(jq -n \
--argjson model "$OPENROUTER_MODEL" \
--arg system_prompt "$SYSTEM_PROMPT" \
--arg payload "$PAYLOAD" \
'{
models: $model,
messages: [
{role: "system", content: $system_prompt},
{role: "user", content: $payload}
]
}')
echo "$JSON_CONTENT"
API_RESPONSE=$(echo "$JSON_CONTENT" | curl https://openrouter.ai/api/v1/chat/completions \
-H "Authorization: Bearer ${{ secrets.OPENROUTER_API_KEY }}" \
-H "Content-Type: application/json" \
-d @-)
echo "$API_RESPONSE"
FEEDBACK_CONTENT=$(echo "$API_RESPONSE" | jq -r '.choices[0].message.content')
echo "feedback<<EOF" >> $GITHUB_OUTPUT
echo "$FEEDBACK_CONTENT" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Post Feedback as PR Comment ✍️
uses: actions/github-script@v7
env:
FEEDBACK_BODY: ${{ steps.ai_feedback.outputs.feedback }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { owner, repo } = context.repo;
const targetTitle = "Feedback";
const signature = "🤖 AI Feedback";
const { data: pullRequests } = await github.rest.pulls.list({
owner,
repo,
state: "open",
per_page: 100
});
const matchingPR = pullRequests.find(pr => pr.title.trim().toLowerCase() === targetTitle.toLowerCase());
if (!matchingPR) {
throw new Error(`No open pull request found with title '${targetTitle}'`);
}
const prNumber = matchingPR.number;
const { data: comments } = await github.rest.issues.listComments({
owner,
repo,
issue_number: prNumber,
per_page: 100
});
const existing = comments.find(c =>
c.user?.login === "github-actions[bot]" &&
c.body?.includes(signature)
);
const timestamp = new Date().toISOString();
const newEntry = `🕒 _Posted on ${timestamp}_\n\n${process.env.FEEDBACK_BODY}\n\n---\n`;
if (existing) {
// Extract previous entries and wrap them in a collapsible block
const previousContent = existing.body.replace(/^### 🤖 AI Feedback\s*/, '').trim();
const collapsed = `<details><summary>Previous Feedback</summary>\n\n${previousContent}\n</details>`;
const updatedBody = `### ${signature}\n\n${newEntry}${collapsed}`;
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existing.id,
body: updatedBody
});
console.log(`🔄 Updated existing comment on PR #${prNumber}`);
} else {
const body = `### ${signature}\n\n${newEntry}`;
await github.rest.issues.createComment({
owner,
repo,
issue_number: prNumber,
body
});
console.log(`🆕 Posted new comment on PR #${prNumber}`);
}
- name: Set up Java 25
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '25'
- name: Compilation Check
id: compilation-check
uses: classroom-resources/autograding-command-grader@v1
with:
test-name: Compilation Check
command: mvn -ntp compile
timeout: 10
max-score: 1
- name: Basic Tests
id: basic-tests
uses: classroom-resources/autograding-command-grader@v1
with:
test-name: Basic Tests
command: mvn -ntp test -Dtest=BasicTest
timeout: 10
max-score: 1
- name: Edge Case Tests
id: edge-case-tests
uses: classroom-resources/autograding-command-grader@v1
with:
test-name: Edge Case Tests
command: mvn -ntp test -Dtest=EdgeCaseTest
timeout: 10
max-score: 1
- name: Autograding Reporter
uses: classroom-resources/autograding-grading-reporter@v1
env:
COMPILATION-CHECK_RESULTS: "${{steps.compilation-check.outputs.result}}"
BASIC-TESTS_RESULTS: "${{steps.basic-tests.outputs.result}}"
EDGE-CASE-TESTS_RESULTS: "${{steps.edge-case-tests.outputs.result}}"
with:
runners: compilation-check,basic-tests,edge-case-tests