-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_verify_split.sh
More file actions
executable file
·148 lines (129 loc) · 3.04 KB
/
Copy pathrun_verify_split.sh
File metadata and controls
executable file
·148 lines (129 loc) · 3.04 KB
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
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(git rev-parse --show-toplevel)"
cd "$ROOT"
OUTPUT=""
VERIFY_FILES="${COMPETITIVE_VERIFY_FILES_PATH:-verify_files.json}"
SPLIT_SIZE="20"
SPLIT_INDEX=""
TIMEOUT="1800"
PREV_RESULT=""
FULL_VERIFY="false"
while [[ "$#" -gt 0 ]]; do
case "$1" in
--output)
OUTPUT="$2"
shift 2
;;
--verify-files)
VERIFY_FILES="$2"
shift 2
;;
--split-size)
SPLIT_SIZE="$2"
shift 2
;;
--split-index)
SPLIT_INDEX="$2"
shift 2
;;
--timeout)
TIMEOUT="$2"
shift 2
;;
--prev-result)
PREV_RESULT="$2"
shift 2
;;
--full)
FULL_VERIFY="true"
shift
;;
*)
echo "unknown option: $1" >&2
exit 2
;;
esac
done
if [[ -z "$OUTPUT" ]]; then
echo "`--output` is required." >&2
exit 2
fi
if [[ -z "$VERIFY_FILES" ]]; then
echo "Either `--verify-files` or `COMPETITIVE_VERIFY_FILES_PATH` is required." >&2
exit 2
fi
if [[ ! -f "$VERIFY_FILES" ]]; then
echo "verify files JSON was not found: $VERIFY_FILES" >&2
echo "On GitHub Actions, pass the json-path output from download-verify-artifact to --verify-files." >&2
exit 2
fi
if [[ -n "$PREV_RESULT" && ! -f "$PREV_RESULT" ]]; then
echo "prev-result was not found: $PREV_RESULT" >&2
exit 2
fi
if [[ -z "${COMPETITIVE_VERIFIER_CMD:-}" ]]; then
if [[ "${GITHUB_ACTIONS:-}" == "true" ]]; then
COMPETITIVE_VERIFIER_CMD="competitive-verifier"
elif command -v uv >/dev/null 2>&1; then
COMPETITIVE_VERIFIER_CMD="uv run --group dev competitive-verifier"
else
COMPETITIVE_VERIFIER_CMD="competitive-verifier"
fi
fi
read -r -a CV_CMD <<< "$COMPETITIVE_VERIFIER_CMD"
if [[ "$FULL_VERIFY" == "true" ]]; then
rm -rf .competitive-verifier/cache
PREV_RESULT=""
fi
mkdir -p "$(dirname "$OUTPUT")"
rm -f "$OUTPUT"
cmd=(
"${CV_CMD[@]}"
verify
--verify-json "$VERIFY_FILES"
--check-error
--timeout "$TIMEOUT"
--output "$OUTPUT"
)
if [[ -n "$SPLIT_SIZE" ]]; then
cmd+=(--split "$SPLIT_SIZE")
fi
if [[ -n "$SPLIT_INDEX" ]]; then
cmd+=(--split-index "$SPLIT_INDEX")
fi
if [[ -n "$PREV_RESULT" ]]; then
cmd+=(--prev-result "$PREV_RESULT")
fi
set +e
"${cmd[@]}"
status="$?"
set -e
echo "competitive-verifier verify status: $status"
if [[ ! -s "$OUTPUT" ]]; then
echo "competitive-verifier verify did not generate a result JSON: $OUTPUT" >&2
if [[ "$status" -eq 0 ]]; then
exit 1
fi
exit "$status"
fi
PYTHON_BIN="${PYTHON_BIN:-python3}"
if ! "$PYTHON_BIN" - "$OUTPUT" <<'PY'
import json
import pathlib
import sys
path = pathlib.Path(sys.argv[1])
json.loads(path.read_text(encoding="utf-8"))
PY
then
echo "Could not parse the result JSON generated by competitive-verifier verify: $OUTPUT" >&2
if [[ "$status" -eq 0 ]]; then
exit 1
fi
exit "$status"
fi
if [[ "$status" -ne 0 ]]; then
echo "competitive-verifier verify exited with a non-zero status, but a result JSON was generated." >&2
echo "The final verification result will be determined by the subsequent competitive-verifier check." >&2
fi
exit 0