Skip to content
Closed
Show file tree
Hide file tree
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
dist

# lets binary
lets
/lets
lets-dev
.lets
lets.my.yaml
Expand Down
8 changes: 4 additions & 4 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ release:

builds:
- id: darwin-amd64
main: .
main: ./cmd/lets
goos:
- darwin
goarch:
Expand All @@ -25,7 +25,7 @@ builds:
ldflags:
- -s -w -X main.version={{.Version}}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): The ldflags symbol still targets main.version while the variable has been renamed to main.Version, which will break this build.

In this config, main now builds from ./cmd/lets and the variable in cmd/lets/main.go is Version, so -X main.version refers to a non‑existent symbol and will cause the linker step to fail. Update this entry to match the others, e.g. -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.

Stale main.version linker flag — version won't be injected for darwin-amd64

The variable was renamed from version to Version (uppercase) in cmd/lets/main.go, but the darwin-amd64 build still references the old lowercase name. At link time, -X main.version={{.Version}} will silently do nothing because no such symbol exists, so all darwin-amd64 releases will report 0.0.0-dev as the version.

The same issue also appears on line 54 for the linux-amd64 build — only darwin-arm64 (line 41) was correctly updated to -X main.Version={{.Version}}.

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

- id: darwin-arm64
main: .
main: ./cmd/lets
goos:
- darwin
goarch:
Expand All @@ -38,9 +38,9 @@ builds:
flags:
- -mod=readonly
ldflags:
- -s -w -X main.version={{.Version}}
- -s -w -X main.Version={{.Version}}
- id: linux-amd64
main: .
main: ./cmd/lets
goos:
- linux
goarch:
Expand Down
12 changes: 0 additions & 12 deletions .run/lets --version.run.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .run/lets print-env.run.xml

This file was deleted.

11 changes: 0 additions & 11 deletions .run/lets.run.xml

This file was deleted.

44 changes: 22 additions & 22 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}"
},
{
"name": "Run",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceRoot}",
"args": []
}
]
}
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch Package",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}"
},
{
"name": "Run",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceRoot}/cmd/lets/main.go",
"args": []
}
]
}
12 changes: 6 additions & 6 deletions main.go → cmd/lets/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/spf13/cobra"
)

var version = "0.0.0-dev"
var Version = "0.0.0-dev"

