Skip to content

Commit

Permalink
Add CircleCI testing and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeShu committed Nov 21, 2020
1 parent 7b467d3 commit 8b55470
Show file tree
Hide file tree
Showing 22 changed files with 751 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .circleci/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/coveralls
/golangci-lint
35 changes: 35 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: 2.1

jobs:

"test":
docker:
- image: golang:1.15
resource_class: small
steps:
- checkout
- run: make test
- run:
name: "Generate code-coverage report"
command: |
set -e
if test -e dlib.cov; then
make .circleci/goveralls
.circleci/goveralls -coverprofile=dlib.cov -service=circle-ci -repotoken=$COVERALLS_TOKEN
fi
when: always

"lint":
docker:
- image: golang:1.15
resource_class: small
steps:
- checkout
- run: make lint

workflows:

"dlib":
jobs:
- "test"
- "lint"
1 change: 1 addition & 0 deletions .circleci/errcheck-exclude.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(*os.Process).Signal
5 changes: 5 additions & 0 deletions .circleci/golangci-lint.d/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module local

go 1.15

require github.com/golangci/golangci-lint v1.32.2
614 changes: 614 additions & 0 deletions .circleci/golangci-lint.d/go.sum

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions .circleci/golangci-lint.d/pin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// +build pin

package ignore

import "github.com/golangci/golangci-lint/cmd/golangci-lint"
5 changes: 5 additions & 0 deletions .circleci/goveralls.d/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module local

go 1.15

require github.com/mattn/goveralls v0.0.7
22 changes: 22 additions & 0 deletions .circleci/goveralls.d/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
github.com/mattn/goveralls v0.0.7 h1:vzy0i4a2iDzEFMdXIxcanRadkr0FBvSBKUmj0P8SPlQ=
github.com/mattn/goveralls v0.0.7/go.mod h1:h8b4ow6FxSPMQHF6o2ve3qsclnffZjYTNEKmLesRwqw=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.2.0 h1:KU7oHjnv3XNWfa5COkzUifxZmxp1TyI7ImMXqFxLwvQ=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200522201501-cb1345f3a375 h1:SjQ2+AKWgZLc1xej6WSzL+Dfs5Uyd5xcZH1mGC411IA=
golang.org/x/tools v0.0.0-20200522201501-cb1345f3a375/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
5 changes: 5 additions & 0 deletions .circleci/goveralls.d/pin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// +build pin

package ignore

import "github.com/mattn/goveralls"
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.cov
*.cov.html
vendor/
21 changes: 21 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
linters:
enable:
- nolintlint
disable:
- unused # broken, gives false positives
linters-settings:
gofmt:
simplify: true
goimports:
local-prefixes: github.com/datawire/dlib
errcheck:
exclude: "./.circleci/errcheck-exclude.txt"
nolintlint:
allow-leading-space: false
issues:
exclude-rules:
- path: "/borrowed_"
text: ".*"
- path: "^dcontext/hardsoft_example_test\\.go$"
linters: ["govet"]
text: "lostcancel|tests: .* should return nothing"
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
help:
@echo 'Usage:'
@echo ' make help'
@echo ' make test'
@echo ' make dlib.cov.html'
@echo ' make lint'
.PHONY: help

dlib.cov: test
test:
go test -coverprofile=dlib.cov -race ./...
.PHONY: test

%.cov.html: %.cov
go tool cover -html=$< -o=$@

.circleci/%: .circleci/%.d/go.mod .circleci/%.d/pin.go
cd $(<D) && go build -o ../$(@F) $$(sed -En 's,^import "(.*)"$$,\1,p' pin.go)

lint: .circleci/golangci-lint
.circleci/golangci-lint run ./...
.PHONY: lint

.SECONDARY:
1 change: 1 addition & 0 deletions dcontext/callee_example_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:deadcode
package dcontext_test

import (
Expand Down
1 change: 1 addition & 0 deletions dcontext/polling_example_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:deadcode,errcheck
package dcontext_test

import (
Expand Down
2 changes: 1 addition & 1 deletion derrgroup/errgroup_example_md5all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func MD5All(ctx context.Context, root string) (map[string][md5.Size]byte, error)
})
}
go func() {
g.Wait()
_ = g.Wait()
close(c)
}()

Expand Down
1 change: 0 additions & 1 deletion dexec/borrowed_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//nolint // MODIFIED
package dexec_test // MODIFIED

import (
Expand Down
2 changes: 0 additions & 2 deletions dexec/borrowed_exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//nolint // MODIFIED

package dexec // MODIFIED

import (
Expand Down
1 change: 0 additions & 1 deletion dexec/borrowed_exec_posix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris

//nolint // MODIFIED
package dexec_test // MODIFIED

import (
Expand Down
1 change: 0 additions & 1 deletion dexec/borrowed_exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// Use an external test to avoid os/exec -> net/http -> crypto/x509 -> os/exec
// circular dependency on non-cgo darwin.

//nolint // MODIFIED
package dexec_test // MODIFIED

import (
Expand Down
2 changes: 1 addition & 1 deletion dexec/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func (c *Cmd) Start() error {
case <-dcontext.HardContext(c.ctx).Done(): // hard shutdown
// let os/exec send SIGKILL
case <-c.ctx.Done(): // soft shutdown
c.Cmd.Process.Signal(os.Interrupt) // send SIGINT
_ = c.Cmd.Process.Signal(os.Interrupt) // send SIGINT
case <-c.waitDone:
// it exited on its own
}
Expand Down
2 changes: 1 addition & 1 deletion dgroup/errgroup_example_md5all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func MD5All(ctx context.Context, root string) (map[string][md5.Size]byte, error)
})
}
go func() {
g.Wait()
_ = g.Wait()
close(c)
}()

Expand Down
8 changes: 4 additions & 4 deletions dutil/panic.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ func (pe panicError) StackTrace() errors.StackTrace { return pe.err.StackTrace()
func (pe panicError) Format(s fmt.State, verb rune) {
switch verb {
case 'v':
io.WriteString(s, "PANIC: ")
_, _ = io.WriteString(s, "PANIC: ")
if s.Flag('+') {
fmt.Fprintf(s, "%v", pe.err)
pe.StackTrace().Format(s, verb)
return
}
io.WriteString(s, pe.err.Error())
_, _ = io.WriteString(s, pe.err.Error())
case 's':
io.WriteString(s, pe.Error())
_, _ = io.WriteString(s, pe.Error())
case 'q':
fmt.Fprintf(s, "%q", pe.Error())
_, _ = fmt.Fprintf(s, "%q", pe.Error())
}
}

Expand Down

0 comments on commit 8b55470

Please sign in to comment.