Adds comprehensive build versioning support#217
Adds comprehensive build versioning support#217rgooch merged 13 commits intoCloud-Foundations:masterfrom
Conversation
rgooch
left a comment
There was a problem hiding this comment.
I would like this PR to be split, with the first PR containing only the minimum to add version information (i.e. remove the workflow and reduce/eliminate changes to the Makefile).
I would prefer we don't impose a requirement to change every command. I think the lib/flags/loadflags package is a convenient place to make a fairly central change.
Finally, instead of injecting compile/link flags, I think it's better to use the embed package.
| @@ -0,0 +1 @@ | |||
| v0.12.0 No newline at end of file | |||
There was a problem hiding this comment.
Please fetch this from the most recent tag in the repository.
There was a problem hiding this comment.
Addressed. Getting the latest tag with versioning format as part of make and injecting to the version file.
| revision: "unknown", | ||
| buildTime: "unknown", | ||
| } | ||
|
|
There was a problem hiding this comment.
Please delete empty lines in functions. Same comment applies further down.
| ) | ||
|
|
||
| func LoadForCli(progName string) error { | ||
| registerVersionFlag(progName) |
There was a problem hiding this comment.
Please move this into the impl.go file.
| } | ||
|
|
||
| func LoadForDaemon(progName string) error { | ||
| registerVersionFlag(progName) |
There was a problem hiding this comment.
Please move this into the impl.go file.
Cleanest would be to add a loadForDaemon() function to contain this call.
|
|
||
| go.work | ||
| go.work.sum | ||
| go.work.sum No newline at end of file |
There was a problem hiding this comment.
Please add missing newline on last line.
| os.Exit(0) | ||
| return nil | ||
| }) | ||
| } |
There was a problem hiding this comment.
Please insert blank line between functions.
| func registerVersionFlag(name string) { | ||
| flag.BoolFunc("version", "Print version information and exit", func(string) error { | ||
| info := version.Get() | ||
| fmt.Printf("%s %s\n", name, info.Version) |
There was a problem hiding this comment.
Output should be sent to: flag.CommandLine.Output()
|
|
||
| // String returns a human-readable version string. | ||
| func (i Info) String() string { | ||
| return infoString(i) |
There was a problem hiding this comment.
This is not idiomatic Go. It should call a method.
|
|
||
| // Info contains version information for a binary. | ||
| type Info struct { | ||
| Version string `json:"version"` |
There was a problem hiding this comment.
Please remove all the field tags. The convention in this repository is that the JSON field names are the same as the actual field names.
| } | ||
|
|
||
| func infoString(i Info) string { | ||
| return fmt.Sprintf("%s (built: %s)", i.Version, i.BuildDate) |
There was a problem hiding this comment.
Perhaps here is where the Go version can be inserted.
There was a problem hiding this comment.
Added the go version along with other details
| all: | ||
| UPSTREAM_REPO := https://github.com/Cloud-Foundations/Dominator.git | ||
|
|
||
| build-info: |
There was a problem hiding this comment.
This target slows down the time to run make. Are these remote Git operations required? Are there other ways to reduce the time?
There was a problem hiding this comment.
I have introduced a flag to fetch the latest SHA from the upstream. The flag is disabled by default. If it is disabled, we will not know how many commits the current branch/fork is behind the upstream. The version info will now show unknown by default and if it is built with the flag enabled it will show either up to date or n commits for the Behind field. Rest of the git operations are run locally and doesn't cause any slowness. These gives information of fork and branch.
| case "$$raw_origin" in *Cloud-Foundations*) is_fork=false;; *) is_fork=true;; esac; \ | ||
| if [ "$$is_fork" = false ] && [ "$$branch" = "master" ]; then \ | ||
| behind=0; \ | ||
| elif [ -n "$(WITH_UPSTREAM)" ] && \ |
There was a problem hiding this comment.
It would be nice to add a target that does this.
There was a problem hiding this comment.
Addressed. Added a new target.
Summary
Adds build versioning to all binaries. Version, git origin, branch, and commits behind upstream are captured at build time into an embedded
BUILD_INFOfile, combined with VCS info fromdebug.ReadBuildInfo(), and surfaced via:-versionflagFork-specific details (origin, branch, commits behind) are shown only when relevant.
Version Format
v0.12.0— release build (exactly on tag)v0.12.0-3-gabcdef— dev build (3 commits after tag)v0.12.0-3-gabcdef-dirty— uncommitted changesExample
Build
Use
maketo build (generatesBUILD_INFOautomatically):make all # or make build-linux, make install-darwin, etc.