Cotton code
138 lines · 7.2 KB · ShellRaw
#!/usr/bin/env bash# CARGO-NEXTEST — THE LANE PROVISIONS ITS TEST RUNNER, THE MACHINE DOES NOT.##   bash scripts/ci/setup-nextest.sh## Puts a PINNED `cargo-nextest` on `$GITHUB_PATH`, so `cargo nextest run` in# every step after it in the same job is the version written down here rather# than whatever the machine happens to carry. Run by `verify-main.yml`'s `rust`# job, right after `setup-sccache.sh` and before the first `nextest run` — ONE# copy, for the same reason sccache has one: a pin and its sha256 duplicated# across lanes is a supply-chain check that quietly stops being one.## THE FAILURE (run 183, PR #956). Until #941 the `rust` job named# the Linux CI box, one box, and somebody had `cargo install cargo-nextest`d on# it by hand months earlier. #941 moved the job onto the `cotton-rust` LABEL# GROUP, which the two check Macs also declare, and the first `rust` job to land# on a Mac died on the "rust: unit tests" step:##     error: no such command: `nextest`#     help: a command with a similar name exists: `test`## The signing Mac carries no cargo-nextest at all. Another Mac carries 0.9.143 in# `~/.cargo/bin`, which a job never sees either: a job's environment is the# LOGIN environment (the procedure “Hold a repository's bytes in Cotton, and move its origin off the git host”, "What a job's PATH is on a# Mac"), and the toolchain step prepends its OWN `CARGO_HOME/bin` — so the cargo# that ran was the lane's, looking for a `cargo-nextest` next to itself, and# there was none. Neither machine was misconfigured. The lane was: it assumed a# tool it never installed.## So this is the rule the runbook's table states and `setup-pnpm.sh` already# follows: what a job needs, the job fetches, pinned and digest-checked, into# the lane's own HOME. A hand `cargo install` on three machines is the fix that# has to be repeated on the fourth, drifts between the three, and is invisible# in a log until the day it is missing.## AHEAD OF EVERYTHING ELSE, DELIBERATELY. `$GITHUB_PATH` PREPENDS, and this step# runs after the toolchain step and after `setup-sccache.sh` — so the lane's# `bin` is the first directory on the PATH of every step below, and that Mac's# hand-installed 0.9.143 is stepped over rather than used. What CI ran is then a# fact of this file, not of whichever machine the dispatcher picked.## ALREADY-USABLE COPIES ARE ADOPTED, NOT RE-FETCHED. The Linux CI host's# hand-installed copy is used when its version matches the pin (and skipped when# it does not), exactly as `setup-sccache.sh` treats `/usr/local/bin/sccache`;# after the first run on a Mac, the copy in the lane's own `bin` is the one that# answers. The fetch happens ONCE per machine per pin.## `cargo nextest` IS THIS BINARY. cargo resolves an unknown subcommand by# looking for `cargo-<name>` on the PATH, so putting `cargo-nextest` in a# directory ahead of everything is the whole installation — there is no cargo# registry step, no `~/.cargo/.crates.toml` entry, and nothing to keep in step# with the toolchain. `scripts/ci/cargo-test-with-one-retry.sh nextest run`# reaches it the same way.## WHAT IT DOES NOT CHANGE: nextest still does not run doctests. That is# documented behaviour and the reason `rust-deep.yml` carries a `cargo test# --doc` step; pinning the runner neither creates nor closes that gap.## Guard: `scripts/__tests__/setup-nextest.test.ts`.set -euo pipefail# A hand run outside CI has neither file; `set -u` would die on the redirect# rather than on anything this script is about.GITHUB_PATH="${GITHUB_PATH:-/dev/null}"version=0.9.146# ONE RELEASE, ONE ASSET PER LANE. Every sha256 here is the one published beside# the asset as `<asset>.tar.gz.sha256` on the `cargo-nextest-<version>` tag, and# each was checked against a fresh download before it was written down. The# platform is read rather than passed, so a job gets the right binary by running# on the right machine and nothing has to remember to say which.case "$(uname -s)/$(uname -m)" in  Linux/x86_64)    # musl, never gnu: a statically linked binary cannot repeat the    # `libtinfo.so.5` failure `setup-libclang.sh` spends a chapter on.    asset="cargo-nextest-$version-x86_64-unknown-linux-musl"    sha=b64617e8640624e8f9ba99819e37d7971154e97836d7ae4774fed4715501a6aa    ;;  Darwin/arm64)    # THE CHECK MACS. nextest publishes ONE `universal-apple-darwin` asset — a    # fat binary carrying both slices — so there is no aarch64-only name to    # prefer; the arm64 slice is what an M-series Mac execs, with no Rosetta.    # The binary is ad-hoc (linker-)signed, which is what arm64 macOS requires    # to exec it, and a `curl` download carries no quarantine attribute.    asset="cargo-nextest-$version-universal-apple-darwin"    sha=39785160b3c2f6ed9a765049cf4fa79f3b39aa02eb7598a5a0e2a1a0b9ffb9a8    ;;  *)    echo "::error::scripts/ci/setup-nextest.sh has no pinned cargo-nextest $version asset for $(uname -s)/$(uname -m). Add the asset and its published sha256 here before wiring a lane onto that machine — an unpinned download is not a fallback." >&2    exit 1    ;;esac# THE SAME ROOT sccache AND THE TARGET DIRECTORIES USE. One durable store per# machine under the lane's HOME, swept and sized by the steps that already know# about it; a second root would be a second thing to reclaim.root="$HOME/.cache/cottondb/rust"bin="$root/bin"# `cargo-nextest nextest --version` prints `cargo-nextest <ver> (<sha> <date>)`,# so the first two fields are the comparison and the build stamp is ignored.usable() {  command -v "$1" >/dev/null 2>&1 || return 1  [ "$("$1" nextest --version 2>/dev/null | head -1 | awk '{print $1, $2}')" = "cargo-nextest $version" ]}if usable cargo-nextest; then  # The Linux CI host's hand-installed copy, when it is the pin. Nothing is  # fetched and nothing is prepended — the PATH already resolves to it.  echo "nextest: $(command -v cargo-nextest) is already the pinned $version"elif usable "$bin/cargo-nextest"; then  echo "nextest: the lane's own copy at $bin/cargo-nextest is the pinned $version"  echo "$bin" >> "$GITHUB_PATH"  export PATH="$bin:$PATH"else  echo "nextest: no pinned $version on this host — fetching it into $bin"  mkdir -p "$bin"  tmp="$(mktemp -d)"  trap 'rm -rf "$tmp"' EXIT  curl -fsSL --proto '=https' --tlsv1.2 -o "$tmp/nextest.tar.gz" \    "https://github.com/nextest-rs/nextest/releases/download/cargo-nextest-$version/$asset.tar.gz"  # macOS ships no `sha256sum`. `shasum -a 256 -c -` reads exactly the same  # "<sha>  <path>" line and exits non-zero on a mismatch, so the hard failure  # is the same one on both lanes — there is no path past a bad hash.  if command -v sha256sum >/dev/null 2>&1; then    echo "$sha  $tmp/nextest.tar.gz" | sha256sum -c -  else    echo "$sha  $tmp/nextest.tar.gz" | shasum -a 256 -c -  fi  # nextest's tarball is FLAT: one `cargo-nextest` at the root, no directory  # named after the asset (sccache's has one — the two release processes differ  # and neither is wrong).  tar xzf "$tmp/nextest.tar.gz" -C "$tmp"  install -m 0755 "$tmp/cargo-nextest" "$bin/cargo-nextest"  echo "$bin" >> "$GITHUB_PATH"  export PATH="$bin:$PATH"  "$bin/cargo-nextest" nextest --versionfiecho "nextest: \`cargo nextest\` is the pinned $version for the rest of this job"