feature idea: detect git short version hash during build and embed into binary
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 5.6k
- Forks
- 175
- PR merge metrics
- No merged PRs in 30d
Description
In my apps I usually do something like:
```
var Version string
func main() {
os.Exit(httpserver.Run(Version))
}
```
Then at build time (in my Makefile) I do this:
```
VERSION := $(shell git describe --always --dirty=-dirty)
GOLDFLAGS += -X main.Version=$(VERSION)
GOFLAGS := -ldflags "$(GOLDFLAGS)"
```
This embeds the version string into the app so that I can access it, which is useful for me because then in production I can access this value and put it in my footers and error messages so that I know precisely which commit is running.
It would be cool if `bud build` could detect if it's building out of a git repo, and embed the git shorthash into the built binary in this way. It seems that you could skip the `ldflags` part and simply "hardcode" the git shorthash into the main.go via the main.gotext template at build filesystem generation time.
Anyway, just an idea, and I'm happy to take a crack at making a patch for this when I have some time, I just wanted to write it down while it's in my head.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the `bud build` flow, the Makefile build settings, and the `main.go` and `main.gotext` locations mentioned in the issue. Trace how the build filesystem is generated and determine how a Git short hash could be embedded when building from a repository. Done means the built binary exposes the commit hash while builds outside Git remain supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, go
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100