-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
run
executable file
·124 lines (110 loc) · 4.83 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
#!/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"')
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"
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."
else
empty="Empty submission"
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."
fi
echo '{ "command": "start-judgement" }'
echo "{ \"command\": \"start-tab\", \"title\": \"$title\" }"
if [ -s "$file" ]; then
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
filename="$resources/files.json"
if [ -f "$filename" ]; then
echo '{ "command": "close-tab" }'
echo "{ \"command\": \"start-tab\", \"title\": \"Files\" }"
jq --compact-output '.[]' "$filename" | while read -r fileinfo; do
type=$(echo "$fileinfo" | jq -r '."type"')
path=$(echo "$fileinfo" | jq -r '."path"')
echo '{ "command": "start-context" }'
echo "{ \"command\": \"start-testcase\", \"description\": \"$path\" }"
if [ "$type" = "file" ]; then
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
if source="$(echo "$fileinfo" | jq --exit-status -r '."compare"')"; then
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 } }'
fi
if regex="$(echo "$fileinfo" | jq --exit-status -r '."regex"')"; then
if ! grep -qE "$regex" "$path"; then
echo "{ \"command\": \"escalate-status\", \"status\": { \"enum\": \"wrong\", \"human\": \"$path: $no_match\" } }"
fi
fi
elif [ "$type" = "directory" ]; then
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
fi
echo '{ "command": "close-testcase" }'
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" }'