-
Notifications
You must be signed in to change notification settings - Fork 30
71 lines (62 loc) · 3.37 KB
/
Copy pathtest-error-annotation.yaml
File metadata and controls
71 lines (62 loc) · 3.37 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
name: error-annotation
on:
push:
branches: [main]
pull_request:
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
jobs:
entrypoint_error_annotation:
runs-on: ubuntu-latest
name: Entrypoints surface genuine errors as annotations, not success/fail-on
steps:
- name: checkout
uses: actions/checkout@v7
- name: Exercise every entrypoint with a stubbed oasdiff
run: |
set -eu
# Stub oasdiff: write $STUB_STDERR to stderr (if set), produce no
# stdout, and exit $STUB_CODE. Lets us drive each entrypoint's
# exit-code handling deterministically — no real spec, no network.
mkdir -p /tmp/bin
cat > /tmp/bin/oasdiff <<'STUB'
#!/bin/sh
[ -n "${STUB_STDERR:-}" ] && printf '%s\n' "$STUB_STDERR" >&2
exit "${STUB_CODE:-0}"
STUB
chmod +x /tmp/bin/oasdiff
export PATH="/tmp/bin:$PATH"
export GITHUB_OUTPUT=/tmp/gh_output GITHUB_STEP_SUMMARY=/tmp/gh_summary
export GITHUB_REPOSITORY=o/r GITHUB_SHA=deadbeef GITHUB_REF=refs/pull/1/merge
echo '{}' > /tmp/event.json; export GITHUB_EVENT_PATH=/tmp/event.json
fail() { echo "FAIL: $1" >&2; exit 1; }
# invoke <exit-code> <stderr> <command> -> prints the entrypoint's stdout.
# pr-comment gets an empty oasdiff-token so it skips the network POST.
invoke() {
export STUB_CODE="$1" STUB_STDERR="$2"; cmd="$3"
: > "$GITHUB_OUTPUT"; : > "$GITHUB_STEP_SUMMARY"
case "$cmd" in
breaking) sh breaking/entrypoint.sh base.yaml rev.yaml "" "" "" "" "" "" "" "" "" "" "" "" "false" ;;
changelog) sh changelog/entrypoint.sh base.yaml rev.yaml "" "" "" "" "" "" "" "" "" "" "" "" "false" ;;
diff) sh diff/entrypoint.sh base.yaml rev.yaml "" "" "" "" "" "" "" "false" ;;
pr-comment) sh pr-comment/entrypoint.sh base.yaml rev.yaml "" "" "" "" "" "" "false" ;;
validate) sh validate/entrypoint.sh spec.yaml "" "false" ;;
esac
}
for cmd in breaking changelog diff pr-comment validate; do
# success (exit 0): no ::error:: annotation
out=$(invoke 0 "" "$cmd" 2>/dev/null || true)
echo "$out" | grep -q '::error::' && fail "$cmd: success (exit 0) must not emit ::error::"
# genuine error (exit 102): ::error:: annotation surfaced
out=$(invoke 102 'Error: failed to load spec from "x.yaml": no such file' "$cmd" 2>/dev/null || true)
echo "$out" | grep -q '::error::' || fail "$cmd: exit 102 must emit a ::error:: annotation"
# disallowed external ref (exit 123): the allow-external-refs remedy
out=$(invoke 123 'Error: external $ref not allowed: https://evil' "$cmd" 2>/dev/null || true)
echo "$out" | grep -q 'allow-external-refs: true' || fail "$cmd: exit 123 must emit the allow-external-refs remedy"
# fail-on / changes-found (exit 1, no stderr): no ::error:: annotation
out=$(invoke 1 "" "$cmd" 2>/dev/null || true)
echo "$out" | grep -q '::error::' && fail "$cmd: exit 1 (fail-on) must not emit ::error::"
echo "ok: $cmd"
done
echo "all error-annotation assertions passed"