#!/usr/bin/env bash # Fails when a Cargo.lock lists more than one commit of the gitdan-crates # git source: two commits mean two copies of every shared type. # # crates-lock-check.sh # # Several packages from the one source share a commit, so what counts is # distinct commits, not entries. The query string (`?branch=main`, `?rev=...`) # is ignored, and so is the URL's spelling (scheme, port, `.git`): two copies # of the repo are two copies whichever way they were named. No entry passes. set -euo pipefail [ $# -eq 1 ] || { echo "::error::crates-lock-check: expected " >&2; exit 1; } lock="$1" [ -f "$lock" ] || { echo "::error::gitdan-crates-access: lockfile '$lock' not found; set the action's 'lockfile' input to its path, or to an empty string to skip the check" >&2 exit 1 } # source = "git+[?query]#" shas=$(sed -nE 's#^source = "git\+[^"?\#]*daniel/gitdan-crates(\.git)?(\?[^"\#]*)?\#([^"]*)"$#\3#p' "$lock" | sort -u) count=$(grep -c . <<<"$shas" || true) if [ "$count" -gt 1 ]; then echo "::error::$lock locks $count different commits of gitdan-crates; every consumer must resolve one, or shared types are duplicated. Run: cargo update -p --precise , or cargo update, to unify them:" >&2 while read -r s; do echo " $s" >&2; done <<<"$shas" exit 1 fi echo "gitdan-crates lock check: ${count} commit(s) of gitdan-crates in $lock"