Skip to content

Adds comprehensive build versioning support#217

Merged
rgooch merged 13 commits intoCloud-Foundations:masterfrom
Vikramarjuna:versioning
Apr 24, 2026
Merged

Adds comprehensive build versioning support#217
rgooch merged 13 commits intoCloud-Foundations:masterfrom
Vikramarjuna:versioning

Conversation

@Vikramarjuna
Copy link
Copy Markdown
Contributor

@Vikramarjuna Vikramarjuna commented Jan 29, 2026

Summary

Adds build versioning to all binaries. Version, git origin, branch, and commits behind upstream are captured at build time into an embedded BUILD_INFO file, combined with VCS info from debug.ReadBuildInfo(), and surfaced via:

  • -version flag
  • Startup logs
  • HTML status page footers

Fork-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 changes

Example

$ domtool -version
domtool v0.12.0-68-gfd5cf75a-dirty
  Commit: fd5cf75a
  Origin: Vikramarjuna/Dominator
  Branch: versioning
  Built:  2026-04-01T06:49:28Z
  Go:     go1.25.5

Build

Use make to build (generates BUILD_INFO automatically):

make all    # or make build-linux, make install-darwin, etc.

Copy link
Copy Markdown
Member

@rgooch rgooch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread lib/flags/loadflags/impl.go Outdated
Comment thread lib/version/VERSION Outdated
@@ -0,0 +1 @@
v0.12.0 No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please fetch this from the most recent tag in the repository.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed. Getting the latest tag with versioning format as part of make and injecting to the version file.

Comment thread lib/version/impl.go
Comment thread lib/version/version.go Outdated
revision: "unknown",
buildTime: "unknown",
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please delete empty lines in functions. Same comment applies further down.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed.

@Vikramarjuna Vikramarjuna changed the title Adds comprehensive build versioning support to inject version information into all binaries at build time using ldflags Adds comprehensive build versioning support Apr 1, 2026
Comment thread lib/flags/loadflags/api.go Outdated
)

func LoadForCli(progName string) error {
registerVersionFlag(progName)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this into the impl.go file.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

Comment thread lib/flags/loadflags/api.go Outdated
}

func LoadForDaemon(progName string) error {
registerVersionFlag(progName)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please move this into the impl.go file.
Cleanest would be to add a loadForDaemon() function to contain this call.

Comment thread .gitignore Outdated

go.work
go.work.sum
go.work.sum No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add missing newline on last line.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed

Comment thread lib/flags/loadflags/impl.go Outdated
os.Exit(0)
return nil
})
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please insert blank line between functions.

Comment thread lib/flags/loadflags/impl.go Outdated
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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Output should be sent to: flag.CommandLine.Output()

Comment thread Makefile
Comment thread lib/version/api.go Outdated

// String returns a human-readable version string.
func (i Info) String() string {
return infoString(i)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not idiomatic Go. It should call a method.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

Comment thread lib/version/api.go Outdated

// Info contains version information for a binary.
type Info struct {
Version string `json:"version"`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed

Comment thread lib/version/impl.go Outdated
}

func infoString(i Info) string {
return fmt.Sprintf("%s (built: %s)", i.Version, i.BuildDate)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps here is where the Go version can be inserted.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the go version along with other details

Comment thread Makefile Outdated
all:
UPSTREAM_REPO := https://github.com/Cloud-Foundations/Dominator.git

build-info:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This target slows down the time to run make. Are these remote Git operations required? Are there other ways to reduce the time?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread Makefile
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)" ] && \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to add a target that does this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed. Added a new target.

@rgooch rgooch merged commit f4652cc into Cloud-Foundations:master Apr 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants