Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/cli/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ all: build

build:
@echo "Building $(BINARY_NAME)..."
go build -ldflags="-s -w -X github.com/docker/model-runner/cmd/cli/desktop.Version=$(shell git describe --tags --always --dirty)" -o $(BINARY_NAME) .
go build -ldflags="-s -w -X github.com/docker/model-runner/cmd/cli/desktop.Version=$(shell git describe --tags --always --dirty --match "cmd/cli*" | sed 's|^cmd/cli/||')" -o $(BINARY_NAME) .
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (bug_risk): The inner double quotes around --match "cmd/cli*" will likely break the Makefile/ldflags quoting.

Because -ldflags is wrapped in double quotes, reusing double quotes inside --match "cmd/cli*" will end the string early in the Makefile, causing parse/build issues or wrong arguments to go build. Please either switch the inner pattern to single quotes or escape the inner quotes (e.g. "cmd/cli*") so the full git describe command is passed correctly.

Copy link
Contributor

Choose a reason for hiding this comment

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

high

The current git describe command will fail if no tags matching cmd/cli* are found in the commit history, even with the --always flag. This could cause the build to fail for developers with a fresh clone of the repository or on branches without such tags.

To make the build more robust, you could add a fallback. The suggested change first attempts to find a cmd/cli tag. If it fails, it gracefully falls back to finding any tag (the old behavior), ensuring the build doesn't break. The sed command is safe to apply in both cases as it will only act on the cmd/cli/ prefix.

	go build -ldflags="-s -w -X github.com/docker/model-runner/cmd/cli/desktop.Version=$(shell (git describe --tags --always --dirty --match "cmd/cli*" 2>/dev/null || git describe --tags --always --dirty) | sed 's|^cmd/cli/||')" -o $(BINARY_NAME) .


link:
@if [ ! -f $(BINARY_NAME) ]; then \
Expand Down
Loading