Skip to content

feat(DCP-2596): show cli version in release#375

Merged
MrManning merged 5 commits intomainfrom
DCP-2596/fix-versioning
Mar 25, 2026
Merged

feat(DCP-2596): show cli version in release#375
MrManning merged 5 commits intomainfrom
DCP-2596/fix-versioning

Conversation

@MrManning
Copy link
Copy Markdown
Contributor

@MrManning MrManning commented Mar 23, 2026

Summary

  • Added Get() function to version package that falls back to runtime/debug build info when Version is not injected via ldflags
  • versionFromBuildInfo guards against "", "(devel)", and pseudo-versions (vX.Y.Z-TIMESTAMP-HASH) — local make build still correctly shows dev
  • Renamed GITCOMMITVersion across version/version.go, Makefile, and DEVELOPMENT.md to better reflect its purpose
  • Added TestVersionFromBuildInfo and TestGet covering all version resolution paths
  • Fixes go install @vX.Y.Z installs (e.g. Kandji) showing dev instead of the real version number

Jira Ticket

DCP-2596: Fix versioning

Testing

Method Before After
make static (local) 93ca342 93ca342
GIT_RELEASE=vX.Y.Z make static-named 0.0.62 0.0.62
go install @vX.Y.Z dev 0.0.62 ✓ (after new version released)
make build (no ldflags) dev dev

Checklist

  • Bug Fix
  • Feature
  • Refactoring
  • Documentation
  • Infrastructure
  • Build/CI
  • Architectural changes
  • Customer impact — affects existing functionality
  • New tests added
  • Existing tests updated
  • Manual testing performed
  • I have performed a self-review of my code
  • Code follows style guidelines
  • Commits follow Conventional Commits format
  • All commits are signed with GPG
  • New and existing tests pass locally
  • PR has appropriate labels

@MrManning MrManning self-assigned this Mar 23, 2026
@MrManning MrManning requested a review from a team as a code owner March 23, 2026 12:02
Copilot AI review requested due to automatic review settings March 23, 2026 12:02
@prolific-snyk
Copy link
Copy Markdown

prolific-snyk commented Mar 23, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the CLI’s reported version so releases (and some install methods) can display a meaningful semantic version instead of only relying on a build-time variable.

Changes:

  • Add version.Get() to compute the CLI version from -ldflags first, then fall back to debug.ReadBuildInfo().
  • Switch Cobra’s root command Version field to use version.Get().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
version/version.go Introduces version resolution logic using ldflags and Go build metadata.
cmd/root.go Uses the new version resolver for --version output.

Comment on lines 9 to 11
// GITCOMMIT is injected at build time via -ldflags (e.g. "0.0.62").
// Defaults to "dev" when not set.
var GITCOMMIT string = "dev"
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

The variable name GITCOMMIT is now used as the primary source of the CLI version (and the comment/example show semantic versions). This is misleading for future maintainers. Consider introducing a Version variable as the canonical value (still settable via -ldflags) and keeping GITCOMMIT only as a backwards-compatible alias/deprecated name.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Does this no longer work, and if not, can it be updated?

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.

make static still works unchanged. The ldflags inject GITCOMMIT as the short commit hash (e.g. 93ca342), which is not "dev", so Get() returns it immediately on the first check — the runtime/debug fallback is never reached. Same applies to make static-named in the release pipeline.

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.

Unless I have misunderstood what you meant?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Might be just talking cross purposes. Fairly sure this use to work. So releases would set VERSION=xxxx make static so there was no need for code to do what we are doing here.

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.

Sorry so a bit a context might be useful. In local instances and builds using the binary are fine, however we noticed that when the cli is installed via Kandji we're returning prolific version dev instead of the version. It seems highly possible that Kandji isn't using them, likely using go install but looking into this now

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

oic - Yeah Ideally Kandji uses the released binaries rather than building again - Cool

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.

Done in 0162b21 — renamed GITCOMMIT to Version in version/version.go, Makefile, and DEVELOPMENT.md. Follows standard Go export naming convention.

@MrManning MrManning force-pushed the DCP-2596/fix-versioning branch from 31b4c45 to 200caa2 Compare March 23, 2026 12:15
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@MrManning MrManning added the dct-ready-for-review Triggers Slack notification when PR is ready for review label Mar 25, 2026
@MrManning MrManning enabled auto-merge March 25, 2026 15:36
@MrManning MrManning merged commit 9c30723 into main Mar 25, 2026
5 checks passed
@MrManning MrManning deleted the DCP-2596/fix-versioning branch March 25, 2026 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dct-ready-for-review Triggers Slack notification when PR is ready for review team-dct

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants