From 01885017f0dd9e24b0828b360111471f71c1b98d Mon Sep 17 00:00:00 2001 From: Filip Nguyen Date: Wed, 5 Feb 2020 21:59:35 +0100 Subject: [PATCH] Goreleaser (#394) When publishing binaries using Goreleaser use build flags. Also remove custom archives and checksum name_templates because Goreleaser has reasonable defaults, see https://goreleaser.com/customization/#Archive --- .goreleaser.yml | 15 +++++++-------- mockgen/mockgen.go | 18 ++++++++++++++++-- mockgen/version.1.11.go | 2 +- mockgen/version.1.12.go | 2 +- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index edf9277d..2a272d66 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -22,15 +22,14 @@ builds: - GOPROXY=https://proxy.golang.org - GOSUMDB=sum.golang.org main: ./mockgen/ -archive: - format: tar.gz - wrap_in_directory: true - name_template: '{{ .Binary }}-{{ .Version }}-{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}' - files: - - LICENSE - - README.md + +archives: + - format: tar.gz + wrap_in_directory: true + files: + - LICENSE + - README.md checksum: - name_template: '{{ .Binary }}-{{ .Version }}-checksums.txt' snapshot: name_template: "snap-{{ .Commit }}" changelog: diff --git a/mockgen/mockgen.go b/mockgen/mockgen.go index b13885d9..ed87b8e2 100644 --- a/mockgen/mockgen.go +++ b/mockgen/mockgen.go @@ -45,6 +45,12 @@ const ( gomockImportPath = "github.com/golang/mock/gomock" ) +var ( + version = "" + commit = "none" + date = "unknown" +) + var ( source = flag.String("source", "", "(source mode) Input Go source file; enables source mode.") destination = flag.String("destination", "", "Output file; defaults to stdout.") @@ -55,14 +61,14 @@ var ( copyrightFile = flag.String("copyright_file", "", "Copyright file used to add copyright header") debugParser = flag.Bool("debug_parser", false, "Print out parser results only.") - version = flag.Bool("version", false, "Print version.") + showVersion = flag.Bool("version", false, "Print version.") ) func main() { flag.Usage = usage flag.Parse() - if *version { + if *showVersion { printVersion() return } @@ -633,3 +639,11 @@ func lookupPackageName(importPath string) (string, bool) { } return pkg.Name, true } + +func printVersion() { + if version != "" { + fmt.Printf("v%s\nCommit: %s\nDate: %s\n", version, commit, date) + } else { + printModuleVersion() + } +} diff --git a/mockgen/version.1.11.go b/mockgen/version.1.11.go index e47183d2..e6b25db2 100644 --- a/mockgen/version.1.11.go +++ b/mockgen/version.1.11.go @@ -20,7 +20,7 @@ import ( "log" ) -func printVersion() { +func printModuleVersion() { log.Printf("No version information is available for Mockgen compiled with " + "version 1.11") } diff --git a/mockgen/version.1.12.go b/mockgen/version.1.12.go index 3cc2ad83..ad121ae6 100644 --- a/mockgen/version.1.12.go +++ b/mockgen/version.1.12.go @@ -23,7 +23,7 @@ import ( "runtime/debug" ) -func printVersion() { +func printModuleVersion() { if bi, exists := debug.ReadBuildInfo(); exists { fmt.Println(bi.Main.Version) } else {