Upgrade module pins to newest releases and make dependency checks authoritative
ci / build and test (pull_request) Successful in 1m4s

The require blocks were unchanged from the base manifest even though newer
releases are available for most modules. Pin every module to the newest
release observed on proxy.golang.org, add the checksums published by
sum.golang.org, and add the transitive modules the upgraded graph now needs
(bitset, clipperhouse/displaywidth, clipperhouse/stringish,
clipperhouse/uax29/v2, go.yaml.in/yaml/v3). charmbracelet/huh is a direct
import and is recorded as such.

Rewrite scripts/check-deps.sh so it never treats the local module cache as
evidence of what the newest release is. It uses `go list -m -u` when the proxy
is reachable and otherwise compares every go.mod pin with the dependency facts
prepared by the execution profile, validating the report source, freshness
status and query scope. If neither source is available it exits with status 2
instead of reporting success.

Add scripts/test-check-deps.sh, which covers stale, uncovered and unverifiable
pins without network access, and scripts/test-ci-workflow.sh, which checks that
the single Gitea Actions job still runs on pull requests and invokes the checks.
Both run from scripts/check.sh, so one pass verifies formatting, vet, build,
tests, the CI workflow and dependency freshness.

`go build ./...`, `go vet ./...`, `go test -cover ./...`, `go mod verify` and the
new scripts all pass in the sandbox.
This commit is contained in:
software-maintainer committed 2026-10-28 09:59:57 +00:00
1 parent f3f6b5dfb4
commit c098c93ae9
8 files changed
+405 -97

No files matched your search

