Skip to content

Fix go build commands#291

Merged
kindermax merged 1 commit intomasterfrom
fix-go-build-command
Mar 10, 2026
Merged

Fix go build commands#291
kindermax merged 1 commit intomasterfrom
fix-go-build-command

Conversation

@kindermax
Copy link
Copy Markdown
Collaborator

@kindermax kindermax commented Mar 10, 2026

Summary by Sourcery

Switch the CLI to an internal cmd/lets entrypoint and central Version variable, updating build, release, and test tooling accordingly.

Enhancements:

  • Move the main lets entrypoint into cmd/lets and expose the application version via a exported Version variable.
  • Update Go build commands, docker-compose setup, and GoReleaser config to build from the new cmd/lets path and use the new Version variable.
  • Add a helper command for running GoReleaser builds in development and improve build output to show the actual binary version after build.

Tests:

  • Adjust version-related Bats tests to build and run the binary from the new cmd/lets entrypoint using the exported Version variable.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Mar 10, 2026

Reviewer's Guide

Refactors the lets CLI into an internal cmd/lets application structure, updates version injection to use a public main.Version variable, and aligns build, test, Docker, and GoReleaser configurations with the new entrypoint and version symbol while cleaning up IDE run configs.

Class diagram for the updated main package entrypoint

classDiagram
    class main {
        +string Version
        +main()
    }
Loading

File-Level Changes

Change Details Files
Move CLI entrypoint to cmd/lets and expose version as a public variable consumed throughout the app.
  • Relocated main.go to cmd/lets/main.go as the new application entrypoint.
  • Renamed the package-level version variable to a public Version variable with the same default value.
  • Updated calls to cmd.CreateRootCommand, cmd.InitSelfCmd, config.Load, workdir.InitLetsFile, and upgrade.NewBinaryUpgrader to use the new Version symbol instead of the old version variable.
cmd/lets/main.go
Align build and release tooling with the new cmd/lets main package and Version ldflag symbol.
  • Updated lets.yaml dev-build and build commands to build from cmd/lets/main.go and inject main.Version via -ldflags, and to print the built binary's runtime --version on success.
  • Adjusted .goreleaser.yml builds to use ./cmd/lets as main and to inject main.Version instead of main.version where appropriate.
  • Added a goreleaser-dev helper command in lets.build.yaml to run goreleaser build for local testing.
  • Updated docker-compose test service to build /usr/bin/lets from cmd/lets/main.go instead of using *.go in the repo root.
lets.yaml
.goreleaser.yml
lets.build.yaml
docker-compose.yml
Update tests and ancillary project files to work with the new structure and symbol names, and remove obsolete run configurations.
  • Changed config_version.bats to build the test binary from cmd/lets/main.go and inject main.Version instead of main.version, and normalized indentation to two spaces.
  • Removed obsolete IDE run configurations under .run that referenced the old layout.
  • Left .gitignore and .vscode/launch.json effectively unchanged aside from possible formatting/metadata updates.
tests/config_version.bats
.run/lets --version.run.xml
.run/lets print-env.run.xml
.run/lets.run.xml
.gitignore
.vscode/launch.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@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 - I've found 1 issue, and left some high level feedback:

  • In .goreleaser.yml, some build configs (e.g., darwin-amd64) still use -X main.version={{.Version}} while others use main.Version; align all ldflags to the new Version symbol so releases embed the correct version.
  • In the build command in lets.yaml, the failure branch only prints "Failed to build" but does not return a non-zero exit code; consider exiting with the original go build status so CI and callers can detect build failures.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `.goreleaser.yml`, some build configs (e.g., `darwin-amd64`) still use `-X main.version={{.Version}}` while others use `main.Version`; align all ldflags to the new `Version` symbol so releases embed the correct version.
- In the `build` command in `lets.yaml`, the failure branch only prints `"Failed to build"` but does not return a non-zero exit code; consider exiting with the original `go build` status so CI and callers can detect build failures.

## Individual Comments

