Fall back to dev when git describe prints nothing (closes #74)
check / check (push) Waiting to run
check / check (push) Waiting to run
The Makefile example in the Go styleguide and in the HTTP server conventions set VERSION from `git describe --tags --always` alone. Where that prints nothing (outside a git checkout, or where git is missing or refuses the checkout), 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 names that condition. A `VERSION` from the environment or the make command line still takes precedence. Model: opus-5-5
This commit is contained in:
@@ -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 (outside
|
||||
a git checkout, or where git is missing or refuses the 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: Fixed two defects in the canonical Go `Dockerfile` example (issue
|
||||
73). The test phase now uses the Debian Go image, since `-race` needs cgo and
|
||||
the alpine image has no C compiler, so the phase failed before running a test.
|
||||
|
||||
@@ -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,10 @@ 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. When it prints
|
||||
# nothing (outside a git checkout, or where git is missing or refuses the
|
||||
# checkout), the version falls back to `dev`.
|
||||
VERSION ?= $(or $(shell git describe --tags --always 2>/dev/null),dev)
|
||||
|
||||
GOLDFLAGS += -X main.Version=$(VERSION)
|
||||
|
||||
|
||||
@@ -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,10 @@ 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. When it prints
|
||||
# nothing (outside a git checkout, or where git is missing or refuses the
|
||||
# checkout), 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
|
||||
|
||||
Reference in New Issue
Block a user