Commit 97ddb22
feat(buildinfo): fall back to debug.BuildInfo when ldflags unset
`go install github.com/randomcodespace/codeiq/go/cmd/codeiq@v0.3.0`
worked but the resulting binary reported "dev / unknown / unknown"
because the -ldflags path only runs under goreleaser. Same story for
`go build` from a local git checkout.
Add an init() hydrate step that reads runtime/debug.BuildInfo and
fills any var still at its default:
- Main.Version → Version (skips "(devel)" sentinel)
- vcs.revision → Commit (7-char short hash)
- vcs.time → Date
- vcs.modified → Dirty (only promotes "false" → "true")
Resolution priority:
1. -ldflags -X (release builds via goreleaser) — highest
2. runtime/debug.BuildInfo — `go install …@<tag>` or local `go build`
3. Defaults ("dev" / "unknown") — last resort
Verified:
- plain `go build` from a worktree:
codeiq dev
commit: e5fd3fe (dirty)
built: 2026-05-14T01:37:03Z
- `-ldflags -X buildinfo.Version=v0.3.0 …`:
codeiq v0.3.0
commit: abc1234 (dirty)
built: 2026-05-14T00:00:00Z
Tests:
- 6 buildinfo tests pass (was 5). Old "must be exactly defaults"
test was brittle once init() ran; replaced with two tests covering
well-formedness and the ldflags-preservation contract.
- Full suite: 884 passed.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent e5fd3fe commit 97ddb22
2 files changed
Lines changed: 110 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
4 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
5 | 16 | | |
6 | 17 | | |
7 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
8 | 23 | | |
9 | 24 | | |
10 | 25 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
15 | 34 | | |
16 | 35 | | |
17 | 36 | | |
18 | 37 | | |
19 | 38 | | |
20 | 39 | | |
21 | 40 | | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
22 | 82 | | |
23 | 83 | | |
24 | 84 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | | - | |
10 | | - | |
11 | | - | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
12 | 17 | | |
13 | | - | |
14 | | - | |
| 18 | + | |
| 19 | + | |
15 | 20 | | |
16 | | - | |
17 | | - | |
| 21 | + | |
| 22 | + | |
18 | 23 | | |
19 | | - | |
20 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
21 | 54 | | |
22 | 55 | | |
23 | 56 | | |
| |||
0 commit comments