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

Fix CI on Windows #1395

Closed
wants to merge 17 commits into from
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
go.sum linguist-generated
* text=auto eol=lf
*.ps1 text eol=crlf
1 change: 0 additions & 1 deletion .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ jobs:
go-version: 1.15 # test only the latest go version to speed up CI
- name: Run tests
run: make.exe test
continue-on-error: true
tests-on-macos:
needs: golangci-lint # run after golangci-lint action to not produce duplicated errors
runs-on: macos-latest
Expand Down
15 changes: 10 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@
# enable consistent Go 1.12/1.13 GOPROXY behavior.
export GOPROXY = https://proxy.golang.org

BINARY = golangci-lint
ifeq ($(OS),Windows_NT)
BINARY := $(BINARY).exe
endif

# Build

build: golangci-lint
.PHONY: build

build_race:
go build -race -o golangci-lint ./cmd/golangci-lint
go build -race -o $(BINARY) ./cmd/golangci-lint
.PHONY: build_race

clean:
rm -f golangci-lint
rm -f $(BINARY)
rm -f test/path
rm -f tools/Dracula.itermcolors
rm -f tools/godownloader
Expand All @@ -26,12 +31,12 @@ clean:
# Test
test: export GOLANGCI_LINT_INSTALLED = true
test: build
GL_TEST_RUN=1 ./golangci-lint run -v
GL_TEST_RUN=1 ./$(BINARY) run -v
GL_TEST_RUN=1 go test -v -parallel 2 ./...
.PHONY: test

test_race: build_race
GL_TEST_RUN=1 ./golangci-lint run -v --timeout=5m
GL_TEST_RUN=1 ./$(BINARY) run -v --timeout=5m
.PHONY: test_race

test_linters:
Expand Down Expand Up @@ -70,7 +75,7 @@ snapshot: .goreleaser.yml tools/goreleaser
# Non-PHONY targets (real files)

golangci-lint: FORCE
go build -o $@ ./cmd/golangci-lint
go build -o $(BINARY) ./cmd/golangci-lint

tools/godownloader: export GOFLAGS = -mod=readonly
tools/godownloader: tools/go.mod tools/go.sum
Expand Down
7 changes: 0 additions & 7 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions test/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"path/filepath"
)

const testdataDir = "testdata"
const binName = "../golangci-lint"
const (
testdataDir = "testdata"
)

var minimalPkg = getTestDataDir("minimalpkg")

Expand Down
9 changes: 5 additions & 4 deletions test/linters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,17 @@ func TestGciLocal(t *testing.T) {
func saveConfig(t *testing.T, cfg map[string]interface{}) (cfgPath string, finishFunc func()) {
f, err := ioutil.TempFile("", "golangci_lint_test")
assert.NoError(t, err)
name := f.Name()
assert.NoError(t, f.Close())

cfgPath = f.Name() + ".yml"
err = os.Rename(f.Name(), cfgPath)
cfgPath = name + ".yml"
err = os.Rename(name, cfgPath)
assert.NoError(t, err)

err = yaml.NewEncoder(f).Encode(cfg)
assert.NoError(t, err)

return cfgPath, func() {
assert.NoError(t, f.Close())
if os.Getenv("GL_KEEP_TEMP_FILES") != "1" {
assert.NoError(t, os.Remove(cfgPath))
}
Expand Down Expand Up @@ -154,7 +155,7 @@ func testOneSource(t *testing.T, sourcePath string) {

caseArgs = append(caseArgs, sourcePath)

cmd := exec.Command(binName, caseArgs...)
cmd := exec.Command(testshared.BinaryName(), caseArgs...)
t.Log(caseArgs)
runGoErrchk(cmd, []string{sourcePath}, t)
}
Expand Down
22 changes: 18 additions & 4 deletions test/testshared/testshared.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,27 @@ import (
"io/ioutil"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"sync"
"syscall"
"time"

"github.com/stretchr/testify/assert"
assert "github.com/stretchr/testify/require"

"github.com/golangci/golangci-lint/pkg/exitcodes"
"github.com/golangci/golangci-lint/pkg/logutils"
)

func BinaryName() string {
name := filepath.Join("..", "golangci-lint")
if runtime.GOOS == "windows" {
name += ".exe"
}
return name
}

type LintRunner struct {
t assert.TestingT
log logutils.Log
Expand Down Expand Up @@ -96,10 +106,10 @@ func (r *LintRunner) RunCommand(command string, args ...string) *RunResult {

runArgs := append([]string{command}, args...)
defer func(startedAt time.Time) {
r.log.Infof("ran [../golangci-lint %s] in %s", strings.Join(runArgs, " "), time.Since(startedAt))
r.log.Infof("ran [%s %s] in %s", BinaryName(), strings.Join(runArgs, " "), time.Since(startedAt))
}(time.Now())

cmd := exec.Command("../golangci-lint", runArgs...)
cmd := exec.Command(BinaryName(), runArgs...)
cmd.Env = append(os.Environ(), r.env...)
out, err := cmd.CombinedOutput()
if err != nil {
Expand All @@ -114,7 +124,11 @@ func (r *LintRunner) RunCommand(command string, args ...string) *RunResult {
}

r.t.Errorf("can't get error code from %s", err)
return nil
return &RunResult{
t: r.t,
output: err.Error(),
exitCode: -1,
}
}

// success, exitCode should be 0 if go is ok
Expand Down