Skip to content

Commit 481ab34

Browse files
authored
feat: grader update challenge (#372)
1 parent 2be061b commit 481ab34

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Grader update challenge
2+
3+
on:
4+
push:
5+
paths:
6+
- "extension/packages/hardhat/test/**"
7+
branches:
8+
- "challenge-*"
9+
10+
jobs:
11+
notify-autograder:
12+
runs-on: ubuntu-latest
13+
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true)
14+
15+
steps:
16+
- name: Extract challenge ID from branch
17+
id: extract_challenge
18+
run: |
19+
# Get the branch name
20+
if [ "${{ github.event_name }}" = "pull_request" ]; then
21+
BRANCH_NAME="${{ github.event.pull_request.base.ref }}"
22+
else
23+
BRANCH_NAME="${{ github.ref_name }}"
24+
fi
25+
26+
echo "Branch name: $BRANCH_NAME"
27+
28+
# Use the full branch name as challenge ID (e.g., challenge-simple-nft-example)
29+
if [[ $BRANCH_NAME =~ ^challenge-.+$ ]]; then
30+
CHALLENGE_ID="$BRANCH_NAME"
31+
echo "challenge_id=$CHALLENGE_ID" >> $GITHUB_OUTPUT
32+
echo "Challenge ID: $CHALLENGE_ID"
33+
else
34+
echo "Branch name does not match challenge pattern: $BRANCH_NAME"
35+
exit 1
36+
fi
37+
38+
- name: Update test files on autograding server
39+
if: steps.extract_challenge.outputs.challenge_id != ''
40+
run: |
41+
CHALLENGE_ID="${{ steps.extract_challenge.outputs.challenge_id }}"
42+
43+
echo "Updating test files on autograding server for challenge: $CHALLENGE_ID"
44+
echo "Autograding server URL: ${{ secrets.AUTOGRADER_URL }}/install"
45+
46+
RESPONSE=$(curl -s -w "\n%{http_code}" -X POST \
47+
"${{ secrets.AUTOGRADER_URL }}/install" \
48+
-H "Content-Type: application/json" \
49+
-H "x-api-key: ${{ secrets.AUTOGRADER_API_KEY }}" \
50+
-d "{\"challengeId\": \"$CHALLENGE_ID\"}")
51+
52+
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
53+
RESPONSE_BODY=$(echo "$RESPONSE" | head -n -1)
54+
55+
echo "HTTP Status Code: $HTTP_CODE"
56+
echo "Response: $RESPONSE_BODY"
57+
58+
if [ "$HTTP_CODE" -eq 200 ]; then
59+
echo "✅ Successfully updated test files on autograding server for challenge $CHALLENGE_ID"
60+
else
61+
echo "❌ Failed to update test files on autograding server for challenge $CHALLENGE_ID (HTTP $HTTP_CODE)"
62+
exit 1
63+
fi
64+
65+
- name: Add summary
66+
if: always()
67+
run: |
68+
if [ "${{ steps.extract_challenge.outputs.challenge_id }}" != "" ]; then
69+
echo "## 🧪 Test Files Update" >> $GITHUB_STEP_SUMMARY
70+
echo "" >> $GITHUB_STEP_SUMMARY
71+
echo "**Challenge ID:** \`${{ steps.extract_challenge.outputs.challenge_id }}\`" >> $GITHUB_STEP_SUMMARY
72+
echo "**Branch:** \`${{ github.ref_name }}\`" >> $GITHUB_STEP_SUMMARY
73+
echo "**Autograding Server:** \`${{ secrets.AUTOGRADER_URL }}/install\`" >> $GITHUB_STEP_SUMMARY
74+
echo "" >> $GITHUB_STEP_SUMMARY
75+
if [ "${{ job.status }}" = "success" ]; then
76+
echo "✅ **Status:** Successfully updated test files on autograding server" >> $GITHUB_STEP_SUMMARY
77+
else
78+
echo "❌ **Status:** Failed to update test files on autograding server" >> $GITHUB_STEP_SUMMARY
79+
fi
80+
else
81+
echo "## 🧪 Test Files Update" >> $GITHUB_STEP_SUMMARY
82+
echo "" >> $GITHUB_STEP_SUMMARY
83+
echo "❌ **Status:** Could not extract challenge ID from branch" >> $GITHUB_STEP_SUMMARY
84+
fi

0 commit comments

Comments
 (0)