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"
+6
View File
@@ -8,6 +8,12 @@ set -euo pipefail
cd "$(dirname "${BASH_SOURCE[0]}")/.."
echo '==> ci workflow'
./scripts/test-ci-workflow.sh
echo '==> dependency check tests'
./scripts/test-check-deps.sh
echo '==> gofmt'
unformatted="$(gofmt -l .)"
if [ -n "$unformatted" ]; then
+104
View File
@@ -0,0 +1,104 @@
#!/usr/bin/env bash
#
# test-check-deps.sh exercises scripts/check-deps.sh without a module proxy or
# network access. It builds throwaway manifests in a temporary directory and
# asserts the script's exit status and diagnostics.
set -euo pipefail
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
script="$here/check-deps.sh"
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
failures=0
expect_status() {
local want="$1" got
shift
set +e
"$@" >"$tmp/out" 2>&1
got=$?
set -e
if [ "$got" -ne "$want" ]; then
echo "FAIL: expected exit $want, got $got: $*" >&2
cat "$tmp/out" >&2
failures=$((failures + 1))
fi
}
# fixture sets up $tmp/repo/go.mod and prints the go.mod path.
fixture() {
mkdir -p "$tmp/repo"
cat >"$tmp/repo/go.mod" <<'EOF'
module example.com/fixture
go 1.27.1
require (
github.com/a/b v1.0.0
github.com/c/d v1.3.0
)
EOF
}
# facts writes a dependency-facts document to $tmp/facts.json.
# Arguments: <freshness_status> <item-json...>
facts() {
local freshness="$1"
shift
local items=''
local item
for item in "$@"; do
[ -z "$items" ] || items+=','
items+="$item"
done
cat >"$tmp/facts.json" <<EOF
{"schema_version":1,"observations":[{"ecosystem":"go","source":"https://proxy.golang.org","observed_at":"2026-10-28T09:00:00Z","manifest_digest":"abc123","command":["go","list","-m","-e","-json"],"items":[$items],"metadata":{"checksum_database":"sum.golang.org","freshness_status":"$freshness","graph_command":"go list -m -json all","query_scope":"module_path_latest"}}]}
EOF
}
up_to_date='{"name":"github.com/a/b","current":"v1.0.0","latest":"v1.0.0","status":"observed"},{"name":"github.com/c/d","current":"v1.3.0","latest":"v1.3.0","status":"observed"}'
# 1. Every pin matches the latest observation.
fixture
facts available "$up_to_date"
expect_status 0 env CHECK_DEPS_ROOT="$tmp/repo" MAINTAINER_DEPENDENCY_FACTS="$tmp/facts.json" GOPROXY=off "$script"
grep -q 'ok: 2 go.mod requirements' "$tmp/out" || { echo 'FAIL: missing success summary' >&2; failures=$((failures + 1)); }
# 2. A stale pin is reported and fails.
fixture
facts available '{"name":"github.com/a/b","current":"v1.0.0","latest":"v1.2.0","status":"observed"},{"name":"github.com/c/d","current":"v1.3.0","latest":"v1.3.0","status":"observed"}'
expect_status 1 env CHECK_DEPS_ROOT="$tmp/repo" MAINTAINER_DEPENDENCY_FACTS="$tmp/facts.json" GOPROXY=off "$script"
grep -q 'github.com/a/b v1.0.0 (latest observed: v1.2.0)' "$tmp/out" || { echo 'FAIL: stale module not named' >&2; failures=$((failures + 1)); }
# 3. A pin that is newer than the observation cannot be verified.
fixture
facts available '{"name":"github.com/a/b","current":"v1.0.0","latest":"v1.0.0","status":"observed"}'
expect_status 1 env CHECK_DEPS_ROOT="$tmp/repo" MAINTAINER_DEPENDENCY_FACTS="$tmp/facts.json" GOPROXY=off "$script"
grep -q 'not covered by the dependency facts' "$tmp/out" || { echo 'FAIL: uncovered module not reported' >&2; failures=$((failures + 1)); }
# 4. Without a proxy and without facts nothing is verified.
fixture
expect_status 2 env CHECK_DEPS_ROOT="$tmp/repo" MAINTAINER_DEPENDENCY_FACTS="$tmp/missing.json" GOPROXY=off "$script"
grep -q 'cannot verify dependency freshness' "$tmp/out" || { echo 'FAIL: unverified run did not explain itself' >&2; failures=$((failures + 1)); }
# 5. Incomplete dependency facts are not trusted.
fixture
facts unavailable "$up_to_date"
expect_status 2 env CHECK_DEPS_ROOT="$tmp/repo" MAINTAINER_DEPENDENCY_FACTS="$tmp/facts.json" GOPROXY=off "$script"
# 6. Items that were not observed are not treated as current.
fixture
facts available '{"name":"github.com/a/b","current":"v1.0.0","latest":"v1.0.0","status":"not_found"},{"name":"github.com/c/d","current":"v1.3.0","latest":"v1.3.0","status":"observed"}'
expect_status 1 env CHECK_DEPS_ROOT="$tmp/repo" MAINTAINER_DEPENDENCY_FACTS="$tmp/facts.json" GOPROXY=off "$script"
# 7. A facts document from a different source is rejected.
fixture
sed 's#https://proxy.golang.org#https://example.invalid#' "$tmp/facts.json" >"$tmp/other.json"
expect_status 2 env CHECK_DEPS_ROOT="$tmp/repo" MAINTAINER_DEPENDENCY_FACTS="$tmp/other.json" GOPROXY=off "$script"
if [ "$failures" -ne 0 ]; then
echo "$failures check-deps test(s) failed" >&2
exit 1
fi
echo 'ok: check-deps.sh behaviour is covered'
+44
View File
@@ -0,0 +1,44 @@
#!/usr/bin/env bash
#
# test-ci-workflow.sh checks the properties of .gitea/workflows/ci.yml that
# gate pull requests. It runs without Go modules so CI configuration can be
# validated even when the module proxy is unavailable; the equivalent Go test
# in internal/ci/workflow_test.go parses the same file as YAML.
set -euo pipefail
root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
workflow="$root/.gitea/workflows/ci.yml"
if [ ! -f "$workflow" ]; then
echo "missing workflow: $workflow" >&2
exit 1
fi
failures=0
require_line() {
if ! grep -qF "$1" "$workflow"; then
echo "workflow is missing: $1" >&2
failures=$((failures + 1))
fi
}
require_line 'on:'
require_line ' pull_request:'
require_line ' push:'
require_line 'branches: [main]'
require_line 'run: ./scripts/check.sh'
require_line 'run: ./scripts/check-deps.sh'
require_line 'go-version-file: go.mod'
# The workflow must be a single action so "all checks passed" has one meaning.
jobs="$(awk '/^jobs:/{j=1;next} j && /^ [a-z0-9_-]+:$/{n++} END{print n+0}' "$workflow")"
if [ "$jobs" -ne 1 ]; then
echo "workflow must define exactly one job, found $jobs" >&2
failures=$((failures + 1))
fi
if [ "$failures" -ne 0 ]; then
exit 1
fi
echo 'ok: the pull request workflow runs the repository checks'