From b9cbda4ff0f9371edd4269ec1676ebb654e7f2bc Mon Sep 17 00:00:00 2001 From: sneak Date: Sun, 4 Oct 2026 02:16:59 +0000 Subject: [PATCH] Fall back to dev when git describe prints nothing (closes #74) The Makefile example in the Go styleguide and in the HTTP server conventions set VERSION from `git describe --tags --always` alone. Outside a git checkout, such as an unpacked source tarball, that prints nothing, so the binary was stamped with an empty version and nothing said so. Both now read `VERSION ?= $(or $(shell git describe --tags --always 2>/dev/null),dev)`, and the comment above each says so. A `VERSION` from the environment or the make command line still takes precedence. Model: opus-5-5 --- TODO.md | 5 +++++ prompts/CODE_STYLEGUIDE_GO.md | 7 ++++--- prompts/GO_HTTP_SERVER_CONVENTIONS.md | 7 ++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/TODO.md b/TODO.md index 1d3ac0e..dd34f90 100644 --- a/TODO.md +++ b/TODO.md @@ -21,6 +21,11 @@ fmt-check, and commit. # Completed Steps +- 2026-10-04: The Makefile examples in the Go styleguide and the HTTP server + conventions now fall back to `dev` when `git describe` prints nothing, as it + does outside a git checkout, instead of stamping an empty version (issue 74). + The canonical `Dockerfile` already fails on a `dev` version when `.git` is in + the build context. - 2026-10-03: Moved the canonical golangci-lint to v2.14.0, built with go1.27, because v2.12.2 refuses to lint a module whose `go` directive is 1.27 (issue 65). Releases from v2.13.0 deprecate `exhaustruct` in favour of diff --git a/prompts/CODE_STYLEGUIDE_GO.md b/prompts/CODE_STYLEGUIDE_GO.md index 5ce1289..c620415 100644 --- a/prompts/CODE_STYLEGUIDE_GO.md +++ b/prompts/CODE_STYLEGUIDE_GO.md @@ -1,6 +1,6 @@ --- title: Code Styleguide — Go -last_modified: 2026-10-02 +last_modified: 2026-10-04 --- 1. Try to hard wrap long lines at 77 characters or less. @@ -51,8 +51,9 @@ last_modified: 2026-10-02 # ?= rather than := so that a `VERSION` build argument takes precedence: # where a build stage invokes make, `ARG VERSION` puts it in the # environment and `?=` defers to it. Otherwise `git describe` runs, in a - # build stage on the `.git` the build context carries. - VERSION ?= $(shell git describe --tags --always) + # build stage on the `.git` the build context carries. Outside a git + # checkout it prints nothing, and the version falls back to `dev`. + VERSION ?= $(or $(shell git describe --tags --always 2>/dev/null),dev) GOLDFLAGS += -X main.Version=$(VERSION) diff --git a/prompts/GO_HTTP_SERVER_CONVENTIONS.md b/prompts/GO_HTTP_SERVER_CONVENTIONS.md index 0aa35b5..2e9ab3a 100644 --- a/prompts/GO_HTTP_SERVER_CONVENTIONS.md +++ b/prompts/GO_HTTP_SERVER_CONVENTIONS.md @@ -1,6 +1,6 @@ --- title: Go HTTP Server Conventions -last_modified: 2026-10-02 +last_modified: 2026-10-04 --- This document defines the architectural patterns, design decisions, and @@ -987,8 +987,9 @@ Use ldflags to inject version information at build time: # ?= rather than := so that a `VERSION` build argument takes precedence: # where a build stage invokes make, `ARG VERSION` puts it in the # environment and `?=` defers to it. Otherwise `git describe` runs, in a -# build stage on the `.git` the build context carries. -VERSION ?= $(shell git describe --tags --always) +# build stage on the `.git` the build context carries. Outside a git +# checkout it prints nothing, and the version falls back to `dev`. +VERSION ?= $(or $(shell git describe --tags --always 2>/dev/null),dev) build: go build -ldflags "-X main.Version=$(VERSION)" ./cmd/httpd