Files
matcha/test_install.sh
T
chrnx 87cf3eac82
CI / installer (macos-14) (pull_request) Successful in 5s
CI / check (pull_request) Successful in 27s
CI / starter (bun) (pull_request) Successful in 33s
CI / starter (deno) (pull_request) Successful in 32s
CI / starter (edge) (pull_request) Successful in 39s
CI / core-freshness (pull_request) Has been skipped
CI / installer (ubuntu-latest) (pull_request) Failing after 6s
CI / starter (node) (pull_request) Successful in 32s
feat(release): a Linux arm64 binary, built through one cross toolchain
The installer refused Linux arm64 and sent you to `cargo install --git`, so
Graviton, a Raspberry Pi, an ARM CI runner and Docker on Apple Silicon all
needed a Rust toolchain to install a CLI whose whole point is not needing one.

`rustup target add` could never have fixed it. `tree-sitter` and
`tree-sitter-typescript` both compile C through the `cc` crate, so the target
needs a real cross C compiler, and Ubuntu ships none for aarch64 musl. zig is
one, for both arches — which is why the x86_64 leg moved onto it too rather than
keeping `musl-tools` beside it. One toolchain for Linux beats a working one plus
a second one that only the new target uses. Verified before touching the
pipeline: all four targets cross-compile from macOS arm64 through zig, C
included, producing binaries of the right architecture and format.

Each release job now also runs the artifact it built, wherever the runner can
execute it. agartha is a macOS host executor, so it runs both macOS binaries —
the Intel one through Rosetta, confirmed by running the built binary on that
host. Rosetta is probed rather than assumed, because a hosted runner may not
have it and a smoke that hard-failed there would block a release over the
runner's configuration rather than over the binary; the probe is an `if` rather
than an AND-list so a missing Rosetta cannot end the step through `set -e`.

Whether the aarch64 Linux binary gets started that way is not a property of the
pipeline, though — it depends on what `ubuntu-latest` resolves to on the forge
that fired. `verify-linux-arm64` removes the dependency by pinning an arm64
Linux runner and installing the published binary there through `install.sh`, so
the answer is the same on every release, and the installer's arm64 branch and
its checksum verification are covered against the real assets on the way. It
carries the same `server_url` guard `publish-crate` already uses, since GitHub
offers such runners and Gitea does not, and a job pinned to a label one forge
lacks would queue there forever.

Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
2026-09-05 16:46:25 -05:00

65 lines
2.9 KiB
Bash
Executable File

#!/bin/sh
# Tests install.sh against a local file:// fixture (no network).
set -eu
here=$(cd "$(dirname "$0")" && pwd)
fail() { echo "FAIL: $*" >&2; exit 1; }
# derive this machine's expected triple the same way install.sh does
os=$(uname -s); arch=$(uname -m)
case "$os" in
Darwin) case "$arch" in arm64|aarch64) triple=aarch64-apple-darwin;; x86_64) triple=x86_64-apple-darwin;; esac;;
Linux) case "$arch" in
x86_64|amd64) triple=x86_64-unknown-linux-musl;;
arm64|aarch64) triple=aarch64-unknown-linux-musl;;
esac;;
esac
[ -n "${triple:-}" ] || { echo "SKIP: unsupported test host"; exit 0; }
work=$(mktemp -d); trap 'rm -rf "$work"' EXIT
tag=v0.0.0
assetdir="$work/fixture/releases/download/$tag"
mkdir -p "$assetdir"
# build a fake release asset: a tarball containing a 'matcha' executable
printf '#!/bin/sh\necho "matcha 0.0.0-test"\n' > "$work/matcha"
chmod +x "$work/matcha"
tar -czf "$assetdir/matcha-$triple.tar.gz" -C "$work" matcha
if command -v sha256sum >/dev/null 2>&1; then
( cd "$assetdir" && sha256sum "matcha-$triple.tar.gz" > "matcha-$triple.tar.gz.sha256" )
else
( cd "$assetdir" && shasum -a 256 "matcha-$triple.tar.gz" > "matcha-$triple.tar.gz.sha256" )
fi
# --- case 1: happy path installs the binary ---
bin="$work/bin"
MATCHA_REPO_BASE="file://$work/fixture" MATCHA_VERSION="$tag" MATCHA_INSTALL_DIR="$bin" \
sh "$here/install.sh" >/dev/null 2>&1 || fail "install.sh exited non-zero on happy path"
[ -x "$bin/matcha" ] || fail "matcha not installed to $bin"
"$bin/matcha" --version >/dev/null 2>&1 || fail "installed matcha not runnable"
# --- case 2: checksum mismatch aborts and does NOT install ---
echo "deadbeef matcha-$triple.tar.gz" > "$assetdir/matcha-$triple.tar.gz.sha256"
bin2="$work/bin2"
if MATCHA_REPO_BASE="file://$work/fixture" MATCHA_VERSION="$tag" MATCHA_INSTALL_DIR="$bin2" \
sh "$here/install.sh" >/dev/null 2>&1; then
fail "install.sh should have failed on checksum mismatch"
fi
[ -e "$bin2/matcha" ] && fail "matcha must NOT be installed on checksum mismatch"
# --- case 3: an unresolvable "latest" explains itself and installs nothing ---
# Both bases point at a path that does not exist, so the redirect and the API
# fallback each come back empty. The branch is worth a test because its failure
# mode is a message: the old one said only "could not resolve latest release
# tag", which is also what a rate-limited API produces.
bin3="$work/bin3"
out=$(MATCHA_REPO_BASE="file://$work/nowhere" MATCHA_API_BASE="file://$work/nowhere" \
MATCHA_INSTALL_DIR="$bin3" sh "$here/install.sh" 2>&1) && \
fail "install.sh should have failed with no resolvable latest"
case "$out" in
*MATCHA_VERSION*) ;;
*) fail "the unresolvable-latest error must point at MATCHA_VERSION; got: $out" ;;
esac
[ -e "$bin3/matcha" ] && fail "matcha must NOT be installed when latest cannot resolve"
echo "PASS: test_install.sh"