1#!/usr/bin/env bash 2# Fail if a version written outside mise.toml differs from the one in it. mise.toml is the one place 3# versions live; these are the few other files that cannot read it and so repeat one. 4# 5# tools/check-versions.sh 6# 7# Needs only POSIX tools: it reads mise.toml's `key = "value"` lines, not a TOML parser. 8set -euo pipefail 9cd "$(dirname "$0")/.." 10fail=0 11bad() { echo "check-versions: $*" >&2; fail=1; } 12tool() { grep -m1 -E "^\"?$1\"? *= *\[?\"" mise.toml | sed -E 's/^[^=]*= *\[?"([^"]*)".*/\1/'; } 13 14# Every PostgreSQL major in build/defs.bzl has a server in mise.toml, and no other. 15majors=$(sed -n 's/^PG_MAJORS = \[\(.*\)\].*/\1/p' build/defs.bzl | tr -d '" ' | tr ',' ' ') 16have=$(grep -m1 -E '^"conda:postgresql" *=' mise.toml | grep -oE '"[0-9]+\.[0-9]+"' | tr -d '"' | cut -d. -f1 | sort -n | tr '\n' ' ') 17want=$(echo $majors | tr ' ' '\n' | sort -n | tr '\n' ' ') 18[ "$have" = "$want" ] || bad "build/defs.bzl supports majors [$want] but mise.toml installs servers for [$have]" 19 20# cargo-pgrx must be the pgrx the graph resolves. 21pgrx="$(tool 'cargo:cargo-pgrx')" 22grep -qE "^pgrx *= *\{ *version *= *\"=$pgrx\"" third-party/Cargo.toml || bad "third-party/Cargo.toml does not pin pgrx =$pgrx (the cargo-pgrx in mise.toml)" 23 24hk="$(tool hk)" 25grep -q "hk@$hk#" hk.pkl || bad "hk.pkl does not reference hk $hk (the release mise.toml installs)" 26 27# Nothing may pin a tool version in the flake: it only wraps mise. 28if grep -vE '^[[:space:]]*#' flake.nix | grep -nE 'postgresql_[0-9]|pkgs\.(rustc|cargo|clang|python3|reindeer)' >&2; then 29 bad "flake.nix provides a tool the toolchain is mise.toml's to provide" 30fi 31[ "$fail" = 0 ] && echo "check-versions: ok" 32exit "$fail"