Skip to content
Merged
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
12 changes: 6 additions & 6 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 @@ -23,9 +23,9 @@ builds:
flags:
- -mod=readonly
ldflags:
- -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 All @@ -51,7 +51,7 @@ builds:
flags:
- -mod=readonly
ldflags:
- -s -w -X main.version={{.Version}}
- -s -w -X main.Version={{.Version}}

archives:
- formats: [tar.gz]
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
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ services:
- bash
- -c
- |
go build -o /usr/bin/lets *.go
go build -buildvcs=false -o /usr/bin/lets ./cmd/lets
ls -l /usr/bin/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 && \
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.


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 && \

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

success=$?
if [[ $success -eq 0 ]]; then
version=$(./${BIN} --version)
echo " - binary './${BIN}' ($version) successfully build"
else
echo "Failed to build"
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"
}