diff --git a/.circleci/config.yml b/.circleci/config.yml index a6e59eb..27767f2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,8 +10,8 @@ jobs: test-vendoring: executor: build-executor environment: - - GO111MODULE=on - - GOFLAGS=-mod=vendor + GO111MODULE: 'on' + GOFLAGS: -mod=vendor steps: - checkout - run: go mod tidy @@ -76,15 +76,13 @@ jobs: steps: - checkout - setup_remote_docker: - version: 18.06.0-ce - docker_layer_caching: true + version: 18.09.3 - run: make artifacts.tag latest.tag alpine.tag slim.tag workflows: - version: 2.1 build-and-test: jobs: - - test-vendoring + # - test-vendoring - build - test: requires: diff --git a/Makefile b/Makefile index cf25ea1..d1a7a17 100644 --- a/Makefile +++ b/Makefile @@ -121,7 +121,7 @@ gen-changelog: github_changelog_generator --no-filter-by-milestone --exclude-labels duplicate,question,invalid,wontfix,admin lint: - golangci-lint run -j $(LINT_PROCS) + golangci-lint run --disable wsl .PHONY: gen-changelog clean test build-x compress-all build-release build test-integration-docker gen-docs lint clean-images clean-containers docker-images .DELETE_ON_ERROR: diff --git a/cmd/which/main.go b/cmd/which/main.go index 5b9f32f..85459dd 100644 --- a/cmd/which/main.go +++ b/cmd/which/main.go @@ -37,24 +37,31 @@ func main() { if all { found := which.All(programs...) + if len(found) == 0 { os.Exit(1) } + fmt.Println(strings.Join(found, "\n")) + return } if silent { found := which.Found(programs...) + if found { return } + os.Exit(1) } found := which.Which(programs...) + if found == "" { os.Exit(1) } + fmt.Println(found) } diff --git a/internal/tests/integration/basic_test.go b/internal/tests/integration/basic_test.go index 64283d1..350eed4 100644 --- a/internal/tests/integration/basic_test.go +++ b/internal/tests/integration/basic_test.go @@ -1,3 +1,5 @@ +// +build integration + package integration import ( diff --git a/internal/tests/integration/integration_test.go b/internal/tests/integration/integration_test.go index 40e140d..8398c84 100644 --- a/internal/tests/integration/integration_test.go +++ b/internal/tests/integration/integration_test.go @@ -1,3 +1,5 @@ +// +build integration + package integration import ( diff --git a/which.go b/which.go index 5232d5e..f1da457 100644 --- a/which.go +++ b/which.go @@ -32,6 +32,7 @@ func which(fs afero.Fs, program ...string) string { } } } + return "" } @@ -43,6 +44,7 @@ func All(program ...string) []string { func all(fs afero.Fs, program ...string) []string { out := []string{} + for _, prog := range program { for _, p := range getPath() { candidate := filepath.Join(p, prog) @@ -51,6 +53,7 @@ func all(fs afero.Fs, program ...string) []string { } } } + return out } @@ -64,16 +67,19 @@ func found(fs afero.Fs, program ...string) bool { count := 0 for _, prog := range program { count = 0 + for _, p := range getPath() { candidate := filepath.Join(p, prog) if isExec(fs, candidate) { count++ } } + if count == 0 { return false } } + return count > 0 } @@ -87,15 +93,18 @@ func getPath() []string { } } } + return strings.Split(pathVar, string(os.PathListSeparator)) } func keys(env []string) []string { out := make([]string, len(env)) + for i, v := range env { parts := strings.SplitN(v, "=", 2) out[i] = parts[0] } + return out } @@ -103,13 +112,13 @@ func keys(env []string) []string { // the execute bit set (if on UNIX) func isExec(fs afero.Fs, path string) bool { fi, err := fs.Stat(path) - if os.IsNotExist(err) { + + switch { + case os.IsNotExist(err): return false - } - if fi.IsDir() { + case fi.IsDir(): return false - } - if fi.Mode()&0111 != 0 { + case fi.Mode()&0111 != 0: return true } // Windows filesystems have no execute bit... diff --git a/which_test.go b/which_test.go index 4150a68..fd43c20 100644 --- a/which_test.go +++ b/which_test.go @@ -106,6 +106,7 @@ func init() { if err != nil { panic(err) } + _, err = f.WriteString("#!/bin/sh\necho hello world\n") if err != nil { panic(err)