Skip to content

Commit

Permalink
use golangci-lint and GitHub Actions (spf13#876) (spf13#968) (spf13#1044
Browse files Browse the repository at this point in the history
)
  • Loading branch information
umarcor committed Sep 25, 2020
1 parent 20e85a4 commit 72c92fb
Show file tree
Hide file tree
Showing 34 changed files with 486 additions and 519 deletions.
1 change: 1 addition & 0 deletions .gitattributes
@@ -0,0 +1 @@
* text=auto
58 changes: 58 additions & 0 deletions .github/workflows/push.yml
@@ -0,0 +1,58 @@
name: 'push'

on:
push:
pull_request:

env:
GO111MODULE: on

jobs:

test:
strategy:
fail-fast: false
matrix:
os: [ ubuntu, windows, macOS ]
go: [
1.12.x,
1.13.x,
1.14.x
]

runs-on: ${{ matrix.os }}-latest

steps:

- name: Setup go
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go }}


- run: git config --global core.autocrlf input
if: matrix.os == 'windows'
shell: bash

- uses: actions/checkout@v2

- name: Install golangci-lint, richgo and gox
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $HOME/go/bin/ latest
go install github.com/kyoh86/richgo
go install github.com/mitchellh/gox
- name: Run tests
shell: bash
run: |
export PATH=$PATH:$HOME/go/bin/
make test
- name: Check formatting
run: make fmt

- name: Build generator
shell: bash
run: |
export PATH=$PATH:$HOME/go/bin/
make cobra_generator
48 changes: 48 additions & 0 deletions .golangci.yml
@@ -0,0 +1,48 @@
run:
deadline: 5m

linters:
disable-all: true
enable:
#- bodyclose
- deadcode
#- depguard
#- dogsled
#- dupl
- errcheck
#- exhaustive
#- funlen
- gas
#- gochecknoinits
- goconst
#- gocritic
#- gocyclo
#- gofmt
- goimports
- golint
#- gomnd
#- goprintffuncname
#- gosec
#- gosimple
- govet
- ineffassign
- interfacer
#- lll
- maligned
- megacheck
#- misspell
#- nakedret
#- noctx
#- nolintlint
#- rowserrcheck
#- scopelint
#- staticcheck
- structcheck
#- stylecheck
#- typecheck
- unconvert
#- unparam
#- unused
- varcheck
#- whitespace
fast: false
7 changes: 3 additions & 4 deletions .travis.yml
@@ -1,7 +1,6 @@
language: go

stages:
- diff
- test
- build

Expand All @@ -10,9 +9,12 @@ go:
- 1.13.x
- tip

env: GO111MODULE=on

before_install:
- go get -u github.com/kyoh86/richgo
- go get -u github.com/mitchellh/gox
- curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin latest

env:
- GO111MODULE=on
Expand All @@ -21,9 +23,6 @@ matrix:
allow_failures:
- go: tip
include:
- stage: diff
go: 1.13.x
script: make fmt
- stage: build
go: 1.13.x
script: make cobra_generator
Expand Down
18 changes: 11 additions & 7 deletions Makefile
@@ -1,21 +1,29 @@
BIN="./bin"
SRC=$(shell find . -name "*.go")

ifeq (, $(shell which golangci-lint))
$(warning "could not find golangci-lint in $(PATH), run: curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh")
endif

ifeq (, $(shell which richgo))
$(warning "could not find richgo in $(PATH), run: go get github.com/kyoh86/richgo")
endif

.PHONY: fmt vet test cobra_generator install_deps clean
.PHONY: fmt lint test cobra_generator install_deps clean

default: all

all: fmt vet test cobra_generator
all: fmt test cobra_generator

fmt:
$(info ******************** checking formatting ********************)
@test -z $(shell gofmt -l $(SRC)) || (gofmt -d $(SRC); exit 1)

test: install_deps vet
lint:
$(info ******************** running lint tools ********************)
golangci-lint run -v

test: install_deps lint
$(info ******************** running tests ********************)
richgo test -v ./...

Expand All @@ -28,9 +36,5 @@ install_deps:
$(info ******************** downloading dependencies ********************)
go get -v ./...

vet:
$(info ******************** vetting ********************)
go vet ./...

clean:
rm -rf $(BIN)
13 changes: 2 additions & 11 deletions README.md
Expand Up @@ -194,7 +194,6 @@ import (
"fmt"
"os"

homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
Expand Down Expand Up @@ -234,27 +233,19 @@ func init() {
rootCmd.AddCommand(initCmd)
}

func er(msg interface{}) {
fmt.Println("Error:", msg)
os.Exit(1)
}

func initConfig() {
if cfgFile != "" {
// Use config file from the flag.
viper.SetConfigFile(cfgFile)
} else {
// Find home directory.
home, err := homedir.Dir()
if err != nil {
er(err)
}
home, err := os.UserHomeDir()
cobra.CheckErr(err)

// Search config in home directory with name ".cobra" (without extension).
viper.AddConfigPath(home)
viper.SetConfigName(".cobra")
}

viper.AutomaticEnv()

if err := viper.ReadInConfig(); err == nil {
Expand Down

0 comments on commit 72c92fb

Please sign in to comment.