11name : Grade Assignment
22
33on :
4- pull_request :
4+ pull_request_target :
55 branches :
66 - main
77
@@ -10,45 +10,62 @@ jobs:
1010 runs-on : ubuntu-latest
1111 permissions :
1212 pull-requests : write
13+ issues : write
1314
1415 steps :
1516 - name : Checkout code
1617 uses : actions/checkout@v4
18+ with :
19+ ref : ${{ github.event.pull_request.head.sha }}
1720
1821 - name : Setup Node.js
1922 uses : actions/setup-node@v4
2023 with :
21- node-version : " 24 "
24+ node-version : " lts/* "
2225
2326 - name : Run tests
24- id : test
25- run : |
26- node .hyf/tester.js > test-output.txt 2>&1
27- echo "exit_code=$?" >> $GITHUB_OUTPUT
28- continue-on-error : true
27+ working-directory : .hyf
28+ run : node tester.js > test-output.txt 2>&1
2929
3030 - name : Read test output
3131 id : output
3232 run : |
33- OUTPUT=$(cat test-output.txt)
33+ OUTPUT=$(cat .hyf/ test-output.txt)
3434 echo "results<<EOF" >> $GITHUB_OUTPUT
3535 echo "$OUTPUT" >> $GITHUB_OUTPUT
3636 echo "EOF" >> $GITHUB_OUTPUT
3737
38+ - name : Read score
39+ id : score
40+ run : |
41+ SCORE=$(jq -r '.score' .hyf/score.json)
42+ PASS=$(jq -r '.pass' .hyf/score.json)
43+ PASSING_SCORE=$(jq -r '.passingScore' .hyf/score.json)
44+ echo "score=$SCORE" >> $GITHUB_OUTPUT
45+ echo "pass=$PASS" >> $GITHUB_OUTPUT
46+ echo "passing_score=$PASSING_SCORE" >> $GITHUB_OUTPUT
47+
3848 - name : Comment PR
3949 uses : actions/github-script@v7
4050 with :
4151 script : |
4252 const output = `${{ steps.output.outputs.results }}`;
43- const exitCode = '${{ steps.test.outputs.exit_code }}';
44- const status = exitCode === '0' ? '✅ Passed' : '❌ Failed';
53+ const score = '${{ steps.score.outputs.score }}';
54+ const pass = '${{ steps.score.outputs.pass }}' === 'true';
55+ const passingScore = '${{ steps.score.outputs.passing_score }}';
56+ const status = pass ? '✅ Passed' : '❌ Failed';
4557 github.rest.issues.createComment({
4658 issue_number: context.issue.number,
4759 owner: context.repo.owner,
4860 repo: context.repo.repo,
49- body: `## Assignment Grade ${status}\n\n\`\`\`\n${output}\n\`\`\``
61+ body: `## !Assignment score ${score} / 100\n\n
62+ **Score:** ${score}/${passingScore}\n\n
63+ <details>\n
64+ <summary>Test Details</summary>\n\n
65+ \`\`\`\n${output}\n\`\`\`\n\n
66+ </details>`
5067 });
5168
5269 - name : Fail if tests failed
53- if : steps.test .outputs.exit_code != '0 '
70+ if : steps.score .outputs.pass != 'true '
5471 run : exit 1
0 commit comments