From 1fbb05339c52c9263848f248fc80d6e83ae0cd7b Mon Sep 17 00:00:00 2001 From: software-maintainer Date: Wed, 28 Oct 2026 07:45:30 +0000 Subject: [PATCH 1/4] Upgrade Go toolchain pins and add Gitea Actions CI checks Bump the go directive and mise tool pin to Go 1.27.1, the newest toolchain available in the build environment; module versions already resolve to the newest releases present in the pinned module cache. Add .gitea/workflows/ci.yml, which runs on every pull request and every push to main and invokes scripts/check.sh (gofmt, go mod verify, go vet, go build, go test -cover). Also cover the Gitea client token/slug handling with unit tests and document the CI workflow. Add the mise check task so the CI checks can be run locally. --- .gitea/workflows/ci.yml | 23 ++++++++ docs/workflow.md | 24 ++++++++- go.mod | 2 +- internal/gitea/gitea_test.go | 100 +++++++++++++++++++++++++++++++++++ mise.toml | 6 ++- scripts/check.sh | 29 ++++++++++ 6 files changed, 181 insertions(+), 3 deletions(-) create mode 100644 .gitea/workflows/ci.yml create mode 100644 internal/gitea/gitea_test.go create mode 100755 scripts/check.sh diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..eac1fae --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,23 @@ +name: ci + +on: + pull_request: + push: + branches: [main] + +jobs: + check: + name: build and test + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: false + + - name: Run checks + run: ./scripts/check.sh diff --git a/docs/workflow.md b/docs/workflow.md index 90b4c25..52bc521 100644 --- a/docs/workflow.md +++ b/docs/workflow.md @@ -18,6 +18,28 @@ It works with any project type and supports monorepos. --- +## Continuous Integration + +Every pull request and every push to `main` runs the `ci` workflow in +[`.gitea/workflows/ci.yml`](../.gitea/workflows/ci.yml). Its single `check` job +runs [`scripts/check.sh`](../scripts/check.sh), which: + +1. fails if any Go file is not `gofmt`-formatted, +2. runs `go mod verify` to confirm the dependency modules match `go.sum`, +3. runs `go vet ./...` and `go build ./...`, +4. runs `go test -cover ./...`. + +Run the same checks locally with: + +```sh +./scripts/check.sh +``` + +The job fails when any check fails, so a pull request cannot land with broken +code or tests. + +--- + ## Two Release Workflows ### Direct release @@ -483,4 +505,4 @@ Tag format: `@v` for monorepos (e.g. `my-app@v1.3.0`), or `v gofmt' +unformatted="$(gofmt -l .)" +if [ -n "$unformatted" ]; then + echo 'These files are not gofmt-formatted:' >&2 + printf '%s\n' "$unformatted" >&2 + exit 1 +fi + +echo '==> go mod verify' +go mod verify + +echo '==> go vet' +go vet ./... + +echo '==> go build' +go build ./... + +echo '==> go test' +go test -cover ./... -- 2.54.0 From 22e4c961929acfff3483732252e3dbedab7d1d24 Mon Sep 17 00:00:00 2001 From: software-maintainer Date: Wed, 28 Oct 2026 07:45:30 +0000 Subject: [PATCH 2/4] Upgrade Go toolchain pins and add Gitea Actions CI checks Bump the go directive and mise tool pin to Go 1.27.1, the newest toolchain available in the build environment; all module pins already resolve to the newest versions present in the pinned module source. Add scripts/check-deps.sh, which fails when go.mod pins an old module. It uses `go list -m -u` when the module proxy is reachable and falls back to comparing pins against the newest version in the local module cache for offline builds. Expose it as the `mise run deps` task and document it. Add .gitea/workflows/ci.yml, which runs on every pull request and every push to main and invokes scripts/check.sh (gofmt, go mod verify, go vet, go build, go test -cover). Also cover the Gitea client token/slug handling with unit tests and document the CI workflow. Add the mise check task so the CI checks can be run locally. --- .gitea/workflows/ci.yml | 23 ++++++++ docs/workflow.md | 28 +++++++++- go.mod | 2 +- internal/gitea/gitea_test.go | 100 +++++++++++++++++++++++++++++++++++ mise.toml | 10 +++- scripts/check-deps.sh | 74 ++++++++++++++++++++++++++ scripts/check.sh | 29 ++++++++++ 7 files changed, 263 insertions(+), 3 deletions(-) create mode 100644 .gitea/workflows/ci.yml create mode 100644 internal/gitea/gitea_test.go create mode 100755 scripts/check-deps.sh create mode 100755 scripts/check.sh diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..eac1fae --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,23 @@ +name: ci + +on: + pull_request: + push: + branches: [main] + +jobs: + check: + name: build and test + runs-on: ubuntu-latest + steps: + - name: Check out repository + uses: actions/checkout@v4 + + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: false + + - name: Run checks + run: ./scripts/check.sh diff --git a/docs/workflow.md b/docs/workflow.md index 90b4c25..d1582fe 100644 --- a/docs/workflow.md +++ b/docs/workflow.md @@ -18,6 +18,32 @@ It works with any project type and supports monorepos. --- +## Continuous Integration + +Every pull request and every push to `main` runs the `ci` workflow in +[`.gitea/workflows/ci.yml`](../.gitea/workflows/ci.yml). Its single `check` job +runs [`scripts/check.sh`](../scripts/check.sh), which: + +1. fails if any Go file is not `gofmt`-formatted, +2. runs `go mod verify` to confirm the dependency modules match `go.sum`, +3. runs `go vet ./...` and `go build ./...`, +4. runs `go test -cover ./...`. + +Run the same checks locally with: + +```sh +./scripts/check.sh +``` + +The job fails when any check fails, so a pull request cannot land with broken +code or tests. + +Dependency freshness is checked separately with `mise run deps` (or +[`scripts/check-deps.sh`](../scripts/check-deps.sh)), which fails when a module +pinned in `go.mod` has a newer release available. + +--- + ## Two Release Workflows ### Direct release @@ -483,4 +509,4 @@ Tag format: `@v` for monorepos (e.g. `my-app@v1.3.0`), or `v module graph is loadable' +go list -m -e all >/dev/null + +echo '==> modules are up to date' +updates="$(go list -m -u -e -f '{{.Path}} {{.Version}} {{if .Update}}{{.Update.Version}}{{end}}' all | awk 'NF == 3')" +if [ -n "$updates" ]; then + echo 'These modules have newer versions available:' >&2 + printf '%s\n' "$updates" >&2 + exit 1 +fi + +if [ "$(go env GOPROXY)" != "off" ]; then + exit 0 +fi + +# The module proxy is disabled, so `go list -m -u` cannot report updates. +# Compare the pins in go.mod with the versions in the local module cache. +cache="$(go env GOMODCACHE)/cache/download" + +# escape_path applies the case encoding used by the module cache for paths that +# contain 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" +} + +checked=0 +stale='' +while read -r path version; do + list="$cache/$(escape_path "$path")/@v/list" + if [ ! -f "$list" ]; then + continue + fi + checked=$((checked + 1)) + latest="$(sort -V "$list" | tail -n 1)" + if [ "$latest" != "$version" ]; then + stale+="$path $version (newest in cache: $latest)"$'\n' + fi +done < <(go mod edit -json | awk -F'"' '/"Path":/ { path = $4 } /"Version":/ { print path, $4 }') + +if [ -n "$stale" ]; then + echo 'These go.mod pins are not the newest cached versions:' >&2 + printf '%s' "$stale" >&2 + exit 1 +fi + +if [ "$checked" -eq 0 ]; then + echo 'note: proxy disabled and module cache is empty; freshness not checked' >&2 +else + echo "all $checked go.mod pins match the newest versions in the module cache" +fi diff --git a/scripts/check.sh b/scripts/check.sh new file mode 100755 index 0000000..73569a9 --- /dev/null +++ b/scripts/check.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash +# +# check.sh runs every verification step required before a change can land. +# `.gitea/workflows/ci.yml` invokes it on every pull request and every push to +# main, so this script is the single source of truth for what "CI passed" means. + +set -euo pipefail + +cd "$(dirname "${BASH_SOURCE[0]}")/.." + +echo '==> gofmt' +unformatted="$(gofmt -l .)" +if [ -n "$unformatted" ]; then + echo 'These files are not gofmt-formatted:' >&2 + printf '%s\n' "$unformatted" >&2 + exit 1 +fi + +echo '==> go mod verify' +go mod verify + +echo '==> go vet' +go vet ./... + +echo '==> go build' +go build ./... + +echo '==> go test' +go test -cover ./... -- 2.54.0 From 050936c6fd7d02469d32610993eff796ec2013bf Mon Sep 17 00:00:00 2001 From: software-maintainer Date: Wed, 28 Oct 2026 08:57:55 +0000 Subject: [PATCH 3/4] Make dependency checks offline-safe and guard the CI workflow with tests scripts/check-deps.sh previously ran `go list -m all`, which fails with "module lookup disabled by GOPROXY=off" whenever the module cache does not hold the full module graph, even though the build only needs part of it. Read the pins with `go mod edit -json` instead: the online branch asks the module proxy about only the pinned modules, and the offline branch compares those pins with the newest versions in the module cache. Neither path loads the whole graph, and an empty cache is reported instead of failing. Run the dependency check from the single check job that already gates pull requests, so one action covers both the code/tests and dependency freshness. Add internal/ci tests that parse .gitea/workflows/ci.yml, fail if the workflow stops running on pull requests or stops invoking the check scripts, and fail if those scripts are not executable. Document the two-step job and the new mise tasks. --- .gitea/workflows/ci.yml | 4 ++ README.md | 9 ++- docs/workflow.md | 28 +++++---- internal/ci/workflow_test.go | 113 +++++++++++++++++++++++++++++++++ scripts/check-deps.sh | 118 +++++++++++++++++++++++++---------- 5 files changed, 225 insertions(+), 47 deletions(-) create mode 100644 internal/ci/workflow_test.go diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index eac1fae..2eeac69 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -9,6 +9,7 @@ jobs: check: name: build and test runs-on: ubuntu-latest + timeout-minutes: 20 steps: - name: Check out repository uses: actions/checkout@v4 @@ -21,3 +22,6 @@ jobs: - name: Run checks run: ./scripts/check.sh + + - name: Check dependency freshness + run: ./scripts/check-deps.sh diff --git a/README.md b/README.md index e82115b..09493af 100644 --- a/README.md +++ b/README.md @@ -524,6 +524,12 @@ mise run lint # Install locally mise run install + +# Run the same checks CI runs (format, vet, build, tests) +mise run check + +# Check that every dependency in go.mod is the newest release +mise run deps ``` ## Project Structure @@ -534,6 +540,7 @@ stamp/ ├── internal/ │ ├── changeset/ # Stamp file parsing, writing, and slug generation │ ├── changelog/ # CHANGELOG.md generation and appending +│ ├── ci/ # Checks for the repository CI workflow │ ├── config/ # stamp.toml loading, validation, and saving │ ├── git/ # Git operations (tag, commit, push, branch management) │ ├── gitea/ # Gitea API client (releases, PR comments, release PRs) @@ -549,4 +556,4 @@ stamp/ ## License -MIT \ No newline at end of file +MIT diff --git a/docs/workflow.md b/docs/workflow.md index d1582fe..ecad8b4 100644 --- a/docs/workflow.md +++ b/docs/workflow.md @@ -21,26 +21,30 @@ It works with any project type and supports monorepos. ## Continuous Integration Every pull request and every push to `main` runs the `ci` workflow in -[`.gitea/workflows/ci.yml`](../.gitea/workflows/ci.yml). Its single `check` job -runs [`scripts/check.sh`](../scripts/check.sh), which: +[`.gitea/workflows/ci.yml`](../.gitea/workflows/ci.yml). It has a single `check` +job with two steps: -1. fails if any Go file is not `gofmt`-formatted, -2. runs `go mod verify` to confirm the dependency modules match `go.sum`, -3. runs `go vet ./...` and `go build ./...`, -4. runs `go test -cover ./...`. +1. [`scripts/check.sh`](../scripts/check.sh) fails if any Go file is not + `gofmt`-formatted, then runs `go mod verify`, `go vet ./...`, + `go build ./...`, and `go test -cover ./...`. +2. [`scripts/check-deps.sh`](../scripts/check-deps.sh) fails when a module + pinned in `go.mod` has a newer release. It asks the module proxy for the + newest release and falls back to the newest versions in the local module + cache when the proxy is disabled. + +The job fails when any check fails, so a pull request cannot land with broken +code or tests, or with stale dependencies. Run the same checks locally with: ```sh ./scripts/check.sh +./scripts/check-deps.sh # or: mise run deps ``` -The job fails when any check fails, so a pull request cannot land with broken -code or tests. - -Dependency freshness is checked separately with `mise run deps` (or -[`scripts/check-deps.sh`](../scripts/check-deps.sh)), which fails when a module -pinned in `go.mod` has a newer release available. +[`internal/ci/workflow_test.go`](../internal/ci/workflow_test.go) parses the +workflow and fails `go test ./...` if it stops running on pull requests or +stops invoking those scripts. --- diff --git a/internal/ci/workflow_test.go b/internal/ci/workflow_test.go new file mode 100644 index 0000000..86bc1ac --- /dev/null +++ b/internal/ci/workflow_test.go @@ -0,0 +1,113 @@ +// Package ci tests the repository's Gitea Actions configuration. +package ci + +import ( + "os" + "path/filepath" + "sort" + "testing" + + "gopkg.in/yaml.v3" +) + +// workflowPath is the workflow that gates every pull request. +const workflowPath = "../../.gitea/workflows/ci.yml" + +func TestPullRequestWorkflow(t *testing.T) { + data, err := os.ReadFile(filepath.FromSlash(workflowPath)) + if err != nil { + t.Fatalf("read %s: %v", workflowPath, err) + } + + var doc yaml.Node + if err := yaml.Unmarshal(data, &doc); err != nil { + t.Fatalf("parse %s: %v", workflowPath, err) + } + if len(doc.Content) != 1 || doc.Content[0].Kind != yaml.MappingNode { + t.Fatalf("%s must be a single YAML mapping", workflowPath) + } + + workflow := mapping(doc.Content[0]) + on := workflow["on"] + if on == nil { + t.Fatal("workflow has no on: trigger") + } + if mapping(on)["pull_request"] == nil { + t.Error("workflow must run on every pull request") + } + + jobsNode := workflow["jobs"] + if jobsNode == nil { + t.Fatal("workflow has no jobs") + } + jobs := mapping(jobsNode) + if len(jobs) != 1 { + t.Errorf("workflow must be one action, got %d jobs: %v", len(jobs), keys(jobs)) + } + + job := jobs["check"] + if job == nil { + t.Fatalf("workflow has no check job, got %v", keys(jobs)) + } + if got := scalar(mapping(job)["runs-on"]); got == "" { + t.Error("check job has no runs-on label") + } + + steps := mapping(job)["steps"] + if steps == nil || steps.Kind != yaml.SequenceNode { + t.Fatal("check job has no steps") + } + + runs := map[string]bool{} + for _, step := range steps.Content { + runs[scalar(mapping(step)["run"])] = true + } + for _, script := range []string{"./scripts/check.sh", "./scripts/check-deps.sh"} { + if !runs[script] { + t.Errorf("check job does not run %s", script) + } + } +} + +// mapping returns the mapping nodes of n keyed by their scalar key. +func mapping(n *yaml.Node) map[string]*yaml.Node { + out := map[string]*yaml.Node{} + if n == nil || n.Kind != yaml.MappingNode { + return out + } + for i := 0; i < len(n.Content)-1; i += 2 { + out[n.Content[i].Value] = n.Content[i+1] + } + return out +} + +// scalar returns the value of a scalar node, or the empty string. +func scalar(n *yaml.Node) string { + if n == nil || n.Kind != yaml.ScalarNode { + return "" + } + return n.Value +} + +// keys returns the sorted keys of m for error messages. +func keys(m map[string]*yaml.Node) []string { + out := make([]string, 0, len(m)) + for k := range m { + out = append(out, k) + } + sort.Strings(out) + return out +} + +func TestCheckScriptsAreExecutable(t *testing.T) { + for _, script := range []string{"../../scripts/check.sh", "../../scripts/check-deps.sh"} { + info, err := os.Stat(filepath.FromSlash(script)) + if err != nil { + t.Errorf("stat %s: %v", script, err) + continue + } + if info.Mode()&0o111 == 0 { + t.Errorf("%s is not executable; the ci workflow runs it directly", script) + } + } +} diff --git a/scripts/check-deps.sh b/scripts/check-deps.sh index 44a6ed2..8c24cf3 100755 --- a/scripts/check-deps.sh +++ b/scripts/check-deps.sh @@ -1,39 +1,32 @@ #!/usr/bin/env bash # -# check-deps.sh verifies that every module pinned in go.mod is the newest +# check-deps.sh fails when a module required by go.mod is not the newest # version available. # -# When the module proxy is reachable, `go list -m -u` is authoritative and any -# module with a newer release fails the check. When the proxy is disabled (for -# example in an offline build), the script falls back to comparing each pin -# with the newest version present in the local module cache, which still -# catches pins that were left behind after a newer version was downloaded. +# 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. +# +# The script never loads the full module graph, so it works even when the cache +# only holds the modules needed by the build. set -euo pipefail cd "$(dirname "${BASH_SOURCE[0]}")/.." -echo '==> module graph is loadable' -go list -m -e all >/dev/null +# requirements prints " " for every module required by go.mod. +requirements() { + go mod edit -json | awk -F'"' ' + /^\t"Require": \[/ { in_require = 1 } + in_require && /^\t\],?$/ { in_require = 0 } + in_require && /"Path":/ { path = $4 } + in_require && /"Version":/ { print path, $4 } + ' +} -echo '==> modules are up to date' -updates="$(go list -m -u -e -f '{{.Path}} {{.Version}} {{if .Update}}{{.Update.Version}}{{end}}' all | awk 'NF == 3')" -if [ -n "$updates" ]; then - echo 'These modules have newer versions available:' >&2 - printf '%s\n' "$updates" >&2 - exit 1 -fi - -if [ "$(go env GOPROXY)" != "off" ]; then - exit 0 -fi - -# The module proxy is disabled, so `go list -m -u` cannot report updates. -# Compare the pins in go.mod with the versions in the local module cache. -cache="$(go env GOMODCACHE)/cache/download" - -# escape_path applies the case encoding used by the module cache for paths that -# contain upper-case letters (for example BurntSushi becomes !burnt!sushi). +# 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 @@ -47,28 +40,85 @@ escape_path() { 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" +} + +pins="$(requirements)" +if [ -z "$pins" ]; then + echo 'go.mod requires no modules' >&2 + exit 1 +fi + +count="$(printf '%s\n' "$pins" | wc -l | tr -d ' ')" + +if [ "$(go env GOPROXY)" != "off" ]; then + mods=() + while read -r path version; do + mods+=("$path@$version") + done <<<"$pins" + + 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 + fi + updates="$(printf '%s\n' "$listing" | awk 'NF == 3')" + if [ -n "$updates" ]; then + echo 'These modules have newer versions available:' >&2 + printf '%s\n' "$updates" >&2 + exit 1 + fi + echo "ok: $count go.mod requirements are up to date" + exit 0 +fi + +cache="$(go env GOMODCACHE)/cache/download" checked=0 +unchecked=0 stale='' while read -r path version; do list="$cache/$(escape_path "$path")/@v/list" if [ ! -f "$list" ]; then + unchecked=$((unchecked + 1)) continue fi checked=$((checked + 1)) - latest="$(sort -V "$list" | tail -n 1)" - if [ "$latest" != "$version" ]; then - stale+="$path $version (newest in cache: $latest)"$'\n' + latest="$(newest <"$list")" + if [ "$latest" = "$version" ]; then + continue fi -done < <(go mod edit -json | awk -F'"' '/"Path":/ { path = $4 } /"Version":/ { print path, $4 }') + # 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' + fi +done <<<"$pins" if [ -n "$stale" ]; then - echo 'These go.mod pins are not the newest cached versions:' >&2 + echo 'These go.mod pins are behind the newest cached version:' >&2 printf '%s' "$stale" >&2 exit 1 fi if [ "$checked" -eq 0 ]; then - echo 'note: proxy disabled and module cache is empty; freshness not checked' >&2 -else - echo "all $checked go.mod pins match the newest versions in the module cache" + echo "note: GOPROXY=off and $cache is empty; dependency freshness was not checked" >&2 + exit 0 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" -- 2.54.0 From c098c93ae965134b65d15184249f19a8fea90cc8 Mon Sep 17 00:00:00 2001 From: software-maintainer Date: Wed, 28 Oct 2026 09:59:57 +0000 Subject: [PATCH 4/4] Upgrade module pins to newest releases and make dependency checks authoritative 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. --- docs/workflow.md | 17 +++- go.mod | 51 ++++++----- go.sum | 100 +++++++++++++++++++- mise.toml | 2 +- scripts/check-deps.sh | 178 +++++++++++++++++++++++------------- scripts/check.sh | 6 ++ scripts/test-check-deps.sh | 104 +++++++++++++++++++++ scripts/test-ci-workflow.sh | 44 +++++++++ 8 files changed, 405 insertions(+), 97 deletions(-) create mode 100755 scripts/test-check-deps.sh create mode 100755 scripts/test-ci-workflow.sh diff --git a/docs/workflow.md b/docs/workflow.md index ecad8b4..7053087 100644 --- a/docs/workflow.md +++ b/docs/workflow.md @@ -24,13 +24,18 @@ Every pull request and every push to `main` runs the `ci` workflow in [`.gitea/workflows/ci.yml`](../.gitea/workflows/ci.yml). It has a single `check` job with two steps: -1. [`scripts/check.sh`](../scripts/check.sh) fails if any Go file is not - `gofmt`-formatted, then runs `go mod verify`, `go vet ./...`, +1. [`scripts/check.sh`](../scripts/check.sh) first validates the workflow and + the dependency-policy scripts themselves, then fails if any Go file is not + `gofmt`-formatted, and finally runs `go mod verify`, `go vet ./...`, `go build ./...`, and `go test -cover ./...`. 2. [`scripts/check-deps.sh`](../scripts/check-deps.sh) fails when a module pinned in `go.mod` has a newer release. It asks the module proxy for the - newest release and falls back to the newest versions in the local module - cache when the proxy is disabled. + newest release of every pinned module. When the proxy is disabled it uses + the dependency facts prepared by the execution profile (the file named by + `MAINTAINER_DEPENDENCY_FACTS`), which record the newest release observed on + `proxy.golang.org` and when. If neither source is available the script + exits with status 2 instead of assuming the pins are current; the local + module cache is never used as evidence of what the newest release is. The job fails when any check fails, so a pull request cannot land with broken code or tests, or with stale dependencies. @@ -44,7 +49,9 @@ Run the same checks locally with: [`internal/ci/workflow_test.go`](../internal/ci/workflow_test.go) parses the workflow and fails `go test ./...` if it stops running on pull requests or -stops invoking those scripts. +stops invoking those scripts; [`scripts/test-ci-workflow.sh`](../scripts/test-ci-workflow.sh) +and [`scripts/test-check-deps.sh`](../scripts/test-check-deps.sh) cover the same +behaviour without needing a Go module download. --- diff --git a/go.mod b/go.mod index 79db0c4..7781e23 100644 --- a/go.mod +++ b/go.mod @@ -3,46 +3,51 @@ module git.thokra.dev/thokra/stamp go 1.27.1 require ( - code.gitea.io/sdk/gitea v0.23.2 + code.gitea.io/sdk/gitea v0.25.1 github.com/BurntSushi/toml v1.6.0 - github.com/Masterminds/semver/v3 v3.4.0 + github.com/Masterminds/semver/v3 v3.5.0 + github.com/charmbracelet/huh v1.0.0 github.com/google/go-github/v70 v70.0.0 - github.com/urfave/cli/v3 v3.7.0 + github.com/urfave/cli/v3 v3.14.0 gopkg.in/yaml.v3 v3.0.1 ) require ( - github.com/42wim/httpsig v1.2.3 // indirect + github.com/42wim/httpsig v1.3.0 // indirect github.com/atotto/clipboard v0.1.4 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect + github.com/bits-and-blooms/bitset v1.27.0 // indirect github.com/catppuccin/go v0.3.0 // indirect - github.com/charmbracelet/bubbles v0.21.1-0.20250623103423-23b8fd6302d7 // indirect - github.com/charmbracelet/bubbletea v1.3.6 // indirect - github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc // indirect - github.com/charmbracelet/huh v1.0.0 // indirect + github.com/charmbracelet/bubbles v1.0.0 // indirect + github.com/charmbracelet/bubbletea v1.3.10 // indirect + github.com/charmbracelet/colorprofile v0.4.3 // indirect github.com/charmbracelet/lipgloss v1.1.0 // indirect - github.com/charmbracelet/x/ansi v0.9.3 // indirect - github.com/charmbracelet/x/cellbuf v0.0.13 // indirect - github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 // indirect - github.com/charmbracelet/x/term v0.2.1 // indirect + github.com/charmbracelet/x/ansi v0.11.9 // indirect + github.com/charmbracelet/x/cellbuf v0.0.15 // indirect + github.com/charmbracelet/x/exp/strings v0.1.0 // indirect + github.com/charmbracelet/x/term v0.2.2 // indirect + github.com/clipperhouse/displaywidth v0.11.0 // indirect + github.com/clipperhouse/stringish v0.1.1 // indirect + github.com/clipperhouse/uax29/v2 v2.7.0 // indirect github.com/davidmz/go-pageant v1.0.2 // indirect - github.com/dustin/go-humanize v1.0.1 // indirect + github.com/dustin/go-humanize v1.1.0 // indirect github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect github.com/go-fed/httpsig v1.1.0 // indirect - github.com/google/go-querystring v1.1.0 // indirect - github.com/hashicorp/go-version v1.7.0 // indirect - github.com/lucasb-eyer/go-colorful v1.2.0 // indirect - github.com/mattn/go-isatty v0.0.20 // indirect + go.yaml.in/yaml/v3 v3.0.5 // indirect + github.com/google/go-querystring v1.2.0 // indirect + github.com/hashicorp/go-version v1.9.0 // indirect + github.com/lucasb-eyer/go-colorful v1.4.1 // indirect + github.com/mattn/go-isatty v0.0.24 // indirect github.com/mattn/go-localereader v0.0.1 // indirect - github.com/mattn/go-runewidth v0.0.16 // indirect + github.com/mattn/go-runewidth v0.0.31 // indirect github.com/mitchellh/hashstructure/v2 v2.0.2 // indirect github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 // indirect github.com/muesli/cancelreader v0.2.2 // indirect github.com/muesli/termenv v0.16.0 // indirect github.com/rivo/uniseg v0.4.7 // indirect - github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect - golang.org/x/crypto v0.39.0 // indirect - golang.org/x/sync v0.15.0 // indirect - golang.org/x/sys v0.33.0 // indirect - golang.org/x/text v0.26.0 // indirect + github.com/xo/terminfo v1.2.0 // indirect + golang.org/x/crypto v0.58.0 // indirect + golang.org/x/sync v0.24.0 // indirect + golang.org/x/sys v0.49.0 // indirect + golang.org/x/text v0.43.0 // indirect ) diff --git a/go.sum b/go.sum index 5b561d3..3517efe 100644 --- a/go.sum +++ b/go.sum @@ -1,62 +1,124 @@ code.gitea.io/sdk/gitea v0.23.2 h1:iJB1FDmLegwfwjX8gotBDHdPSbk/ZR8V9VmEJaVsJYg= code.gitea.io/sdk/gitea v0.23.2/go.mod h1:yyF5+GhljqvA30sRDreoyHILruNiy4ASufugzYg0VHM= +code.gitea.io/sdk/gitea v0.25.1 h1:yywxWwoV+SdjHtbC6unBiXojWdZOtoHuGhEazEXeWuE= +code.gitea.io/sdk/gitea v0.25.1/go.mod h1:uDFWYBU8dgZsgOHwe6C/6olxvf8FHguNB3wW1i83fgg= github.com/42wim/httpsig v1.2.3 h1:xb0YyWhkYj57SPtfSttIobJUPJZB9as1nsfo7KWVcEs= github.com/42wim/httpsig v1.2.3/go.mod h1:nZq9OlYKDrUBhptd77IHx4/sZZD+IxTBADvAPI9G/EM= +github.com/42wim/httpsig v1.3.0 h1:HK2bieeZ99X9IvOoc1ST6yrhLek0f4MqlEGES2JCP3g= +github.com/42wim/httpsig v1.3.0/go.mod h1:lgC3Yrvp4lxi1odEF1ge3kQBu/VM+SRcZQu5YwiR3dU= github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk= github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= +github.com/MakeNowJust/heredoc v1.0.0 h1:cXCdzVdstXyiTqTvfqk9SDHpKNjxuom+DOlyEeQ4pzQ= +github.com/MakeNowJust/heredoc v1.0.0/go.mod h1:mG5amYoWBHf8vpLOuehzbGGw0EHxpZZ6lCpQ4fNJ8LE= github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0= github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= +github.com/Masterminds/semver/v3 v3.5.0 h1:kQceYJfbupGfZOKZQg0kou0DgAKhzDg2NZPAwZ/2OOE= +github.com/Masterminds/semver/v3 v3.5.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= +github.com/aymanbagabas/go-udiff v0.4.1 h1:OEIrQ8maEeDBXQDoGCbbTTXYJMYRCRO1fnodZ12Gv5o= +github.com/aymanbagabas/go-udiff v0.4.1/go.mod h1:0L9PGwj20lrtmEMeyw4WKJ/TMyDtvAoK9bf2u/mNo3w= +github.com/bits-and-blooms/bitset v1.27.0 h1:0s3FwmJRlxOqUsmQK+a8/HcPMgPu8jM7KrE/y/X7d+8= +github.com/bits-and-blooms/bitset v1.27.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/catppuccin/go v0.3.0 h1:d+0/YicIq+hSTo5oPuRi5kOpqkVA5tAsU6dNhvRu+aY= github.com/catppuccin/go v0.3.0/go.mod h1:8IHJuMGaUUjQM82qBrGNBv7LFq6JI3NnQCF6MOlZjpc= github.com/charmbracelet/bubbles v0.21.1-0.20250623103423-23b8fd6302d7 h1:JFgG/xnwFfbezlUnFMJy0nusZvytYysV4SCS2cYbvws= github.com/charmbracelet/bubbles v0.21.1-0.20250623103423-23b8fd6302d7/go.mod h1:ISC1gtLcVilLOf23wvTfoQuYbW2q0JevFxPfUzZ9Ybw= +github.com/charmbracelet/bubbles v1.0.0 h1:12J8/ak/uCZEMQ6KU7pcfwceyjLlWsDLAxB5fXonfvc= +github.com/charmbracelet/bubbles v1.0.0/go.mod h1:9d/Zd5GdnauMI5ivUIVisuEm3ave1XwXtD1ckyV6r3E= +github.com/charmbracelet/bubbletea v1.3.10 h1:otUDHWMMzQSB0Pkc87rm691KZ3SWa4KUlvF9nRvCICw= +github.com/charmbracelet/bubbletea v1.3.10/go.mod h1:ORQfo0fk8U+po9VaNvnV95UPWA1BitP1E0N6xJPlHr4= github.com/charmbracelet/bubbletea v1.3.6 h1:VkHIxPJQeDt0aFJIsVxw8BQdh/F/L2KKZGsK6et5taU= github.com/charmbracelet/bubbletea v1.3.6/go.mod h1:oQD9VCRQFF8KplacJLo28/jofOI2ToOfGYeFgBBxHOc= github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc h1:4pZI35227imm7yK2bGPcfpFEmuY1gc2YSTShr4iJBfs= github.com/charmbracelet/colorprofile v0.2.3-0.20250311203215-f60798e515dc/go.mod h1:X4/0JoqgTIPSFcRA/P6INZzIuyqdFY5rm8tb41s9okk= +github.com/charmbracelet/colorprofile v0.4.3 h1:QPa1IWkYI+AOB+fE+mg/5/4HRMZcaXex9t5KX76i20Q= +github.com/charmbracelet/colorprofile v0.4.3/go.mod h1:/zT4BhpD5aGFpqQQqw7a+VtHCzu+zrQtt1zhMt9mR4Q= +github.com/charmbracelet/harmonica v0.2.0 h1:8NxJWRWg/bzKqqEaaeFNipOu77YR5t8aSwG4pgaUBiQ= +github.com/charmbracelet/harmonica v0.2.0/go.mod h1:KSri/1RMQOZLbw7AHqgcBycp8pgJnQMYYT8QZRqZ1Ao= github.com/charmbracelet/huh v1.0.0 h1:wOnedH8G4qzJbmhftTqrpppyqHakl/zbbNdXIWJyIxw= github.com/charmbracelet/huh v1.0.0/go.mod h1:5YVc+SlZ1IhQALxRPpkGwwEKftN/+OlJlnJYlDRFqN4= github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY= github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30= +github.com/charmbracelet/x/ansi v0.11.9 h1:kIrqLBxtTVbLyyHO2Evoi93EjQo1mylWmpNEsfPxXAM= +github.com/charmbracelet/x/ansi v0.11.9/go.mod h1:DG/hpOnaI2QJ/KMMqLL2h0KVhluuJLazf8973P+Vy5w= github.com/charmbracelet/x/ansi v0.9.3 h1:BXt5DHS/MKF+LjuK4huWrC6NCvHtexww7dMayh6GXd0= github.com/charmbracelet/x/ansi v0.9.3/go.mod h1:3RQDQ6lDnROptfpWuUVIUG64bD2g2BgntdxH0Ya5TeE= github.com/charmbracelet/x/cellbuf v0.0.13 h1:/KBBKHuVRbq1lYx5BzEHBAFBP8VcQzJejZ/IA3iR28k= github.com/charmbracelet/x/cellbuf v0.0.13/go.mod h1:xe0nKWGd3eJgtqZRaN9RjMtK7xUYchjzPr7q6kcvCCs= +github.com/charmbracelet/x/cellbuf v0.0.15 h1:ur3pZy0o6z/R7EylET877CBxaiE1Sp1GMxoFPAIztPI= +github.com/charmbracelet/x/cellbuf v0.0.15/go.mod h1:J1YVbR7MUuEGIFPCaaZ96KDl5NoS0DAWkskup+mOY+Q= +github.com/charmbracelet/x/conpty v0.2.0 h1:eKtA2hm34qNfgJCDp/M6Dc0gLy7e07YEK4qAdNGOvVY= +github.com/charmbracelet/x/conpty v0.2.0/go.mod h1:fexgUnVrZgw8scD49f6VSi0Ggj9GWYIrpedRthAwW/8= +github.com/charmbracelet/x/errors v0.0.0-20261025003702-835ad0048169 h1:lmV1ffak03cvDgvVSP1wAWD8Y745Npt8nN2f2vBjJYk= +github.com/charmbracelet/x/errors v0.0.0-20261025003702-835ad0048169/go.mod h1:O2BTD/aMVQDmrvqroIO3fB6zXUuU07ZpVt21QTmZjRg= +github.com/charmbracelet/x/exp/golden v0.1.0 h1:qgUxGaHX4I8Fg077vD+54+qFmDWrgO19lTCQLblHWko= +github.com/charmbracelet/x/exp/golden v0.1.0/go.mod h1:6fMpcW6iwN/kX+xJ52eqVWsDiBTe0UJD24JLoHFe+P0= github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0 h1:qko3AQ4gK1MTS/de7F5hPGx6/k1u0w4TeYmBFwzYVP4= github.com/charmbracelet/x/exp/strings v0.0.0-20240722160745-212f7b056ed0/go.mod h1:pBhA0ybfXv6hDjQUZ7hk1lVxBiUbupdw5R31yPUViVQ= +github.com/charmbracelet/x/exp/strings v0.1.0 h1:i69S2XI7uG1u4NLGeJPSYU++Nmjvpo9nwd6aoEm7gkA= +github.com/charmbracelet/x/exp/strings v0.1.0/go.mod h1:/ehtMPNh9K4odGFkqYJKpIYyePhdp1hLBRvyY4bWkH8= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= +github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk= +github.com/charmbracelet/x/term v0.2.2/go.mod h1:kF8CY5RddLWrsgVwpw4kAa6TESp6EB5y3uxGLeCqzAI= +github.com/charmbracelet/x/termios v0.1.1 h1:o3Q2bT8eqzGnGPOYheoYS8eEleT5ZVNYNy8JawjaNZY= +github.com/charmbracelet/x/termios v0.1.1/go.mod h1:rB7fnv1TgOPOyyKRJ9o+AsTU/vK5WHJ2ivHeut/Pcwo= +github.com/charmbracelet/x/xpty v0.1.4 h1:4jaW7u+8AHQMxesiVc+zUMsspu7GyDwtJO+gy/tFtW4= +github.com/charmbracelet/x/xpty v0.1.4/go.mod h1:7t8P7BpPiolHJ1pLzz7/4ujDbD+sUxI9yA3CBOLOIcU= +github.com/clipperhouse/displaywidth v0.11.0 h1:lBc6kY44VFw+TDx4I8opi/EtL9m20WSEFgwIwO+UVM8= +github.com/clipperhouse/displaywidth v0.11.0/go.mod h1:bkrFNkf81G8HyVqmKGxsPufD3JhNl3dSqnGhOoSD/o0= +github.com/clipperhouse/stringish v0.1.1 h1:+NSqMOr3GR6k1FdRhhnXrLfztGzuG+VuFDfatpWHKCs= +github.com/clipperhouse/stringish v0.1.1/go.mod h1:v/WhFtE1q0ovMta2+m+UbpZ+2/HEXNWYXQgCt4hdOzA= +github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJv2v7Vk= +github.com/clipperhouse/uax29/v2 v2.7.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM= +github.com/creack/pty v1.1.24 h1:bJrF4RRfyJnbTJqzRLHzcGaZK1NeM5kTC9jGgovnR1s= +github.com/creack/pty v1.1.24/go.mod h1:08sCNb52WyoAwi2QDyzUCTgcvVFhUzewun7wtTfvcwE= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davidmz/go-pageant v1.0.2 h1:bPblRCh5jGU+Uptpz6LgMZGD5hJoOt7otgT454WvHn0= github.com/davidmz/go-pageant v1.0.2/go.mod h1:P2EDDnMqIwG5Rrp05dTRITj9z2zpGcD9efWSkTNKLIE= github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/dustin/go-humanize v1.1.0 h1:dbKTrvD0klcbBV/h4AWJdMuZogJACoMlvWIWZ5b2xWg= +github.com/dustin/go-humanize v1.1.0/go.mod h1:hc1CvRkJMsgxqjmjMQF3QNRAZBwY8AXBAzKYoSX9sFI= github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4= github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM= github.com/go-fed/httpsig v1.1.0 h1:9M+hb0jkEICD8/cAiNqEB66R87tTINszBRTjwjQzWcI= github.com/go-fed/httpsig v1.1.0/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/go-github/v70 v70.0.0 h1:/tqCp5KPrcvqCc7vIvYyFYTiCGrYvaWoYMGHSQbo55o= github.com/google/go-github/v70 v70.0.0/go.mod h1:xBUZgo8MI3lUL/hwxl3hlceJW1U8MVnXP3zUyI+rhQY= github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8= github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU= +github.com/google/go-querystring v1.2.0 h1:yhqkPbu2/OH+V9BfpCVPZkNmUXhb2gBxJArfhIxNtP0= +github.com/google/go-querystring v1.2.0/go.mod h1:8IFJqpSRITyJ8QhQ13bmbeMBDfmeEJZD5A0egEOmkqU= github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY= github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/go-version v1.9.0 h1:CeOIz6k+LoN3qX9Z0tyQrPtiB1DFYRPfCIBtaXPSCnA= +github.com/hashicorp/go-version v1.9.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= +github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/lucasb-eyer/go-colorful v1.4.1 h1:1EO+WB73+EH8EVbzlrG3KLAfEypQWVHIBqlTf+2hNss= +github.com/lucasb-eyer/go-colorful v1.4.1/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.24 h1:tGZZoVgT/KiqK1c8ocVLeDS8BSWMRd47J3Lbz7vsReI= +github.com/mattn/go-isatty v0.0.24/go.mod h1:nMCL3Zebbrt45jsMDgnfIwz6ydEQApk5oEI3HqDio6A= github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mattn/go-runewidth v0.0.31 h1:1oCV4ReTlosDBc6rYRw5cL8S/4y8iv5oRl4SJ5IBgwo= +github.com/mattn/go-runewidth v0.0.31/go.mod h1:3qAiGCV4Koz/yuveO58qUefmUTRm8r0IGEXZ9jeHp/8= github.com/mitchellh/hashstructure/v2 v2.0.2 h1:vGKWl0YJqUNxE8d+h8f6NJLcCJrgbhC4NcD46KavDd4= github.com/mitchellh/hashstructure/v2 v2.0.2/go.mod h1:MG3aRVU/N29oo/V/IhBX8GR/zz4kQkprJgF2EVszyDE= github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI= @@ -70,38 +132,70 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +github.com/sahilm/fuzzy v0.1.3 h1:juByESSS32nVD81vr6tHmKmA/8zde7gE+x5CLxrzXPU= +github.com/sahilm/fuzzy v0.1.3/go.mod h1:au6//VbVSqu6DFrkL2CfjlJ5iURpNCPeE+1GwY3XsT8= github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE= +github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg= +github.com/urfave/cli/v3 v3.14.0 h1:a8414NQlHJs0c/iBsulKLzlES0n/lEAskbL2LKpU4/s= +github.com/urfave/cli/v3 v3.14.0/go.mod h1:vXn6HxPNccJSzQr2QvwVncOKrgYGIHU0HY5h8B2nQj4= github.com/urfave/cli/v3 v3.7.0 h1:AGSnbUyjtLiM+WJUb4dzXKldl/gL+F8OwmRDtVr6g2U= github.com/urfave/cli/v3 v3.7.0/go.mod h1:ysVLtOEmg2tOy6PknnYVhDoouyC/6N42TMeoMzskhso= github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= +github.com/xo/terminfo v1.2.0 h1:d0ZTOCpuGE0lwSAOs0zcJjwz3jWQyqcRt9XbGJpCOl4= +github.com/xo/terminfo v1.2.0/go.mod h1:lGzkSo8Fe7IRh/w+Gqz7n5mDog4FVXCj3gy/DYTBqio= +go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw= +go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8= golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM= golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U= +golang.org/x/crypto v0.58.0 h1:COkYLr4k7nDI4r6QtMML2AfzeIswWHAJthLS6K/M/54= +golang.org/x/crypto v0.58.0/go.mod h1:Xh+kl5A+M0gMiWDytH2Hhr5Z7WbNCpv/eB/EFgfSk+w= +golang.org/x/exp v0.0.0-20261014143641-f0251eb4aa3e h1:HgI6W1OolKK6tcV74is+rl9SMT0njsHlp0TbQiGXI/A= +golang.org/x/exp v0.0.0-20261014143641-f0251eb4aa3e/go.mod h1:DBoxwWhjaW8DJJw/YeM4zpeOKMC1FMXSblsYy+1mFSw= +golang.org/x/mod v0.42.0 h1:ICeL3t2L30ljSPHHxDnR4fqVcBt/zR2zJAb9juavmQg= +golang.org/x/mod v0.42.0/go.mod h1:u5fzIrRInkL8MaO1cbRkUHT64v303YIT5KEqpNr7jRs= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.62.0 h1:18ELalfM5+XNRwzM2nYqXsZQ9ByS1uhj2O/U7+5jqRY= +golang.org/x/net v0.62.0/go.mod h1:WgDCOTH8iwtB66T4/GfI94AHo/hhdb7Hah9NDseQfiI= golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8= golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= +golang.org/x/sync v0.24.0 h1:iqiDrGoDgyuvAKrhLQthUEzU/R378N78gXbBjxed7oA= +golang.org/x/sync v0.24.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw= golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/sys v0.49.0 h1:XbzkgYJHdqh/8m2Uu0W/dQv8nktxx4BFHp1M0gROTXA= +golang.org/x/sys v0.49.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.32.0 h1:DR4lr0TjUs3epypdhTOkMmuF5CDFJ/8pOnbzMZPQ7bg= golang.org/x/term v0.32.0/go.mod h1:uZG1FhGx848Sqfsq4/DlJr3xGGsYMu/L5GW4abiaEPQ= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/term v0.47.0 h1:cpyOwQkr2Nzxe2p6KnrTG7Ei2wtzjsuSjhpXXepZ/BM= +golang.org/x/term v0.47.0/go.mod h1:efAfAuG6RKABvg1ArGebRkvX6LXul14SM67o2e4mUCY= golang.org/x/text v0.26.0 h1:P42AVeLghgTYr4+xUnTRKDMqpar+PtX7KWuNQL21L8M= golang.org/x/text v0.26.0/go.mod h1:QK15LZJUUQVJxhz7wXgxSy/CJaTFjd0G+YLonydOVQA= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.43.0 h1:1QivrlhwAsnMOcqgOdl9my7s9OyZl8O5/UGUTJVXoWc= +golang.org/x/text v0.43.0/go.mod h1:hbSIYA/amXcRXTFSZqh8tWHEoqRvvbKPJ2uz/KU+a+s= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.52.0 h1:ryxg4U63oaUYk7uOLTF37n43f4qgtGvqV4Ioit1BaEs= +golang.org/x/tools v0.52.0/go.mod h1:ItcP5UNaVGG+Yc4eIYmaFLNJ4soEopkx5Y2d4lcEurs= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da h1:noIWHXmPHxILtqtCOPIhSt0ABwskkZKjD3bXGnZGpNY= +golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/mise.toml b/mise.toml index 700c2d9..6cfcffb 100644 --- a/mise.toml +++ b/mise.toml @@ -18,5 +18,5 @@ description = "Run formatting, vet, build, and tests (the same checks CI runs)" run = "./scripts/check.sh" [tasks.deps] -description = "Check that go.mod pins the newest available module versions" +description = "Check go.mod pins against the newest observed module releases" run = "./scripts/check-deps.sh" diff --git a/scripts/check-deps.sh b/scripts/check-deps.sh index 8c24cf3..5851805 100755 --- a/scripts/check-deps.sh +++ b/scripts/check-deps.sh @@ -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 " " 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" diff --git a/scripts/check.sh b/scripts/check.sh index 73569a9..7128232 100755 --- a/scripts/check.sh +++ b/scripts/check.sh @@ -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 diff --git a/scripts/test-check-deps.sh b/scripts/test-check-deps.sh new file mode 100755 index 0000000..de1fa79 --- /dev/null +++ b/scripts/test-check-deps.sh @@ -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: +facts() { + local freshness="$1" + shift + local items='' + local item + for item in "$@"; do + [ -z "$items" ] || items+=',' + items+="$item" + done + cat >"$tmp/facts.json" <&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' diff --git a/scripts/test-ci-workflow.sh b/scripts/test-ci-workflow.sh new file mode 100755 index 0000000..e53b907 --- /dev/null +++ b/scripts/test-ci-workflow.sh @@ -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' -- 2.54.0