-
Notifications
You must be signed in to change notification settings - Fork 0
154 lines (141 loc) · 4.9 KB
/
grader.yml
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
name: grader
on:
issues:
types: [opened, edited]
jobs:
grade:
runs-on: ubuntu-22.04
env:
CACHE_KEY: ppl-ocaml-env-lz4-20221001
IMAGE_PATH: ./ppl-ocaml-env.tar
COMPACTED_IMAGE_PATH: ./ppl-ocaml-env.tar.lz4
COMPACTED_IMAGE_URL: https://github.com/ZJU-PPL/ppl-ocaml-env/releases/download/20221001/ppl-ocaml-env.tar.lz4
steps:
- name: Early exit
if: ${{ contains(github.event.issue.body, '::early-exit::') }}
run: exit 1
- name: Get the code submitted
id: fetch-code
env:
TITLE: ${{ github.event.issue.title }}
CONTENT: ${{ github.event.issue.body }}
run: |
echo "$CONTENT" | sed -r -n "s/\[.*\]\((.*)\)/\1/p" > url
wget -O stu-code.tar.gz.pgp $(cat url | tr -d '\r\n')
echo "::set-output name=MD5::$(md5sum -t stu-code.tar.gz.pgp)"
rm url
- name: Checkout keys
uses: actions/checkout@v3
with:
repository: ZJU-PPL/graders
ref: key
token: ${{ secrets.GRADER_PAT }}
path: ./key/
- name: Decrypt the code
run: |
echo zjuppl | gpg2 --pinentry-mode loopback --passphrase-fd 0 --import ./key/key.asc
echo zjuppl | gpg2 --pinentry-mode loopback --passphrase-fd 0 -o stu-code.tar.gz --decrypt stu-code.tar.gz.pgp
mkdir -p ./src/stu/
tar xf stu-code.tar.gz --directory=./src/stu/
- name: Checkout the code of grader
uses: actions/checkout@v3
with:
repository: ZJU-PPL/graders
ref: lab-3
token: ${{ secrets.GRADER_PAT }}
path: ./src/grader/
- name: Make test script
run: |
cat <<EOT > run.sh
set -euxo pipefail
cp -r ./ ../work
cd ../work
cd ./stu
opam install . -y
cd ..
cd ./grader
timeout 10s dune exec grader
EOT
chmod +x run.sh
mv run.sh ./src/run.sh
- name: Try to use image cache
uses: actions/cache@v3
id: cache-env
with:
key: ${{ env.CACHE_KEY }}
path: ${{ env.COMPACTED_IMAGE_PATH }}
- name: Fetch compacted test image
if: ${{ steps.cache-env.outputs.cache-hit != 'true' }}
run: |
wget -O ${{ env.COMPACTED_IMAGE_PATH }} ${{ env.COMPACTED_IMAGE_URL }}
- name: Import test image
run: |
wget -O ./lz4 https://github.com/ZJU-PPL/ppl-ocaml-env/releases/download/20221001/lz4
chmod +x ./lz4
./lz4 -d -c ${{ env.COMPACTED_IMAGE_PATH }} | docker load
- name: Run the grader
id: grade-result
run: |
cat <<EOT > get_grade.py
import sys
found = False
for line in sys.stdin:
if line.rstrip('\r\n') == '===':
found = not found
continue
if found:
print(line.rstrip('\r\n'))
EOT
docker run -v ${{ github.workspace }}/src:/home/opam/src -w /home/opam/src ppl-ocaml-env:latest bash run.sh 2>&1 | tee run.log | python get_grade.py > result.txt
cat run.log
grep -F -x -q '===' run.log
- name: Set the result
id: final-result
uses: actions/github-script@v6
with:
result-encoding: string
script: |
let fs = require('fs');
return fs.readFileSync('./result.txt', { encoding:'utf8', flag:'r' });
- name: Feedback
uses: peter-evans/create-or-update-comment@v2
env:
RESULT: ${{ steps.final-result.outputs.result }}
with:
issue-number: ${{ github.event.issue.number }}
body: |
This is the test report of your code
```
${{ env.RESULT }}
```
- name: Get current timestamp
id: timestamp
run: echo "::set-output name=TS::$(date -u +'%Y-%m-%d_%H-%M-%S_%s')"
- name: Encode the score
id: encode
env:
USER: ${{ github.event.issue.user.login }}
TS: ${{ steps.timestamp.outputs.TS }}
CHKSUM: ${{ steps.fetch-code.outputs.MD5 }}
RESULT: ${{ steps.final-result.outputs.result }}
run: |
echo "user=$USER" > score.txt
echo "timestamp=$TS" >> score.txt
echo "checksum=$CHKSUM" >> score.txt
echo "result=$RESULT" >> score.txt
echo "submitted=$(cat ./stu-code.tar.gz.pgp)" >> score.txt
base64 score.txt > score.b64
- name: Archive the score
env:
USER: ${{ github.event.issue.user.login }}
TS: ${{ steps.timestamp.outputs.TS }}
run: |
echo -n '{ "message": "score archiver", "committer": { "name": "bot", "email": "[email protected]" }, "content": "' > data.json
echo -n "$(cat score.b64 | tr -d '\r\n')" >> data.json
echo -n '" }' >> data.json
curl \
-X PUT \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.ARCHIVER_PAT }}" \
https://api.github.com/repos/ZJU-PPL/scores/contents/lab-3.$TS.$USER.log \
--data-binary "@./data.json"