### Comment 1
<location path="lets.yaml" line_range="114" />
<code_context>
+      go build -ldflags="-X main.Version=${VERSION:1}-dev" -o "${BIN}" cmd/lets/main.go && \
       sudo mv ./${BIN} $PATH2LETSDEV/${BIN} && \
-      echo " - binary ${BIN} version ${VERSION} successfully installed in ${PATH2LETSDEV}"
+      echo " - binary ${BIN} version $($PATH2LETSDEV/${BIN} --version) successfully installed in ${PATH2LETSDEV}"

   build:
</code_context>
<issue_to_address>
**nitpick (bug_risk):** Unquoted paths in the version check could break if `PATH2LETSDEV` contains spaces.

The unquoted `$PATH2LETSDEV/${BIN} --version` invocation will break when the install path has spaces or special characters. Please quote the command, e.g.:

```bash
echo " - binary ${BIN} version "$"${PATH2LETSDEV}/${BIN}" --version" successfully installed in ${PATH2LETSDEV}
```

and apply similar quoting anywhere `${BIN}` or `${PATH2LETSDEV}` are used in commands.
</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.

go build -ldflags="-X main.Version=${VERSION:1}-dev" -o "${BIN}" cmd/lets/main.go && \
sudo mv ./${BIN} $PATH2LETSDEV/${BIN} && \
echo " - binary ${BIN} version ${VERSION} successfully installed in ${PATH2LETSDEV}"
echo " - binary ${BIN} version $($PATH2LETSDEV/${BIN} --version) successfully installed in ${PATH2LETSDEV}"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nitpick (bug_risk): Unquoted paths in the version check could break if PATH2LETSDEV contains spaces.

The unquoted $PATH2LETSDEV/${BIN} --version invocation will break when the install path has spaces or special characters. Please quote the command, e.g.:

echo " - binary ${BIN} version "$"${PATH2LETSDEV}/${BIN}" --version" successfully installed in ${PATH2LETSDEV}

and apply similar quoting anywhere ${BIN} or ${PATH2LETSDEV} are used in commands.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 10, 2026

Greptile Summary

This PR migrates the repository to a standard Go internal project structure by moving main.go to cmd/lets/main.go and exporting the version variable as Version. All tooling references (goreleaser, docker-compose, lets.yaml, VSCode/JetBrains configs, and tests) are updated accordingly.

Key changes:

  • main.go renamed to cmd/lets/main.go; var version renamed to var Version (exported) to allow correct linker injection via -X main.Version
  • .goreleaser.yml entry points updated to ./cmd/lets — but darwin-amd64 and linux-amd64 still reference the old -X main.version (lowercase), meaning the version string will not be injected for those two platforms in production releases
  • docker-compose.yml and lets.yaml build commands pass a file path (cmd/lets/main.go) rather than the package path (./cmd/lets), which is a minor style concern
  • JetBrains run configurations removed; VSCode launch.json updated to point at the new entry point
  • .gitignore anchored to repo root with /lets

Confidence Score: 2/5

  • Not safe to merge — two of the three goreleaser build targets will ship binaries with the hardcoded 0.0.0-dev version string instead of the real release version.
  • The structural migration is correct and the tests/bats file are properly updated. However, the incomplete ldflags fix in .goreleaser.yml is a critical release-time defect: darwin-amd64 and linux-amd64 release binaries will always display 0.0.0-dev, silently breaking version checks and the upgrade flow for the majority of users.
  • .goreleaser.yml lines 26 and 54 require the lowercase main.version to be corrected to main.Version.

Important Files Changed

