Skip to content

Commit d090ecc

Browse files
committed
Merge branch 'main' into main
2 parents b817442 + 47453fc commit d090ecc

File tree

4 files changed

+42
-21
lines changed

4 files changed

+42
-21
lines changed
Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Grade Assignment
22

33
on:
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

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
Thumbs.db
44
[Dd]esktop.ini
55

6+
# hyf
7+
.hyf/score.json
8+
69
# Editor and IDE settings
710
.vscode/
811
.idea/

.hyf/tester.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { task1 } from './task1.js';
22
import { task2 } from './task2.js';
3+
import fs from 'fs/promises';
34

45
const main = async () => {
56
console.log('======================= Task 1 =======================');
@@ -10,18 +11,18 @@ const main = async () => {
1011

1112
console.log('\n======================= Summary =======================');
1213
const totalScore = Math.min(100, Math.round(score1 * 0.7 + score2 * 0.3));
13-
const minPassingScore = 70;
14+
const passingScore = 70;
1415
console.log(`- Task 1 Score: ${score1}%`);
1516
console.log(`- Task 2 Score: ${score2}%`);
1617
console.log(`Total Score: ${totalScore}%`);
17-
console.log(`Min passing score: ${minPassingScore}%`);
18+
console.log(`Min passing score: ${passingScore}%`);
19+
const results = {
20+
score: totalScore,
21+
pass: totalScore >= passingScore,
22+
passingScore: passingScore
23+
};
1824

19-
20-
if (totalScore > 70) {
21-
process.exit(0);
22-
} else {
23-
process.exit(1);
24-
}
25+
await fs.writeFile('score.json', JSON.stringify(results, null, 2));
2526
}
2627

2728
try {

task-1/setup.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# Write your code here
2-
echo "JavaScript works?"
2+
echo "JavaScript works?s"

0 commit comments

Comments
 (0)