Skip to content

Commit b8c5f7c

Browse files
committed
Add GitHub Actions workflows, use golangci-lint
1 parent 5c53498 commit b8c5f7c

File tree

6 files changed

+162
-61
lines changed

6 files changed

+162
-61
lines changed

.github/CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @bai

.github/workflows/ci.yml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: CI
2+
3+
on: push
4+
5+
jobs:
6+
test:
7+
name: Go ${{ matrix.go-version }} on Ubuntu
8+
runs-on: ubuntu-latest
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
go-version: [1.12.x, 1.13.x]
13+
platform: [ubuntu-latest]
14+
15+
env:
16+
KAFKA_PEERS: localhost:9091,localhost:9092,localhost:9093,localhost:9094,localhost:9095
17+
TOXIPROXY_ADDR: http://localhost:8474
18+
KAFKA_INSTALL_ROOT: /home/runner/kafka
19+
KAFKA_HOSTNAME: localhost
20+
DEBUG: true
21+
KAFKA_VERSION: 2.3.0
22+
KAFKA_SCALA_VERSION: 2.12
23+
24+
steps:
25+
- uses: actions/checkout@v1
26+
27+
- name: Setup Go
28+
uses: actions/setup-go@v1
29+
with:
30+
go-version: ${{ matrix.go-version }}
31+
32+
- uses: actions/cache@v1
33+
with:
34+
path: ~/go/pkg/mod
35+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
36+
restore-keys: |
37+
${{ runner.os }}-go-
38+
39+
# See https://github.com/actions/setup-go/issues/14
40+
- name: Setup env
41+
run: |
42+
echo "::set-env name=GOPATH::$(go env GOPATH)"
43+
echo "::add-path::$(go env GOPATH)/bin"
44+
shell: bash
45+
46+
- name: Install dependencies
47+
run: |
48+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.23.1
49+
export REPOSITORY_ROOT=${GITHUB_WORKSPACE}
50+
vagrant/install_cluster.sh
51+
vagrant/boot_cluster.sh
52+
vagrant/create_topics.sh
53+
vagrant/run_java_producer.sh
54+
55+
- name: Run test suite
56+
run: make test
57+
58+
- name: Run linter
59+
run: make lint
60+
61+
- name: Teardown
62+
run: vagrant/halt_cluster.sh

.golangci.yml

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
run:
2+
timeout: 5m
3+
deadline: 10m
4+
5+
linters-settings:
6+
govet:
7+
check-shadowing: false
8+
golint:
9+
min-confidence: 0
10+
gocyclo:
11+
min-complexity: 95
12+
maligned:
13+
suggest-new: true
14+
dupl:
15+
threshold: 100
16+
goconst:
17+
min-len: 2
18+
min-occurrences: 3
19+
misspell:
20+
locale: US
21+
goimports:
22+
local-prefixes: github.com/Shopify/sarama
23+
gocritic:
24+
enabled-tags:
25+
- diagnostic
26+
- experimental
27+
- opinionated
28+
- performance
29+
- style
30+
disabled-checks:
31+
- wrapperFunc
32+
- ifElseChain
33+
funlen:
34+
lines: 300
35+
statements: 300
36+
37+
linters:
38+
disable-all: true
39+
enable:
40+
- bodyclose
41+
# - deadcode
42+
- depguard
43+
- dogsled
44+
# - dupl
45+
# - errcheck
46+
- funlen
47+
# - gocritic
48+
- gocyclo
49+
- gofmt
50+
# - goimports
51+
# - golint
52+
# - gosec
53+
# - gosimple
54+
- govet
55+
# - ineffassign
56+
# - interfacer
57+
# - misspell
58+
# - nakedret
59+
# - scopelint
60+
# - staticcheck
61+
# - structcheck
62+
# - stylecheck
63+
- typecheck
64+
# - unconvert
65+
# - unused
66+
# - varcheck
67+
- whitespace
68+
# - goconst
69+
# - gochecknoinits
70+
71+
issues:
72+
exclude:
73+
- consider giving a name to these results
74+
- include an explanation for nolint directive

.travis.yml

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
dist: xenial
1+
dist: bionic
22
language: go
33
go:
44
- 1.12.x
@@ -22,13 +22,12 @@ before_install:
2222
- vagrant/create_topics.sh
2323
- vagrant/run_java_producer.sh
2424

25-
install: make install_dependencies
25+
before_script:
26+
- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.23.1
2627

2728
script:
2829
- make test
29-
- make vet
30-
- make errcheck
31-
- if [[ "$TRAVIS_GO_VERSION" == 1.13* ]]; then make fmt; fi
30+
- make lint
3231

3332
after_success:
3433
- go tool cover -func coverage.txt

Makefile

+19-48
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,27 @@
1-
export GO111MODULE=on
1+
default: fmt get update test lint
22

3-
default: fmt vet errcheck test lint
3+
GO := GO111MODULE=on GOPRIVATE=github.com/linkedin GOSUMDB=off go
4+
GOBUILD := CGO_ENABLED=0 $(GO) build $(BUILD_FLAG)
5+
GOTEST := $(GO) test -gcflags='-l' -p 3 -v -race -timeout 6m -coverprofile=profile.out -covermode=atomic
46

5-
# Taken from https://github.com/codecov/example-go#caveat-multiple-files
6-
.PHONY: test
7-
test:
8-
echo "mode: atomic" > coverage.txt
9-
for d in `go list ./...`; do \
10-
go test -p 1 -v -timeout 6m -race -coverprofile=profile.out -covermode=atomic $$d || exit 1; \
11-
if [ -f profile.out ]; then \
12-
tail +2 profile.out >> coverage.txt; \
13-
rm profile.out; \
14-
fi \
15-
done
16-
17-
GOLINT := $(shell command -v golint)
7+
FILES := $(shell find . -name '*.go' -type f -not -name '*.pb.go' -not -name '*_generated.go' -not -name '*_test.go')
8+
TESTS := $(shell find . -name '*.go' -type f -not -name '*.pb.go' -not -name '*_generated.go' -name '*_test.go')
189

19-
.PHONY: lint
20-
lint:
21-
ifndef GOLINT
22-
go get golang.org/x/lint/golint
23-
endif
24-
go list ./... | xargs golint
25-
26-
.PHONY: vet
27-
vet:
28-
go vet ./...
10+
get:
11+
$(GO) get ./...
12+
$(GO) mod verify
13+
$(GO) mod tidy
2914

30-
ERRCHECK := $(shell command -v errcheck)
31-
# See https://github.com/kisielk/errcheck/pull/141 for details on ignorepkg
32-
.PHONY: errcheck
33-
errcheck:
34-
ifndef ERRCHECK
35-
go get github.com/kisielk/errcheck
36-
endif
37-
errcheck -ignorepkg fmt github.com/Shopify/sarama/...
15+
update:
16+
$(GO) get -u -v all
17+
$(GO) mod verify
18+
$(GO) mod tidy
3819

39-
.PHONY: fmt
4020
fmt:
41-
@if [ -n "$$(go fmt ./...)" ]; then echo 'Please run go fmt on your code.' && exit 1; fi
21+
gofmt -s -l -w $(FILES) $(TESTS)
4222

43-
.PHONY : install_dependencies
44-
install_dependencies: get
45-
46-
.PHONY: get
47-
get:
48-
go get -v ./...
49-
50-
.PHONY: clean
51-
clean:
52-
go clean ./...
23+
lint:
24+
golangci-lint run
5325

54-
.PHONY: tidy
55-
tidy:
56-
go mod tidy -v
26+
test:
27+
$(GOTEST) ./...

Vagrantfile

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
1-
# -*- mode: ruby -*-
2-
# vi: set ft=ruby :
3-
4-
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
5-
VAGRANTFILE_API_VERSION = "2"
6-
71
# We have 5 * 192MB ZK processes and 5 * 320MB Kafka processes => 2560MB
82
MEMORY = 3072
93

10-
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
11-
config.vm.box = "ubuntu/trusty64"
4+
Vagrant.configure("2") do |config|
5+
config.vm.box = "ubuntu/bionic64"
126

137
config.vm.provision :shell, path: "vagrant/provision.sh"
148

0 commit comments

Comments
 (0)