+113 -65
View File
@@ -1,19 +1,34 @@
#!/usr/bin/env bash
#
# check-deps.sh fails when a module required by go.mod is not the newest
# version available.
# check-deps.sh fails when a module pinned in go.mod is older than the newest
# release we can authoritatively observe.
#
# When the module proxy is reachable, `go list -m -u` is authoritative: it
# asks the proxy for the newest release of each pinned module. When the proxy
# is disabled (offline builds, sandboxes), the script compares the pins with
# the newest versions recorded in the local module cache instead.
# Two sources are accepted, in order:
#
# The script never loads the full module graph, so it works even when the cache
# only holds the modules needed by the build.
# 1. The module proxy. When GOPROXY is not "off", `go list -m -u` is the
# authority: it asks the proxy for the newest release of every pinned
# module. This is what CI uses.
#
# 2. The dependency facts prepared by the execution profile and named by
# MAINTAINER_DEPENDENCY_FACTS. The file records, for every module, the
# newest version that profile observed on proxy.golang.org and when. It is
# evidence rather than a live query, so the script prints its source and
# observation time and refuses to use reports it cannot validate as complete.
#
# The local module cache is never consulted: it only contains versions that
# happened to be downloaded, so it cannot establish what the newest release is.
# When neither source is available the script exits with status 2 instead of
# reporting success.
#
# Exit status: 0 = every pin is current, 1 = a pin is stale (or unverifiable
# for an individual module), 2 = freshness could not be established at all.
set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."
root="${CHECK_DEPS_ROOT:-$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)}"
cd "$root"
facts_file="${MAINTAINER_DEPENDENCY_FACTS:-}"
# requirements prints "<path> <version>" for every module required by go.mod.
requirements() {
@@ -25,37 +40,9 @@ requirements() {
'
}
# escape_path applies the case encoding used by the module cache for paths with
# upper-case letters (for example BurntSushi becomes !burnt!sushi).
escape_path() {
local path="$1" out='' char i
for ((i = 0; i < ${#path}; i++)); do
char="${path:i:1}"
if [[ $char == [A-Z] ]]; then
out+="!${char,,}"
else
out+="$char"
fi
done
printf '%s' "$out"
}
# newest prints the newest version in the stdin version list. Version lists in
# the module cache are unsorted and include pre-releases, so sort them with
# `sort -V` and then prefer a release to its own pre-releases
# (v1.2.0 outranks v1.2.0-rc1, while v1.2.1-0.20240101 outranks v1.2.0).
newest() {
local versions latest base
versions="$(grep -E '^v[0-9]' || true)"
if [ -z "$versions" ]; then
return 1
fi
latest="$(printf '%s\n' "$versions" | sort -V | tail -n 1)"
base="${latest%%-*}"
if printf '%s\n' "$versions" | grep -qxF "$base"; then
latest="$base"
fi
printf '%s\n' "$latest"
# behind reports whether version $1 is older than version $2.
behind() {
[ "$1" != "$2" ] && [ "$(printf '%s\n%s\n' "$1" "$2" | sort -V | tail -n 1)" = "$2" ]
}
pins="$(requirements)"
@@ -74,7 +61,7 @@ if [ "$(go env GOPROXY)" != "off" ]; then
if ! listing="$(go list -m -u -f '{{.Path}} {{.Version}} {{if .Update}}{{.Update.Version}}{{end}}' "${mods[@]}")"; then
echo 'could not query the module proxy for newer versions' >&2
exit 1
exit 2
fi
updates="$(printf '%s\n' "$listing" | awk 'NF == 3')"
if [ -n "$updates" ]; then
@@ -82,43 +69,104 @@ if [ "$(go env GOPROXY)" != "off" ]; then
printf '%s\n' "$updates" >&2
exit 1
fi
echo "ok: $count go.mod requirements are up to date"
echo "ok: $count go.mod requirements are up to date (module proxy)"
exit 0
fi
cache="$(go env GOMODCACHE)/cache/download"
checked=0
unchecked=0
# Offline: fall back to the dependency facts prepared by the execution profile.
# The facts file is refreshed by the execution profile, so a reader can race
# with an atomic rewrite; give it a moment before declaring the facts missing.
if [ -n "$facts_file" ]; then
for _ in 1 2 3 4 5 6 7 8 9 10; do
[ -r "$facts_file" ] && break
sleep 0.2
done
fi
if [ -z "$facts_file" ] || [ ! -r "$facts_file" ]; then
echo 'cannot verify dependency freshness: the module proxy is disabled (GOPROXY=off)' \
'and MAINTAINER_DEPENDENCY_FACTS does not name a readable dependency-facts file' >&2
exit 2
fi
field() {
grep -o "\"$1\"[[:space:]]*:[[:space:]]*\"[^\"]*\"" "$facts_file" | head -n 1 | sed 's/.*:[[:space:]]*"\(.*\)"/\1/'
}
schema="$(grep -o '"schema_version"[[:space:]]*:[[:space:]]*[0-9]*' "$facts_file" | head -n 1 | grep -o '[0-9]*$' || true)"
source="$(field source)"
freshness="$(field freshness_status)"
scope="$(field query_scope)"
observed_at="$(field observed_at)"
digest="$(field manifest_digest)"
if [ "$schema" != 1 ]; then
echo "cannot verify dependency freshness: unsupported dependency-facts schema (${schema:-missing})" >&2
exit 2
fi
if [ "$source" != 'https://proxy.golang.org' ]; then
echo "cannot verify dependency freshness: unexpected dependency-facts source '${source}'" >&2
exit 2
fi
if [ "$freshness" != 'available' ]; then
echo "cannot verify dependency freshness: dependency facts are not marked available ('${freshness}')" >&2
exit 2
fi
if [ "$scope" != 'module_path_latest' ]; then
echo "cannot verify dependency freshness: dependency facts use query scope '${scope}', want module_path_latest" >&2
exit 2
fi
if [ -z "$observed_at" ]; then
echo 'cannot verify dependency freshness: dependency facts have no observation time' >&2
exit 2
fi
# One record per observed module: name, latest version and item status.
records="$(grep -o '{[^{}]*"latest"[^{}]*' "$facts_file" || true)"
if [ -z "$records" ]; then
echo 'cannot verify dependency freshness: dependency facts contain no module observations' >&2
exit 2
fi
latest_for() {
local want="$1" record name latest status
while IFS= read -r record; do
name="$(printf '%s\n' "$record" | sed -n 's/.*"name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p')"
[ "$name" = "$want" ] || continue
latest="$(printf '%s\n' "$record" | sed -n 's/.*"latest"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p')"
status="$(printf '%s\n' "$record" | sed -n 's/.*"status"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p')"
[ "$status" = 'observed' ] || return 1
printf '%s\n' "$latest"
return 0
done <<<"$records"
return 1
}
stale=''
unverified=''
while read -r path version; do
list="$cache/$(escape_path "$path")/@v/list"
if [ ! -f "$list" ]; then
unchecked=$((unchecked + 1))
if ! latest="$(latest_for "$path")"; then
unverified+=" $path $version (not covered by the dependency facts)"$'\n'
continue
fi
checked=$((checked + 1))
latest="$(newest <"$list")"
if [ "$latest" = "$version" ]; then
continue
fi
# Only complain when the cached version really is newer than the pin; a
# pin that is newer than everything cached is simply not verifiable here.
if [ "$(printf '%s\n%s\n' "$version" "$latest" | sort -V | tail -n 1)" = "$latest" ]; then
stale+=" $path $version (newest cached: $latest)"$'\n'
if behind "$version" "$latest"; then
stale+=" $path $version (latest observed: $latest)"$'\n'
elif [ "$version" != "$latest" ]; then
unverified+=" $path $version (pin is newer than the latest observation $latest)"$'\n'
fi
done <<<"$pins"
if [ -n "$stale" ]; then
echo 'These go.mod pins are behind the newest cached version:' >&2
echo 'These go.mod pins are behind the latest observed releases:' >&2
printf '%s' "$stale" >&2
exit 1
fi
if [ -n "$unverified" ]; then
echo 'These go.mod pins could not be checked against the dependency facts:' >&2
printf '%s' "$unverified" >&2
exit 1
fi
if [ "$checked" -eq 0 ]; then
echo "note: GOPROXY=off and $cache is empty; dependency freshness was not checked" >&2
exit 0
echo "ok: $count go.mod requirements match the latest releases observed by the execution profile"
echo "source: $source, observed at $observed_at (module_path_latest)"
if [ -n "$digest" ]; then
echo "note: dependency-facts manifest digest: $digest"
fi
if [ "$unchecked" -ne 0 ]; then
echo "note: $unchecked of $count go.mod requirements are missing from the module cache" >&2
fi
echo "ok: $checked go.mod requirements match the newest versions in the module cache"