func main() {
ctx := getContext()
Expand All @@ -29,11 +29,11 @@ func main() {

logging.InitLogging(os.Stdout, os.Stderr)

rootCmd := cmd.CreateRootCommand(version)
rootCmd := cmd.CreateRootCommand(Version)
rootCmd.InitDefaultHelpFlag()
rootCmd.InitDefaultVersionFlag()
reinitCompletionCmd := cmd.InitCompletionCmd(rootCmd, nil)
cmd.InitSelfCmd(rootCmd, version)
cmd.InitSelfCmd(rootCmd, Version)
rootCmd.InitDefaultHelpCmd()

command, args, err := rootCmd.Traverse(os.Args[1:])
Expand Down Expand Up @@ -66,7 +66,7 @@ func main() {
rootFlags.config = os.Getenv("LETS_CONFIG")
}

cfg, err := config.Load(rootFlags.config, configDir, version)
cfg, err := config.Load(rootFlags.config, configDir, Version)
if err != nil {
if failOnConfigError(rootCmd, command, rootFlags) {
log.Errorf("lets: config error: %s", err)
Expand All @@ -82,7 +82,7 @@ func main() {
if rootFlags.init {
wd, err := os.Getwd()
if err == nil {
err = workdir.InitLetsFile(wd, version)
err = workdir.InitLetsFile(wd, Version)
}

if err != nil {
Expand All @@ -94,7 +94,7 @@ func main() {
}

if rootFlags.upgrade {
upgrader, err := upgrade.NewBinaryUpgrader(registry.NewGithubRegistry(ctx), version)
upgrader, err := upgrade.NewBinaryUpgrader(registry.NewGithubRegistry(ctx), Version)
if err == nil {
err = upgrader.Upgrade()
}
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ services:
- bash
- -c
- |
go build -o /usr/bin/lets *.go
go build -o /usr/bin/lets cmd/lets/main.go
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion (bug_risk): Building a single source file may skip other files in the cmd/lets package; consider building the package path instead.

Building cmd/lets/main.go directly will ignore any other files in the cmd/lets package (e.g., future platform-specific or split-out logic). To match how the binary is normally built and avoid missing code later, prefer go build -o /usr/bin/lets ./cmd/lets instead.

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

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.

Prefer package path over file path for go build

Passing a file path (cmd/lets/main.go) to go build limits compilation to that single file. If any additional .go files are ever added to the cmd/lets package they will be silently excluded. The idiomatic and future-proof form is to pass the package directory, consistent with how .goreleaser.yml references the same entry-point.

The same pattern also appears in lets.yaml at lines 112 and 126.

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

if [[ -n "${LETSOPT_TEST}" ]]; then
bats tests/"${LETSOPT_TEST}" ${LETSOPT_OPTS}
else
Expand Down
4 changes: 4 additions & 0 deletions lets.build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,7 @@ commands:
build-lint-image:
description: Build lets lint docker image
cmd: docker build -t lets-lint -f Dockerfile --target linter .

goreleaser-dev:
description: Run goreleaser to test its build
cmd: goreleaser build --skip=validate --clean
19 changes: 14 additions & 5 deletions lets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ commands:
PATH2LETSDEV=$LETSOPT_PATH
fi

go build -ldflags="-X main.version=${VERSION:1}-dev" -o "${BIN}" *.go && \
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:
description: Build lets from source code
Expand All @@ -120,9 +120,18 @@ commands:
cmd: |
VERSION=$(git describe)
BIN=${LETSOPT_BIN:-lets}

go build -ldflags="-X main.version=${VERSION:1}-dev" -o ${BIN} *.go && \
echo " - binary './${BIN}' (version ${VERSION}) successfully build"

go build \
-ldflags="-X main.Version=${VERSION:1}-dev" \
-o ${BIN} cmd/lets/main.go

success=$?
if [[ $success -eq 0 ]]; then
version=$(./${BIN} --version)
echo " - binary './${BIN}' ($version) successfully build"
else
echo "Failed to build"
Comment on lines +124 to +133
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

issue (bug_risk): The build command failure is swallowed, causing the script to succeed even when the binary was not built.

Because you only echo on failure and don’t exit non‑zero, callers (CI, wrapper scripts) will see this as a successful run even when go build fails. Please propagate the build status (e.g. exit $success in the else branch) or use if go build ...; then ... else exit 1; fi so failures are correctly reported.

fi
Comment on lines +128 to +134
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.

Build failure is silently swallowed — command always exits 0

success=$? correctly captures the go build exit code, but the else branch only echos a message and then falls through to the end of the script. The final command executed is echo "Failed to build", which exits with 0, so lets build will appear to succeed even when the Go compilation failed. This will cause callers (CI, scripts) to believe the build produced a valid binary when it did not.

To propagate the failure, exit explicitly with the captured code:

go build \
  -ldflags="-X main.Version=${VERSION:1}-dev" \
  -o ${BIN} cmd/lets/main.go

success=$?
if [[ $success -eq 0 ]]; then
  version=$(./${BIN} --version)
  echo " - binary './${BIN}' ($version) successfully build"
else
  echo "Failed to build"
  exit $success
fi


publish-docs:
work_dir: docs
Expand Down
30 changes: 15 additions & 15 deletions tests/config_version.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,33 @@ load test_helpers
TEST_VERSION=0.0.2

setup() {
load "${BATS_UTILS_PATH}/bats-support/load.bash"
load "${BATS_UTILS_PATH}/bats-assert/load.bash"
# NOTICE to test this functionality properly we building lets with specified version ${TEST_VERSION}
go build -ldflags="-X main.version=${TEST_VERSION}" -o ./tests/config_version/lets *.go
cd ./tests/config_version
load "${BATS_UTILS_PATH}/bats-support/load.bash"
load "${BATS_UTILS_PATH}/bats-assert/load.bash"
# NOTICE to test this functionality properly we building lets with specified version ${TEST_VERSION}
go build -ldflags="-X main.Version=${TEST_VERSION}" -o ./tests/config_version/lets cmd/lets/main.go
cd ./tests/config_version
}

teardown() {
rm -f ./lets
rm -f ./lets
}

@test "config_version: if config version lower than lets version - its ok" {
LETS_CONFIG=lets-with-version-0.0.1.yaml run ./lets
LETS_CONFIG=lets-with-version-0.0.1.yaml run ./lets

assert_success
assert_line --index 0 "A CLI task runner"
assert_success
assert_line --index 0 "A CLI task runner"
}

@test "config_version: if config version greater than lets version - fail - require upgrade" {
LETS_CONFIG=lets-with-version-0.0.3.yaml run ./lets
LETS_CONFIG=lets-with-version-0.0.3.yaml run ./lets

assert_failure
assert_line --index 0 "lets: config error: config version '0.0.3' is not compatible with 'lets' version '0.0.2'. Please upgrade 'lets' to '0.0.3' using 'lets --upgrade' command or following documentation at https://lets-cli.org/docs/installation'"
assert_failure
assert_line --index 0 "lets: config error: config version '0.0.3' is not compatible with 'lets' version '0.0.2'. Please upgrade 'lets' to '0.0.3' using 'lets --upgrade' command or following documentation at https://lets-cli.org/docs/installation'"
}

@test "config_version: no version specified" {
LETS_CONFIG=lets-without-version.yaml run ./lets
assert_success
assert_line --index 0 "A CLI task runner"
LETS_CONFIG=lets-without-version.yaml run ./lets
assert_success
assert_line --index 0 "A CLI task runner"
}