Skip to content
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

Fixing broken CircleCI build #20

Merged
merged 1 commit into from Oct 14, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions .circleci/config.yml
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -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
Copy link
Owner Author

Choose a reason for hiding this comment

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

Disabling until bombsimon/wsl#38 is fixed it's fixed (but not downstreamed to golangci-lint yet)

Copy link
Owner Author

Choose a reason for hiding this comment

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

Ok, until golangci/golangci-lint#811 is fixed 😂


.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:
Expand Down
7 changes: 7 additions & 0 deletions cmd/which/main.go
Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions internal/tests/integration/basic_test.go
@@ -1,3 +1,5 @@
// +build integration

package integration

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/tests/integration/integration_test.go
@@ -1,3 +1,5 @@
// +build integration

package integration

import (
Expand Down
19 changes: 14 additions & 5 deletions which.go
Expand Up @@ -32,6 +32,7 @@ func which(fs afero.Fs, program ...string) string {
}
}
}

return ""
}

Expand All @@ -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)
Expand All @@ -51,6 +53,7 @@ func all(fs afero.Fs, program ...string) []string {
}
}
}

return out
}

Expand All @@ -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
}

Expand All @@ -87,29 +93,32 @@ 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
}

// isExec returns true when the file at the given path is a regular file with
// 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...
Expand Down
1 change: 1 addition & 0 deletions which_test.go
Expand Up @@ -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)
Expand Down