-
-
Notifications
You must be signed in to change notification settings - Fork 0
292 lines (280 loc) · 11.5 KB
/
Copy pathabi-drift.yml
File metadata and controls
292 lines (280 loc) · 11.5 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
# SPDX-License-Identifier: MPL-2.0
# Copyright (c) 2026 Jonathan D.A. Jewell (hyperpolymath) <j.d.a.jewell@open.ac.uk>
#
# ABI Drift Gate (standards#92 Phase 2)
#
# For every cartridge that has a paired `abi/.../Safe*.idr` (Idris2 ABI
# source of truth) and `ffi/*_ffi.zig` (Zig FFI mirror), this workflow:
# 1. emits the ABI manifest from the Idris2 source (`iseriser abi-emit-manifest`)
# 2. verifies the Zig FFI against the emitted manifest (`iseriser abi-verify`)
# Fails the PR check on any structural drift in: enum encoding,
# transition table, or accept-by-omission. See iseriser/README and
# `iseriser/examples/abi-manifests/README.adoc` for the drift taxonomy.
#
# Triggers only when an ABI- or FFI-bearing file under cartridges/
# changes, so unrelated PRs do not pay for it.
name: ABI Drift Gate
# Was workflow-level path-filtered: a required check that never ran on PRs
# touching none of its paths, leaving the check "Expected" and the PR blocked.
# Now always runs; the `changes` job gates the heavy `verify` job, which when
# skipped reports SUCCESS to required checks. (verify also does its own
# per-cartridge scoping for the relevant case.)
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
concurrency:
group: abi-drift-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}
permissions:
contents: read
jobs:
changes:
name: Detect relevant changes
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
run: ${{ steps.detect.outputs.run }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- id: detect
env:
EVENT: ${{ github.event_name }}
BASE: ${{ github.base_ref }}
BEFORE: ${{ github.event.before }}
run: |
set -uo pipefail
run=true
if [ "$EVENT" = pull_request ]; then
git fetch --no-tags --depth=200 origin "$BASE" 2>/dev/null \
&& changed=$(git diff --name-only "origin/${BASE}...HEAD" 2>/dev/null) \
&& { printf '%s\n' "$changed" | grep -qE '^cartridges/.*/abi/|^cartridges/.*/ffi/' && run=true || run=false; }
elif [ "$EVENT" = push ] && [ -n "$BEFORE" ] && [ "$BEFORE" != 0000000000000000000000000000000000000000 ]; then
changed=$(git diff --name-only "${BEFORE}...${GITHUB_SHA}" 2>/dev/null) \
&& { printf '%s\n' "$changed" | grep -qE '^cartridges/.*/abi/|^cartridges/.*/ffi/' && run=true || run=false; }
fi
printf 'run=%s\n' "$run" >> "$GITHUB_OUTPUT"
echo "relevant=$run; changed files:"; printf '%s\n' "${changed:-<none computed>}"
verify:
name: Emit manifest + verify FFI
needs: changes
if: needs.changes.outputs.run == 'true'
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
# Need at least two commits so `git diff origin/<base>...HEAD`
# can compute the changed-cartridge set on pull_request events.
# `0` = full history (cheap on this repo).
fetch-depth: 0
- name: Install Rust toolchain (stable)
uses: dtolnay/rust-toolchain@b3b07ba8b418998c39fb20f53e8b695cdcc8de1b # stable
with:
toolchain: stable
# Pin to a specific iseriser commit so the cache key changes when
# we bump it. Floating `--branch main` + a prefix-matching
# `restore-keys` (`iseriser-${{ runner.os }}-`) was sticky: once a
# binary was cached for a given OS, the install step's
# `command -v iseriser` short-circuit skipped re-build, and #111's
# GADT-skip fix (iseriser#20, merged 2026-05-20) never reached CI.
# Bumping ISERISER_REV invalidates the cache and forces a rebuild.
- name: Cache cargo bin (iseriser install)
uses: actions/cache@d4323d4df104b026a6aa633fdb11d772146be0bf # v4.2.2
env:
ISERISER_REV: 741a3b63e7619b6e9cfe7f91b04d7ccfb130b1ca
with:
path: |
~/.cargo/bin/iseriser
~/.cargo/registry
~/.cargo/git
key: iseriser-${{ runner.os }}-${{ env.ISERISER_REV }}
- name: Install iseriser
env:
ISERISER_REV: 741a3b63e7619b6e9cfe7f91b04d7ccfb130b1ca
run: |
set -euo pipefail
cargo install --git https://github.com/hyperpolymath/iseriser \
--rev "$ISERISER_REV" --locked --force
iseriser --version
- name: Resolve cartridge allowlist
id: discover
# 80 cartridges in the tree carry a paired Safe*.idr + *_ffi.zig.
# 66 are audited green against the Phase 1b emitter + Phase 1
# verifier (re-run 2026-05-20 after iseriser#20 / #21 / #22 merged:
# GADT-skip in the emitter, runtogether candidate for multi-cap
# acronyms, and terminal `false` switch-arm tolerance in the
# verifier). Versus the previous 56-cartridge allowlist this:
# * ADDS 10 cartridges that the three iseriser fixes unblocked
# (cloud, comms, container, git, gitlab-api, ml,
# mongodb, queues, research, vordr)
# * RESTORES browser-mcp — the Class D `BrowserAction.Type` ↔
# Zig `type_text` drift was fixed in cartridge-side PR #134
# (`Type` renamed to `TypeText` in the Idris2 ADT to match
# the underlying Zig FFI tag).
# 14 cartridges carry real drift across Classes B/C/D — see
# standards#92 plus open sub-issues standards#150-155 (Class C)
# and standards#156 (Class D). Class P (verifier parser limit)
# and Class E (malformed Idris2 source) are now empty: iseriser#22
# closed Class P (5 cartridges) and the vordr-mcp Class E case
# was closed via iseriser#20 + the cartridge's clean re-survey.
# chapeliser-mcp was over-listed in #133 — the cartridge dir does
# not exist in the tree; the loop's `ls cartridges/<n>/abi/*/...`
# fails with exit code 2 and the whole job goes red.
run: |
set -euo pipefail
{
echo 'carts<<EOF'
echo '007-mcp'
echo 'affinescript-mcp'
echo 'agent-mcp'
echo 'airtable-mcp'
echo 'arango-mcp'
echo 'browser-mcp'
echo 'buildkite-mcp'
echo 'clickhouse-mcp'
echo 'cloud-mcp'
echo 'cloudflare-mcp'
echo 'comms-mcp'
echo 'container-mcp'
echo 'crates-mcp'
echo 'discord-mcp'
echo 'dns-shield-mcp'
echo 'docker-hub-mcp'
echo 'duckdb-mcp'
echo 'feedback-mcp'
echo 'fleet-mcp'
echo 'fly-mcp'
echo 'git-mcp'
echo 'github-actions-mcp'
echo 'github-api-mcp'
echo 'gitlab-api-mcp'
echo 'google-docs-mcp'
echo 'google-sheets-mcp'
echo 'grafana-mcp'
echo 'hackage-mcp'
echo 'hex-mcp'
echo 'iac-mcp'
echo 'jira-mcp'
echo 'k8s-mcp'
echo 'k9iser-mcp'
echo 'linear-mcp'
echo 'local-coord-mcp'
echo 'matrix-mcp'
echo 'ml-mcp'
echo 'mongodb-mcp'
echo 'neo4j-mcp'
echo 'neon-mcp'
echo 'nesy-mcp'
echo 'notion-mcp'
echo 'npm-registry-mcp'
echo 'observe-mcp'
echo 'obsidian-mcp'
echo 'opam-mcp'
echo 'opsm-mcp'
echo 'pmpl-mcp'
echo 'prometheus-mcp'
echo 'proof-mcp'
echo 'pypi-mcp'
echo 'queues-mcp'
echo 'railway-mcp'
echo 'render-mcp'
echo 'research-mcp'
echo 'rokur-mcp'
echo 'secrets-mcp'
echo 'sentry-mcp'
echo 'slack-mcp'
echo 'ssg-mcp'
echo 'supabase-mcp'
echo 'telegram-mcp'
echo 'todoist-mcp'
echo 'turso-mcp'
echo 'vordr-mcp'
echo 'zotero-mcp'
echo 'EOF'
} >> "$GITHUB_OUTPUT"
# On pull_request, restrict the verify loop to cartridges that
# actually changed in this PR — unrelated cartridge drift is the
# main branch's problem, not this PR's. On push to main, scan the
# full allowlist so cross-cutting regressions are still caught at
# trunk. Empty changed-set on a PR ⇒ skip the loop (handled in
# the verify step's defensive empty check below).
#
# Single output, always-correct: scope.outputs.carts is the
# PR-filtered allowlist on pull_request, the full allowlist on
# push. Avoids the `${{ X && Y || Z }}` ternary footgun where Y
# being an empty string short-circuits to Z (which would silently
# re-expand to the full sweep — exactly the bug we're trying to
# fix).
- name: Scope cartridges to verify
id: scope
env:
EVENT: ${{ github.event_name }}
BASE_REF: ${{ github.base_ref }}
CARTS: ${{ steps.discover.outputs.carts }}
run: |
set -euo pipefail
if [ "$EVENT" = "pull_request" ]; then
git fetch --no-tags --depth=50 origin "$BASE_REF" || true
changed=$(git diff --name-only "origin/${BASE_REF}...HEAD" -- 'cartridges/**' \
| awk -F/ '{print $2}' | sort -u)
scope=""
while IFS= read -r cart; do
[ -z "$cart" ] && continue
if printf '%s\n' "$changed" | grep -qx "$cart"; then
scope="${scope}${cart}"$'\n'
fi
done <<< "$CARTS"
else
scope="$CARTS"
fi
{
echo 'carts<<EOF'
printf '%s' "$scope"
echo
echo 'EOF'
} >> "$GITHUB_OUTPUT"
echo "Cartridges in scope for this run:"
printf ' • %s\n' $(printf '%s\n' "$scope" | grep -v '^$' || true)
- name: Emit + verify each cartridge
env:
CARTS: ${{ steps.scope.outputs.carts }}
run: |
set -euo pipefail
if [ -z "$(printf '%s' "$CARTS" | tr -d '[:space:]')" ]; then
echo "::notice::No allowlisted cartridges changed in this PR — skipping drift verify."
exit 0
fi
failed=""
while IFS= read -r cart; do
[ -z "$cart" ] && continue
echo "::group::abi-drift: $cart"
idris_src="$(ls cartridges/${cart}/abi/*/Safe*.idr | head -n1)"
zig_ffi="$(ls cartridges/${cart}/ffi/*_ffi.zig | head -n1)"
manifest="$(mktemp --suffix=.json)"
if iseriser abi-emit-manifest \
--idris "$idris_src" \
--cartridge "$cart" \
--source-path "$idris_src" \
--out "$manifest"; then
if iseriser abi-verify --manifest "$manifest" --zig-ffi "$zig_ffi"; then
echo " ✓ $cart"
else
echo " ✗ $cart DRIFT"
failed="$failed $cart"
fi
else
echo " ✗ $cart EMIT FAILED"
failed="$failed $cart"
fi
rm -f "$manifest"
echo "::endgroup::"
done <<< "$CARTS"
if [ -n "$failed" ]; then
echo "::error::ABI drift detected in:$failed"
exit 1
fi