Filename Overview
.goreleaser.yml Updated main entry point to ./cmd/lets for all targets, but darwin-amd64 (line 26) and linux-amd64 (line 54) still use the old lowercase -X main.version linker flag — the version string will not be injected at release time for those platforms.
cmd/lets/main.go Renamed from main.go to cmd/lets/main.go; version variable exported as Version (uppercase). All internal usages updated correctly.
docker-compose.yml Updated build command to reference cmd/lets/main.go; uses a file path rather than the package path ./cmd/lets, which is a minor style concern.
lets.yaml Updated install/build commands to use new path and -X main.Version; same minor file-vs-package path concern as docker-compose.yml.
tests/config_version.bats Correctly updated to use -X main.Version and cmd/lets/main.go; indentation-only formatting change.
.gitignore Changed lets to /lets to anchor the ignore rule to the repo root — correct and intentional improvement.
.vscode/launch.json Updated Run configuration to point to ${workspaceRoot}/cmd/lets/main.go; reformatted to 2-space indentation.
lets.build.yaml Added goreleaser-dev command for local testing of the release build process.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[goreleaser / go build] -->|"-X main.Version"| B[cmd/lets/main.go\nvar Version = '0.0.0-dev']
    B --> C{Platform}
    C -->|darwin-arm64\n✅ main.Version| D[Version injected correctly]
    C -->|darwin-amd64\n❌ main.version| E[Version stays '0.0.0-dev']
    C -->|linux-amd64\n❌ main.version| F[Version stays '0.0.0-dev']
    D --> G[Binary reports correct version]
    E --> H[Binary reports wrong version]
    F --> H
Loading

Comments Outside Diff (1)

  1. .goreleaser.yml, line 54 (link)

    Incorrect ldflags variable name — version injection will silently fail

    Same issue as the darwin-amd64 build (line 26): -X main.version should be -X main.Version to match the renamed exported variable in cmd/lets/main.go.

Last reviewed commit: abe9a1f

.goreleaser.yml Outdated
@@ -25,7 +25,7 @@ builds:
ldflags:
- -s -w -X main.version={{.Version}}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Incorrect ldflags variable name — version injection will silently fail

main.version (lowercase) is used here, but the variable was renamed to Version (uppercase) in cmd/lets/main.go. Go's -X linker flag performs an exact, case-sensitive match on the fully-qualified symbol name. Because main.version no longer exists, goreleaser will silently ignore this flag and the released darwin-amd64 binary will always report 0.0.0-dev instead of the actual release version.

The same problem exists for linux-amd64 at line 54.

Suggested change
- -s -w -X main.version={{.Version}}
- -s -w -X main.Version={{.Version}}

- -c
- |
go build -o /usr/bin/lets *.go
go build -o /usr/bin/lets cmd/lets/main.go
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Building a file path instead of a package path

go build -o /usr/bin/lets cmd/lets/main.go passes a file path to go build. While this works today because main.go is the only file in cmd/lets/, if any additional .go files (e.g. helper functions, _test.go build-tagged files, or init code) are added to that directory later, they will be silently excluded from the build. The idiomatic approach is to pass the package import path:

Suggested change
go build -o /usr/bin/lets cmd/lets/main.go
go build -o /usr/bin/lets ./cmd/lets

echo " - binary ${BIN} version $($PATH2LETSDEV/${BIN} --version) successfully installed in ${PATH2LETSDEV}"

build:
description: Build lets from source code
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Building a file path instead of a package path

Same concern as in docker-compose.yml: go build ... cmd/lets/main.go passes a source-file path rather than a package path (./cmd/lets). Any future files added to cmd/lets/ would be silently omitted. Consider using ./cmd/lets for both the install and build commands.

Suggested change
description: Build lets from source code
go build -ldflags="-X main.Version=${VERSION:1}-dev" -o "${BIN}" ./cmd/lets && \

@kindermax kindermax force-pushed the fix-go-build-command branch 3 times, most recently from f98ebe6 to f33ec89 Compare March 10, 2026 09:19
@kindermax kindermax changed the title switch to internal project structure Fix go build commands Mar 10, 2026
@kindermax kindermax force-pushed the fix-go-build-command branch from f33ec89 to 372f076 Compare March 10, 2026 09:49
@kindermax kindermax force-pushed the fix-go-build-command branch from 372f076 to d1123f1 Compare March 10, 2026 09:53
@kindermax kindermax merged commit 0c22143 into master Mar 10, 2026
5 checks passed
@kindermax kindermax deleted the fix-go-build-command branch March 10, 2026 09:57
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.

1 participant