From b40db025cc6b133448e644ade8c1ba68f0783fac Mon Sep 17 00:00:00 2001 From: Mathias Date: Thu, 17 Sep 2026 18:04:13 +0200 Subject: [PATCH] fix(template): ship a go.sum, and stop the templ generator drifting from the library Closes #8. `task check` did not pass on a clean checkout of this template, and had not for some time. Three defects in a chain, each hiding the next: 1. No go.sum at all. `go build ./...` failed on missing sum entries, so nothing downstream of it ever ran. 2. With that fixed, the real skew appeared: CI installs the templ GENERATOR as @latest while go.mod pinned the templ LIBRARY at v0.2.778. The v0.3 generator emits calls to templruntime.WriteString, which v0.2.778 does not have -- so generated code could not compile against the pinned runtime. Library moved to v0.3.1020 and the CI install now derives its version from go.mod, so generator and library cannot drift apart again. 3. .gitignore carried `*.templ.go`. templ writes `_templ.go` -- an underscore, not a dot -- so the pattern matched nothing. Generated files were kept out of git by luck rather than by the ignore rule. None of this was visible from this repo's CI, which has been green throughout, because the guard job skips `check` here entirely (#12). A template whose gate cannot run is a template whose defects are found by its children. Verified on a clean checkout: `go build ./...` clean, `task check` exit 0. Co-Authored-By: Claude Opus 5 --- .gitea/workflows/cd.yml | 9 ++++++++- .gitignore | 5 ++++- go.mod | 4 +--- go.sum | 4 ++++ 4 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 go.sum diff --git a/.gitea/workflows/cd.yml b/.gitea/workflows/cd.yml index 36e35b4..9af640c 100644 --- a/.gitea/workflows/cd.yml +++ b/.gitea/workflows/cd.yml @@ -48,7 +48,14 @@ jobs: - name: Install toolchain run: | go version - go install github.com/a-h/templ/cmd/templ@latest + # Pin the GENERATOR to the same version as the templ LIBRARY in + # go.mod. Installing @latest let them drift: the generator emitted + # calls (templruntime.WriteString) that the pinned library did not + # have, which is template-go-web#8. Nothing caught it because the + # guard skipped `check` in this repo entirely (#12). + templ_version="$(go list -m -f '{{.Version}}' github.com/a-h/templ)" + echo "templ library is $templ_version — installing the matching generator" + go install "github.com/a-h/templ/cmd/templ@$templ_version" curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh \ | sh -s -- -b "$(go env GOPATH)/bin" v2.11.4 diff --git a/.gitignore b/.gitignore index 902b7e7..756de3f 100644 --- a/.gitignore +++ b/.gitignore @@ -27,4 +27,7 @@ go.work.sum # Project-specific bin/ -*.templ.go +# templ writes _templ.go -- this was '*.templ.go' (a dot, not an +# underscore) and therefore matched nothing, so generated files were only ever +# kept out of git by luck. template-go-web#8. +*_templ.go diff --git a/go.mod b/go.mod index 198b4ef..131d2d2 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,4 @@ module __MODULE_PATH__ go 1.26 -require ( - github.com/a-h/templ v0.2.778 -) +require github.com/a-h/templ v0.3.1020 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..0857b6f --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/a-h/templ v0.3.1020 h1:ypAT/L5ySWEnZ6Zft/5yfoWXYYkhFNvEFOeeqecg4tw= +github.com/a-h/templ v0.3.1020/go.mod h1:A2DlK61v+K+NRoGnhmYbNYVmtYHcFO5/AisMvBdDxTM= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=