diff --git a/.github/scripts/check-cli-contract.sh b/.github/scripts/check-cli-contract.sh new file mode 100755 index 0000000..590e1eb --- /dev/null +++ b/.github/scripts/check-cli-contract.sh @@ -0,0 +1,115 @@ +#!/usr/bin/env bash +# The published CLI's documented contract, as exit-code assertions. +# +# `termlens --help` states three exit codes -- 0 ran, 1 diff found a +# difference, 2 termlens itself could not run -- and STABILITY.md promises +# them. Nothing checked them against an *installed* binary until #326: the +# `install` workflow verified `cargo add termlens` and never `cargo install +# termlens-cli`, so #310 (`termlens inspect --version` exiting 2) shipped in +# 0.10.0 and again in 0.10.1 and was found by a user of the published binary. +# +# Takes the binary to exercise, so the same assertions run against a release +# from crates.io in CI and against `target/debug/termlens` locally -- which +# is how you check that the assertions can fail at all: +# +# cargo build -p termlens-cli +# .github/scripts/check-cli-contract.sh target/debug/termlens +# +# Portability: macOS ships bash 3.2 and BSD sed. No `declare -A`, no GNU-only +# sed flags, no process substitution in the assertions. +set -euo pipefail + +BIN=${1:?usage: check-cli-contract.sh } +command -v "$BIN" >/dev/null 2>&1 || [ -x "$BIN" ] || { + echo "check-cli-contract: $BIN is not executable" >&2 + exit 2 +} + +WORK=$(mktemp -d 2>/dev/null || mktemp -d -t termlens-cli-contract) +trap 'rm -rf "$WORK"' EXIT +status=0 + +# `