Skip to content

fix: use ldflags for version injection instead of hardcoded 1.0.0#16

Merged
shenxianpeng merged 1 commit into
mainfrom
bugfix/version-ldflags-injection
Jun 1, 2026
Merged

fix: use ldflags for version injection instead of hardcoded 1.0.0#16
shenxianpeng merged 1 commit into
mainfrom
bugfix/version-ldflags-injection

Conversation

@shenxianpeng
Copy link
Copy Markdown
Contributor

Problem

ods --version always outputs ods version 1.0.0 regardless of the actual release version (e.g., v0.2.1). This happens because the Cobra Version field and the SARIF driver version are hardcoded to "1.0.0".

Fix

  • New internal/version/version.go — declares var Value = "dev" that can be overridden via -ldflags
  • internal/cmd/root.goVersion: version.Value instead of Version: "1.0.0"
  • internal/report/report.go — SARIF driver version uses version.Value instead of "1.0.0"

Build command

go build -ldflags="-X github.com/open-delivery-spec/cli/internal/version.Value=v0.2.1" ./cmd/ods/

ods --version now correctly shows ods version v0.2.1. Without ldflags, it shows ods version dev.

Verification

$ go build -ldflags="-X github.com/open-delivery-spec/cli/internal/version.Value=v0.2.1" -o ods ./cmd/ods/
$ ./ods --version
ods version v0.2.1

The --version flag and SARIF driver version were hardcoded to "1.0.0",
causing ods@v0.2.1 to report the wrong version.  Replace both with a
version.Value variable that is set via -ldflags at build time and
defaults to "dev" for development builds.

Example: go build -ldflags="-X github.com/open-delivery-spec/cli/internal/version.Value=v0.2.1"
@shenxianpeng shenxianpeng added the bug Something isn't working label Jun 1, 2026
@shenxianpeng shenxianpeng merged commit 37a13b3 into main Jun 1, 2026
4 checks passed
@shenxianpeng shenxianpeng deleted the bugfix/version-ldflags-injection branch June 1, 2026 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant