Browse Source

Add GitHub Actions workflows, use golangci-lint

Vlad Gorodetsky 4 years ago
parent
commit
b8c5f7cfe1
6 changed files with 162 additions and 61 deletions
  1. 1 0
      .github/CODEOWNERS
  2. 62 0
      .github/workflows/ci.yml
  3. 74 0
      .golangci.yml
  4. 4 5
      .travis.yml
  5. 19 48
      Makefile
  6. 2 8
      Vagrantfile

+ 1 - 0
.github/CODEOWNERS

@@ -0,0 +1 @@
+* @bai

+ 62 - 0
.github/workflows/ci.yml

@@ -0,0 +1,62 @@
+name: CI
+
+on: push
+
+jobs:
+  test:
+    name: Go ${{ matrix.go-version }} on Ubuntu
+    runs-on: ubuntu-latest
+    strategy:
+      fail-fast: false
+      matrix:
+        go-version: [1.12.x, 1.13.x]
+        platform: [ubuntu-latest]
+
+    env:
+      KAFKA_PEERS: localhost:9091,localhost:9092,localhost:9093,localhost:9094,localhost:9095
+      TOXIPROXY_ADDR: http://localhost:8474
+      KAFKA_INSTALL_ROOT: /home/runner/kafka
+      KAFKA_HOSTNAME: localhost
+      DEBUG: true
+      KAFKA_VERSION: 2.3.0
+      KAFKA_SCALA_VERSION: 2.12
+
+    steps:
+    - uses: actions/checkout@v1
+
+    - name: Setup Go
+      uses: actions/setup-go@v1
+      with:
+        go-version: ${{ matrix.go-version }}
+
+    - uses: actions/cache@v1
+      with:
+        path: ~/go/pkg/mod
+        key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
+        restore-keys: |
+          ${{ runner.os }}-go-
+
+    # See https://github.com/actions/setup-go/issues/14
+    - name: Setup env
+      run: |
+        echo "::set-env name=GOPATH::$(go env GOPATH)"
+        echo "::add-path::$(go env GOPATH)/bin"
+      shell: bash
+
+    - name: Install dependencies
+      run: |
+        curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.23.1
+        export REPOSITORY_ROOT=${GITHUB_WORKSPACE}
+        vagrant/install_cluster.sh
+        vagrant/boot_cluster.sh
+        vagrant/create_topics.sh
+        vagrant/run_java_producer.sh
+
+    - name: Run test suite
+      run: make test
+
+    - name: Run linter
+      run: make lint
+
+    - name: Teardown
+      run: vagrant/halt_cluster.sh

+ 74 - 0
.golangci.yml

@@ -0,0 +1,74 @@
+run:
+  timeout: 5m
+  deadline: 10m
+
+linters-settings:
+  govet:
+    check-shadowing: false
+  golint:
+    min-confidence: 0
+  gocyclo:
+    min-complexity: 95
+  maligned:
+    suggest-new: true
+  dupl:
+    threshold: 100
+  goconst:
+    min-len: 2
+    min-occurrences: 3
+  misspell:
+    locale: US
+  goimports:
+    local-prefixes: github.com/Shopify/sarama
+  gocritic:
+    enabled-tags:
+      - diagnostic
+      - experimental
+      - opinionated
+      - performance
+      - style
+    disabled-checks:
+      - wrapperFunc
+      - ifElseChain
+  funlen:
+    lines: 300
+    statements: 300
+
+linters:
+  disable-all: true
+  enable:
+    - bodyclose
+    # - deadcode
+    - depguard
+    - dogsled
+    # - dupl
+    # - errcheck
+    - funlen
+    # - gocritic
+    - gocyclo
+    - gofmt
+    # - goimports
+    # - golint
+    # - gosec
+    # - gosimple
+    - govet
+    # - ineffassign
+    # - interfacer
+    # - misspell
+    # - nakedret
+    # - scopelint
+    # - staticcheck
+    # - structcheck
+    # - stylecheck
+    - typecheck
+    # - unconvert
+    # - unused
+    # - varcheck
+    - whitespace
+    # - goconst
+    # - gochecknoinits
+
+issues:
+  exclude:
+    - consider giving a name to these results
+    - include an explanation for nolint directive

+ 4 - 5
.travis.yml

@@ -1,4 +1,4 @@
-dist: xenial
+dist: bionic
 language: go
 go:
 - 1.12.x
@@ -22,13 +22,12 @@ before_install:
 - vagrant/create_topics.sh
 - vagrant/run_java_producer.sh
 
-install: make install_dependencies
+before_script:
+- curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.23.1
 
 script:
 - make test
-- make vet
-- make errcheck
-- if [[ "$TRAVIS_GO_VERSION" == 1.13* ]]; then make fmt; fi
+- make lint
 
 after_success:
 - go tool cover -func coverage.txt

+ 19 - 48
Makefile

@@ -1,56 +1,27 @@
-export GO111MODULE=on
+default: fmt get update test lint
 
-default: fmt vet errcheck test lint
+GO       := GO111MODULE=on GOPRIVATE=github.com/linkedin GOSUMDB=off go
+GOBUILD  := CGO_ENABLED=0 $(GO) build $(BUILD_FLAG)
+GOTEST   := $(GO) test -gcflags='-l' -p 3 -v -race -timeout 6m -coverprofile=profile.out -covermode=atomic
 
-# Taken from https://github.com/codecov/example-go#caveat-multiple-files
-.PHONY: test
-test:
-	echo "mode: atomic" > coverage.txt
-	for d in `go list ./...`; do \
-		go test -p 1 -v -timeout 6m -race -coverprofile=profile.out -covermode=atomic $$d || exit 1; \
-		if [ -f profile.out ]; then \
-			tail +2 profile.out >> coverage.txt; \
-			rm profile.out; \
-		fi \
-	done
-
-GOLINT := $(shell command -v golint)
+FILES    := $(shell find . -name '*.go' -type f -not -name '*.pb.go' -not -name '*_generated.go' -not -name '*_test.go')
+TESTS    := $(shell find . -name '*.go' -type f -not -name '*.pb.go' -not -name '*_generated.go' -name '*_test.go')
 
-.PHONY: lint
-lint:
-ifndef GOLINT
-	go get golang.org/x/lint/golint
-endif
-	go list ./... | xargs golint
-
-.PHONY: vet
-vet:
-	go vet ./...
+get:
+	$(GO) get ./...
+	$(GO) mod verify
+	$(GO) mod tidy
 
-ERRCHECK := $(shell command -v errcheck)
-# See https://github.com/kisielk/errcheck/pull/141 for details on ignorepkg
-.PHONY: errcheck
-errcheck:
-ifndef ERRCHECK
-	go get github.com/kisielk/errcheck
-endif
-	errcheck -ignorepkg fmt github.com/Shopify/sarama/...
+update:
+	$(GO) get -u -v all
+	$(GO) mod verify
+	$(GO) mod tidy
 
-.PHONY: fmt
 fmt:
-	@if [ -n "$$(go fmt ./...)" ]; then echo 'Please run go fmt on your code.' && exit 1; fi
+	gofmt -s -l -w $(FILES) $(TESTS)
 
-.PHONY : install_dependencies
-install_dependencies: get
-
-.PHONY: get
-get:
-	go get -v ./...
-
-.PHONY: clean
-clean:
-	go clean ./...
+lint:
+	golangci-lint run
 
-.PHONY: tidy
-tidy:
-	go mod tidy -v
+test:
+	$(GOTEST) ./...

+ 2 - 8
Vagrantfile

@@ -1,14 +1,8 @@
-# -*- mode: ruby -*-
-# vi: set ft=ruby :
-
-# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
-VAGRANTFILE_API_VERSION = "2"
-
 # We have 5 * 192MB ZK processes and 5 * 320MB Kafka processes => 2560MB
 MEMORY = 3072
 
-Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
-  config.vm.box = "ubuntu/trusty64"
+Vagrant.configure("2") do |config|
+  config.vm.box = "ubuntu/bionic64"
 
   config.vm.provision :shell, path: "vagrant/provision.sh"