diff --git a/.gitignore b/.gitignore index c3fc4df0..2684191a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /*.txt /*.pprof +/dist/ \ No newline at end of file diff --git a/.golangci.yml b/.golangci.yml index 00de0bd0..70ffa40e 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,5 +1,4 @@ run: - deadline: 30s tests: true linters-settings: diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 00000000..eec557b0 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,68 @@ +--- +project_name: golangci-lint + +release: + github: + owner: golangci + name: golangci-lint + +builds: + - binary: golangci-lint + goos: &goos + - darwin + - windows + - linux + goarch: &goarch + - amd64 + - i386 + env: + - CGO_ENABLED=0 + main: ./cmd/golangci-lint/ + ldflags: -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{.Date}} + +archive: + format: tar.gz + wrap_in_directory: true + format_overrides: + - goos: windows + format: zip + name_template: '{{ .Binary }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}' + files: + - LICENSE + - README.md + +snapshot: + name_template: SNAPSHOT-{{ .Commit }} + +checksum: + name_template: '{{ .ProjectName }}-{{ .Version }}-checksums.txt' + +changelog: + sort: asc + filters: + exclude: + - '^docs:' + - '^test:' + - 'README.md' + - Merge pull request + - Merge branch + +dockers: +- image: golangci/golangci-lint + tag_templates: + - '{{ .Tag }}' + - 'v{{ .Major }}.{{ .Minor }}' + - 'latest' + +brew: + github: + owner: golangci + name: golangci-lint-formula + folder: Formula + homepage: https://golangci.com + description: Fast linters runner for Go. + test: | + system "#{bin}/golangci-lint --version" + +git: + short_hash: true \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index cf6a248f..54177899 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,3 +4,18 @@ go: - 1.9.x - 1.10.x script: make test + +after_success: + - test -n "$TRAVIS_TAG" && docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" + +# needed for the docker pipe +services: +- docker + +deploy: +- provider: script + skip_cleanup: true + script: curl -sL https://git.io/goreleaser | bash + on: + tags: true + condition: $TRAVIS_GO_VERSION =~ ^1\.10\.[0-9]+$ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..9931954f --- /dev/null +++ b/Dockerfile @@ -0,0 +1,3 @@ +FROM scratch +COPY golangci-lint / +ENTRYPOINT ["/golangci-lint"] \ No newline at end of file diff --git a/cmd/golangci-lint/main.go b/cmd/golangci-lint/main.go index e67d1e97..bad87e8b 100644 --- a/cmd/golangci-lint/main.go +++ b/cmd/golangci-lint/main.go @@ -4,8 +4,15 @@ import ( "github.com/golangci/golangci-lint/pkg/commands" ) +var ( + // Populated by goreleaser during build + version = "master" + commit = "?" + date = "" +) + func main() { - e := commands.NewExecutor() + e := commands.NewExecutor(version, commit, date) if err := e.Execute(); err != nil { panic(err) } diff --git a/pkg/commands/executor.go b/pkg/commands/executor.go index ad941441..ee8fdfb9 100644 --- a/pkg/commands/executor.go +++ b/pkg/commands/executor.go @@ -11,9 +11,11 @@ type Executor struct { cfg *config.Config exitCode int + + version, commit, date string } -func NewExecutor() *Executor { +func NewExecutor(version, commit, date string) *Executor { e := &Executor{ cfg: &config.Config{}, } @@ -22,6 +24,10 @@ func NewExecutor() *Executor { e.initRun() e.initLinters() + e.version = version + e.commit = commit + e.date = date + return e } diff --git a/pkg/commands/root.go b/pkg/commands/root.go index 984f8e26..56814298 100644 --- a/pkg/commands/root.go +++ b/pkg/commands/root.go @@ -1,11 +1,13 @@ package commands import ( + "fmt" "log" "os" "runtime" "runtime/pprof" + "github.com/golangci/golangci-lint/pkg/printers" "github.com/sirupsen/logrus" "github.com/spf13/cobra" ) @@ -21,6 +23,11 @@ func (e *Executor) initRoot() { } }, PersistentPreRun: func(cmd *cobra.Command, args []string) { + if e.cfg.Run.PrintVersion { + fmt.Fprintf(printers.StdOut, "golangci-lint has version %s built from %s on %s\n", e.version, e.commit, e.date) + os.Exit(0) + } + runtime.GOMAXPROCS(e.cfg.Run.Concurrency) log.SetFlags(0) // don't print time @@ -62,6 +69,7 @@ func (e *Executor) initRoot() { rootCmd.PersistentFlags().StringVar(&e.cfg.Run.CPUProfilePath, "cpu-profile-path", "", "Path to CPU profile output file") rootCmd.PersistentFlags().StringVar(&e.cfg.Run.MemProfilePath, "mem-profile-path", "", "Path to memory profile output file") rootCmd.PersistentFlags().IntVarP(&e.cfg.Run.Concurrency, "concurrency", "j", runtime.NumCPU(), "Concurrency (default NumCPU)") + rootCmd.PersistentFlags().BoolVar(&e.cfg.Run.PrintVersion, "version", false, "Print version") e.rootCmd = rootCmd } diff --git a/pkg/config/config.go b/pkg/config/config.go index 7ac9034c..3ae69dd9 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -55,6 +55,7 @@ type Run struct { ExitCodeIfIssuesFound int `mapstructure:"issues-exit-code"` AnalyzeTests bool `mapstructure:"tests"` Deadline time.Duration + PrintVersion bool } type LintersSettings struct {