From 3020f696061d14c68365dd4cb2f35915d6f4804a Mon Sep 17 00:00:00 2001 From: Julien Fabre Date: Tue, 9 May 2023 16:04:09 -0600 Subject: [PATCH] Add .goreleaser.yml and version (#61) --- .goreleaser.yml | 19 +++++++++++++++++++ cmd/wzprof/main.go | 25 +++++++++++++++++-------- 2 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 .goreleaser.yml diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..f955829 --- /dev/null +++ b/.goreleaser.yml @@ -0,0 +1,19 @@ +project_name: wzprof +dist: ./goreleaser/dist + +before: + hooks: + - go mod tidy + +builds: + - main: ./cmd/wzprof/main.go + binary: wzprof + mod_timestamp: '{{ .CommitTimestamp }}' + + ldflags: + - -X main.version={{.Version}} + +release: + github: + owner: stealthrocket + name: wzprof diff --git a/cmd/wzprof/main.go b/cmd/wzprof/main.go index 932d171..bf07944 100644 --- a/cmd/wzprof/main.go +++ b/cmd/wzprof/main.go @@ -175,16 +175,19 @@ func silenceContextCanceled(err error) error { } var ( - pprofAddr string - cpuProfile string - memProfile string - sampleRate float64 - hostProfile bool - hostTime bool - inuseMemory bool - mounts string + pprofAddr string + cpuProfile string + memProfile string + sampleRate float64 + hostProfile bool + hostTime bool + inuseMemory bool + mounts string + printVersion bool ) +var version = "dev" + func init() { log.Default().SetOutput(os.Stderr) flag.StringVar(&pprofAddr, "pprof-addr", "", "Address where to expose a pprof HTTP endpoint.") @@ -195,11 +198,17 @@ func init() { flag.BoolVar(&hostTime, "iowait", false, "Include time spent waiting on I/O in guest CPU profile.") flag.BoolVar(&inuseMemory, "inuse", false, "Include snapshots of memory in use (experimental).") flag.StringVar(&mounts, "mount", "", "Comma-separated list of directories to mount (e.g. /tmp:/tmp:ro).") + flag.BoolVar(&printVersion, "version", false, "Print the wzprof version.") } func run(ctx context.Context) error { flag.Parse() + if printVersion { + fmt.Printf("wzprof version %s\n", version) + return nil + } + args := flag.Args() if len(args) != 1 { // TODO: print flag usage