-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run
executable file
·155 lines (138 loc) · 6.36 KB
/
run
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
#!/bin/sh
set -u
config=$(cat -)
file=$(echo "$config" | jq -r '."source"')
resources=$(echo "$config" | jq -r '."resources"')
workdir=$(echo "$config" | jq -r '."workdir"')
language=$(echo "$config" | jq -r '."natural_language"')
judge_file="$resources/judge.json"
hadolint_args=""
for filename in .hadolint.yml .hadolint.yaml hadolint.yml hadolint.yaml
do
filename="$resources/$filename"
if [ -f "$filename" ]; then
hadolint_args="--config=$filename"
break
fi
done
title="Docker"
if [ "$language" = "nl" ]; then
empty="Lege oplossing"
evaluator_fail="Evaluator is gestopt met errors"
linter_fail="Linter is gestopt met errors"
build_fail="Docker build is gefaald"
file_not_found="Bestand is niet gevonden"
dir_not_found="Folder is niet gevonden"
no_match="Geen overeenkomst met regex"
file_check="Bestaan van bestand controleren"
file_content="Inhoud van bestand controleren"
file_regex="Inhoud van bestand controleren met behulp van reguliere expressie"
directory_check="Bestaan van folder controleren"
else
empty="Empty submission"
evaluator_fail="Evaluator exited with errors"
linter_fail="Linter exited with errors"
build_fail="Docker build failed"
file_not_found="File not found"
dir_not_found="Directory not found"
no_match="Didn't match regex"
file_check="Checking file existence"
file_content="Checking file content"
file_regex="Matching file content using regular expression"
directory_check="Checking directory existence"
fi
echo '{ "command": "start-judgement" }'
echo "{ \"command\": \"start-tab\", \"title\": \"$title\" }"
if [ -s "$file" ]; then
if [ -f "$judge_file" ]; then
if ! dodona-containerfile-evaluator --config "$judge_file" "$file"; then
echo "{ \"command\": \"escalate-status\", \"status\": { \"enum\": \"wrong\", \"human\": \"$evaluator_fail\" } }"
fi
fi
fail="$(mktemp)"
if { HADOLINT_NOFAIL=1 hadolint $hadolint_args --format json "$file" || echo > "$fail"; } |
jq --compact-output '.[] | .column -= 1 | .command = "annotate-code" | .row = .line - 1 | .text = .message | .type = if .level == "style" or .level == "ignore" then "info" else .level end | del(.code, .file, .line, .level, .message)' \
&& [ -s "$fail" ]; then
echo "{ \"command\": \"escalate-status\", \"status\": { \"enum\": \"wrong\", \"human\": \"$linter_fail\" } }"
fi
rm "$fail"
# /kaniko is a safe space
cp /bin/busybox /kaniko
mv /bin/jq /kaniko
if ! err=$(/kaniko/executor -v error --no-push --no-push-cache --context "$workdir" -f "$file" 2>&1 > /dev/null); then
/kaniko/jq --null-input --compact-output \
--arg description "$err" \
'{ "command": "append-message", "message": { "format": "callout-danger", "description": $description } }'
/kaniko/busybox echo "{ \"command\": \"escalate-status\", \"status\": { \"enum\": \"wrong\", \"human\": \"$build_fail\" } }"
fi
# After running kaniko we can't trust anything outside of /kaniko to be the same
PATH="/kaniko"
busybox ln -s /kaniko/busybox /kaniko/ln
ln -s /kaniko/busybox /kaniko/cat
ln -s /kaniko/busybox /kaniko/echo
ln -s /kaniko/busybox /kaniko/grep
if [ -f "$filename" ]; then
echo '{ "command": "close-tab" }'
echo "{ \"command\": \"start-tab\", \"title\": \"Files\" }"
jq --compact-output '.files[]' "$judge_file" | while read -r fileinfo; do
type=$(echo "$fileinfo" | jq -r '."type"')
path=$(echo "$fileinfo" | jq -r '."path"')
echo "{ \"command\": \"start-context\", \"description\": \"$path\" }"
if [ "$type" = "file" ]; then
echo "{ \"command\": \"start-testcase\", \"description\": \"$file_check\" }"
echo "{ \"command\": \"start-test\", \"expected\": \"$path\" }"
if [ -f "$path" ]; then
echo "{ \"command\": \"close-test\", \"generated\": \"$path\", \"status\": { \"enum\": \"correct\" } }"
else
echo "{ \"command\": \"close-test\", \"generated\": \"\", \"status\": { \"enum\": \"wrong\", \"human\": \"$file_not_found\" } }"
fi
echo '{ "command": "close-testcase" }'
if source="$(echo "$fileinfo" | jq --exit-status -r '."compare"')"; then
echo "{ \"command\": \"start-testcase\", \"description\": \"$file_content\" }"
source="$workdir/$source"
source_content=$(cat "$source")
jq --null-input --compact-output \
--arg content "$source_content" \
'{ "command": "start-test", "expected": $content }'
path_content=$(cat "$path")
result="wrong"
if [ "$source_content" = "$path_content" ]; then
result="correct"
fi
jq --null-input --compact-output \
--arg content "$path_content" --arg result "$result" \
'{ "command": "close-test", "generated": $content, "status": { "enum": $result } }'
echo '{ "command": "close-testcase" }'
fi
if regex="$(echo "$fileinfo" | jq --exit-status -r '."regex"')"; then
echo "{ \"command\": \"start-testcase\", \"description\": \"$file_regex\" }"
jq --null-input --compact-output \
--arg content "$regex" \
'{ "command": "start-test", "expected": $content }'
if grep -qE "$regex" "$path"; then
jq --null-input --compact-output \
--arg content "$regex" \
'{ "command": "close-test", "generated": $content, "status": { "enum": "correct" } }'
else
echo "{ \"command\": \"close-test\", \"generated\": \"\", \"status\": { \"enum\": \"wrong\", \"human\": \"$no_match\" } }"
fi
echo '{ "command": "close-testcase" }'
fi
elif [ "$type" = "directory" ]; then
echo "{ \"command\": \"start-testcase\", \"description\": \"$directory_check\" }"
echo "{ \"command\": \"start-test\", \"expected\": \"$path\" }"
if [ -d "$path" ]; then
echo "{ \"command\": \"close-test\", \"generated\": \"$path\", \"status\": { \"enum\": \"correct\" } }"
else
echo "{ \"command\": \"close-test\", \"generated\": \"\", \"status\": { \"enum\": \"wrong\", \"human\": \"$dir_not_found\" } }"
fi
echo '{ "command": "close-testcase" }'
fi
echo '{ "command": "close-context" }'
done
fi
else
echo "{ \"command\": \"escalate-status\", \"status\": { \"enum\": \"wrong\", \"human\": \"$empty\" } } "
fi
echo '{ "command": "close-tab" }'
echo '{ "command": "close-judgement" }'