-
Notifications
You must be signed in to change notification settings - Fork 79
build(cli): filter git tags by cmd/cli prefix for version #507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Dorin Geman <[email protected]>
Summary of ChangesHello @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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this 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 withsed 's|^cmd/cli/||', so tags likecmd/cliXwould be matched but not cleaned correctly; consider using a consistent pattern like--match 'cmd/cli/*'to align with thesedexpression. - Because the
git describeinvocation is embedded in a double-quotedldflagsstring, it may be safer to use single quotes around the--matchpattern (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>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) . |
There was a problem hiding this comment.
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.
There was a problem hiding this 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) . |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) .
Update build to match only cmd/cli/* tags and strip the prefix, allowing CLI-specific versioning.
Before:
Now: