Skip to content

Conversation

@Vikramarjuna
Copy link

Add Build Versioning Infrastructure

Summary

Adds comprehensive build versioning support to inject version information into all binaries at build time using ldflags.

Changes

New Files:

  • lib/version/version.go - Version package with ldflags injection and fallback support
  • scripts/version.lib - Shared bash library for version calculation (used by tarball scripts)
  • .github/workflows/release.yml - Release workflow triggered on tag push with multi-arch builds

Modified Files:

  • Makefile - Added version calculation from git tags, ldflags injection, and cross-compilation targets
  • scripts/make-tarball - Updated to use version.lib for version injection
  • cmd/installer/make-tarball - Updated to use version.lib for version injection
  • All 29 cmd/*/main.go files - Added -version flag support

Version Format

Context Format Example
Tagged release vX.Y.Z v1.2.3
Main branch (post-tag) vX.Y.Z-dev.N+commit v1.2.3-dev.5+abc1234
Feature branch vX.Y.Z-branch.N+commit v1.2.3-feature-api.5+abc1234
Uncommitted changes ...-dirty v1.2.3-dirty

Build Targets

Target Description
make Install to $GOPATH/bin (existing behavior, now with version)
make build Build for current OS/arch to ./dist/
make build-linux Build for Linux amd64
make build-linux-arm Build for Linux arm64
make build-darwin Build for macOS amd64 (excludes Linux-only commands)
make build-darwin-arm Build for macOS arm64 (excludes Linux-only commands)
make <service>.tarball Build deployment tarball with versioned binary

Darwin Build Exclusions

The following Linux-only commands are excluded from Darwin builds:

  • installer - Linux syscalls, no cross-platform support
  • subd - Linux syscalls, no cross-platform support
  • image-unpacker - Has // +build linux constraint
  • imaginator - Has // +build linux constraint

Release Workflow

  • Triggered on tag push (v*)
  • Builds 4 architectures in parallel (linux-amd64, linux-arm64, darwin-amd64, darwin-arm64)
  • Generates SHA256 checksums
  • Creates GitHub Release with tarballs

Usage

# Check version
./vm-control -version

# Output
vm-control v1.2.3-dev.5+abc1234
  Commit: abc1234
  Branch: main
  Built:  2026-01-29T12:00:00Z
  Go:     go1.25.4

# Short version
./vm-control -version -short
v1.2.3-dev.5+abc1234

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.

1 participant