Skip to content

Conversation

@doringeman
Copy link
Contributor

Update build to match only cmd/cli/* tags and strip the prefix, allowing CLI-specific versioning.

Before:

$ make -C cmd/cli install
Building model-cli...
go build -ldflags="-s -w -X github.com/docker/model-runner/cmd/cli/desktop.Version=v1.0.9" -o model-cli .
...

Now:

$ make -C cmd/cli install
Building model-cli...
go build -ldflags="-s -w -X github.com/docker/model-runner/cmd/cli/desktop.Version=v1.0.4-2-gf12b17b-dirty" -o model-cli .
...

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @doringeman, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the versioning mechanism for the command-line interface (CLI) component. By adjusting the build script to specifically target and format CLI-related Git tags, it establishes an independent and accurate versioning scheme for the CLI, allowing its version to reflect its own development progress more precisely.

Highlights

  • CLI-Specific Versioning: The build process for the CLI now filters Git tags to only consider those prefixed with "cmd/cli*", ensuring that the version reported for the CLI is specific to its own release cycle rather than the entire repository.
  • Prefix Stripping: The "cmd/cli/" prefix is now stripped from the filtered Git tags, resulting in a cleaner and more relevant version string for the CLI executable.
  • Makefile Update: The Makefile in cmd/cli has been updated to incorporate these changes into the go build command's ldflags.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and found some issues that need to be addressed.

  • The --match "cmd/cli*" pattern doesn’t include the trailing slash you later strip with sed 's|^cmd/cli/||', so tags like cmd/cliX would be matched but not cleaned correctly; consider using a consistent pattern like --match 'cmd/cli/*' to align with the sed expression.
  • Because the git describe invocation is embedded in a double-quoted ldflags string, it may be safer to use single quotes around the --match pattern (and/or escape the inner quotes) to avoid quoting issues or unwanted shell globbing in different environments.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `--match "cmd/cli*"` pattern doesn’t include the trailing slash you later strip with `sed 's|^cmd/cli/||'`, so tags like `cmd/cliX` would be matched but not cleaned correctly; consider using a consistent pattern like `--match 'cmd/cli/*'` to align with the `sed` expression.
- Because the `git describe` invocation is embedded in a double-quoted `ldflags` string, it may be safer to use single quotes around the `--match` pattern (and/or escape the inner quotes) to avoid quoting issues or unwanted shell globbing in different environments.

## Individual Comments

### Comment 1
<location> `cmd/cli/Makefile:17` </location>
<code_context>
 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) .

 link:
</code_context>

<issue_to_address>
**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.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request aims to introduce CLI-specific versioning by filtering git tags in the Makefile. The approach of using git describe --match and sed is correct for this purpose. However, the current implementation has a flaw where the build will fail if no tags with the cmd/cli/ prefix are found. I've provided a review comment with a suggestion to make the command more robust by adding a fallback mechanism, which ensures the build remains stable for all developers while still prioritizing the new versioning scheme.

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.

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) .

@doringeman doringeman merged commit 5796242 into docker:main Dec 12, 2025
9 checks passed
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