-
Notifications
You must be signed in to change notification settings - Fork 219
Expand file tree
/
Copy pathvalidate-examples.sh
More file actions
executable file
·51 lines (48 loc) · 1.79 KB
/
Copy pathvalidate-examples.sh
File metadata and controls
executable file
·51 lines (48 loc) · 1.79 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
#!/usr/bin/env bash
# Validate every example project through the real compile pipeline.
#
# The examples are the first thing a new user copies, and nothing else
# compiles them, so a broken graph or a dead @file(...) reference would
# ship silently. A fresh checkout has no credentials connected, so the
# connect-an-account diagnostics are the expected baseline; any other
# ERROR fails. A warning is advice (a leaf node whose outputs nobody
# reads is how a program that sends a message ends), and an example is
# allowed to carry it.
set -u
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR/.." || exit 1
if ! command -v jq >/dev/null 2>&1; then
echo "jq is not on PATH; it is needed to read the validate output" >&2
exit 1
fi
status=0
for main in examples/*/src/main.weft; do
dir="$(dirname "$(dirname "$main")")"
if ! out="$(cd "$dir" && cargo run --quiet --locked -p weft-cli -- validate --file src/main.weft < src/main.weft)"; then
echo "FAIL $dir: weft validate itself errored" >&2
status=1
continue
fi
# A jq failure (the output shape changed) must fail the example, not
# print "ok" over diagnostics nobody read.
if ! unexpected="$(printf '%s' "$out" | jq -r '
.diagnostics[]
| select(.severity == "error")
| select((.code == "rule-runtime"
and ((.message | contains("has no connected"))
or (.message | contains("connection picked")))) | not)
| " line \(.line): [\(.code)] \(.message)"')"; then
echo "FAIL $dir: could not read the validate output as JSON:" >&2
printf '%s\n' "$out" >&2
status=1
continue
fi
if [ -n "$unexpected" ]; then
echo "FAIL $dir: errors beyond the expected connect-a-credential ones:" >&2
echo "$unexpected" >&2
status=1
else
echo "ok $dir"
fi
done
exit "$status"