#!/usr/bin/env bash # Exit 0 when this VM is the baked CI toolchain image of this checkout (scripts/build-ci-image.sh): /etc/swc-image starts # with `ci-toolchain `, is the sha256 of /etc/swc-image.detail, which names the sha256 of this checkout's scripts/knotless-ci-toolchain.sh (an image baked by another # version of the script is installed over, not trusted), it was baked from this checkout's toolchain pins (scripts/knotless-ci-pins.sh: rust, # go, deno, zig), /opt/ci/env is there, and its Go is the one go.mod asks for. # Prints why not, and exits 1, otherwise: the job then runs scripts/knotless-ci-toolchain.sh. set -u fail() { echo "baked toolchain: not used: $*"; exit 1; } [ -f /etc/swc-image ] || fail "no /etc/swc-image" marker="$(head -n1 /etc/swc-image)" case "$marker" in "ci-toolchain "*) ;; *) fail "the image is not a ci-toolchain image: $marker" ;; esac # the marker is `ci-toolchain ` (a bidder refuses one over 256 bytes); the detail names what was baked [ -f /etc/swc-image.detail ] || fail "no /etc/swc-image.detail" [ "ci-toolchain $(sha256sum /etc/swc-image.detail | cut -d' ' -f1)" = "$marker" ] || fail "the marker is not the digest of /etc/swc-image.detail: $marker" want="$(sha256sum scripts/knotless-ci-toolchain.sh | cut -d' ' -f1)" grep -qx "toolchain=$want" /etc/swc-image.detail || fail "baked by another toolchain script (this checkout's is $want): $(tr '\n' ' '