Stamp the git tag or short commit into the binary (closes #10) #11

Merged
clawbot merged 1 commits from issue-10-version-stamp into next 2026-10-02 10:21:25 +02:00
Collaborator

Implements #10. rtnetmon had no version. It now has main.Version, set at link time with -X and logged in the first startup line (Starting rtnetmon <version>, in the log file).

  • .dockerignore now matches the canonical copy on sneak/prompts next, plus this repo's own build artifacts. .git is sent so the build can stamp the version. .git/config is left out because it can hold a credential, and git describe does not need it.
  • The Dockerfile's build stage takes the VERSION build argument when one is given. Otherwise it runs git describe --tags --always on the .git in the context, which gives the tag, tag-N-gHASH or the short commit. The build fails if the context carries .git and the result is empty, dev or unknown.
  • make build and make dev stamp the version the same way, from VERSION when given, otherwise from git describe --tags --always, as the Go styleguide shows.

Worth knowing:

  • script/docker and script/cibuild pass no VERSION, so the build works the version out itself. These scripts never computed a version and are unchanged.
  • The CI checkout is shallow and fetches no tags, so CI images stamp the short commit.
  • A docker build with neither .git nor VERSION (a source tarball) reports dev. make build outside a git checkout stamps an empty version.

Disclosures:

  • Rule suppressed: //nolint:gochecknoglobals on Version, which the linker sets.
  • Not changed: this repo's REPO_POLICIES.md still describes the old convention (ARG VERSION=dev, no git describe in any stage). Changing it is outside this issue.
  • No unit test added: the change is in the build, not in Go logic.

Model: opus-5-5

Implements https://git.eeqj.de/sneak/rtnetmon/issues/10. rtnetmon had no version. It now has `main.Version`, set at link time with `-X` and logged in the first startup line (`Starting rtnetmon <version>`, in the log file). - `.dockerignore` now matches the canonical copy on `sneak/prompts` `next`, plus this repo's own build artifacts. `.git` is sent so the build can stamp the version. `.git/config` is left out because it can hold a credential, and `git describe` does not need it. - The `Dockerfile`'s build stage takes the `VERSION` build argument when one is given. Otherwise it runs `git describe --tags --always` on the `.git` in the context, which gives the tag, `tag-N-gHASH` or the short commit. The build fails if the context carries `.git` and the result is empty, `dev` or `unknown`. - `make build` and `make dev` stamp the version the same way, from `VERSION` when given, otherwise from `git describe --tags --always`, as the Go styleguide shows. Worth knowing: - `script/docker` and `script/cibuild` pass no `VERSION`, so the build works the version out itself. These scripts never computed a version and are unchanged. - The CI checkout is shallow and fetches no tags, so CI images stamp the short commit. - A `docker build` with neither `.git` nor `VERSION` (a source tarball) reports `dev`. `make build` outside a git checkout stamps an empty version. Disclosures: - Rule suppressed: `//nolint:gochecknoglobals` on `Version`, which the linker sets. - Not changed: this repo's `REPO_POLICIES.md` still describes the old convention (`ARG VERSION=dev`, no `git describe` in any stage). Changing it is outside this issue. - No unit test added: the change is in the build, not in Go logic. Model: opus-5-5
clawbot added the needs-review label 2026-10-02 08:44:17 +02:00
clawbot self-assigned this 2026-10-02 08:44:17 +02:00
Author
Collaborator
  • Makefile, build target (also behind run; dev runs go run the same way): the binary it builds still reports dev. make build is the README's installation step, and as the Dockerfile notes, rtnetmon runs on the host rather than in a container, so the binary people actually run never carries its commit, while docker build . of the same clean commit stamps the short commit. Acceptable: the Makefile sets VERSION ?= $(shell git describe --tags --always) and passes -ldflags "-X main.Version=$(VERSION)" in build and dev, as prompts/CODE_STYLEGUIDE_GO.md on sneak/prompts next shows, and the comment on Version in cmd/rtnetmon/main.go no longer names the Dockerfile as the only place it is set.

Model: opus-5-5

- `Makefile`, `build` target (also behind `run`; `dev` runs `go run` the same way): the binary it builds still reports `dev`. `make build` is the README's installation step, and as the `Dockerfile` notes, rtnetmon runs on the host rather than in a container, so the binary people actually run never carries its commit, while `docker build .` of the same clean commit stamps the short commit. Acceptable: the `Makefile` sets `VERSION ?= $(shell git describe --tags --always)` and passes `-ldflags "-X main.Version=$(VERSION)"` in `build` and `dev`, as `prompts/CODE_STYLEGUIDE_GO.md` on `sneak/prompts` `next` shows, and the comment on `Version` in `cmd/rtnetmon/main.go` no longer names the `Dockerfile` as the only place it is set. Model: opus-5-5
clawbot added needs-rework and removed needs-review labels 2026-10-02 09:47:37 +02:00
clawbot added 1 commit 2026-10-02 09:59:20 +02:00
rtnetmon had no version. main.Version is now set at link time and logged
in the first startup line. `make build` and `make dev` set it from
`git describe --tags --always` unless VERSION is given. The Dockerfile
takes it from the VERSION build argument when one is given, otherwise
from `git describe --tags --always` of the .git the build context now
carries, and fails the build if the context carries .git and no version
comes out. .dockerignore follows the canonical copy: .git is sent,
.git/config, which can hold a credential, is not.

Model: opus-5-5
clawbot force-pushed issue-10-version-stamp from 51d2bd24df to 05689e6f72 2026-10-02 09:59:20 +02:00 Compare
clawbot added needs-review and removed needs-rework labels 2026-10-02 09:59:25 +02:00
Author
Collaborator

Review passed.

Model: opus-5-5

Review passed. Model: opus-5-5
clawbot merged commit bce8bdbb2e into next 2026-10-02 10:21:25 +02:00
clawbot deleted branch issue-10-version-stamp 2026-10-02 10:21:25 +02:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sneak/rtnetmon#11