diff --git a/.goreleaser.yml b/.goreleaser.yml index 0a4874b..255f467 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -8,18 +8,26 @@ before: - go generate ./... builds: - env: - - CGO_ENABLED=1 + - CGO_ENABLED=0 goos: + - linux - darwin goarch: + - "386" - amd64 - arm - arm64 + - ppc64 + goarm: + - "7" ignore: - - goos: linux - goarch: arm64 - - goos: linux + - goos: windows goarch: arm + mod_timestamp: '{{ .CommitTimestamp }}' + flags: + - -trimpath + ldflags: + - -s -w -X main.version={{.Version}} -X main.commit={{.Commit}} -X main.date={{ .CommitDate }} -X main.builtBy=goreleaser archives: - replacements: darwin: Darwin diff --git a/main.go b/main.go index 51f097d..d27c2ed 100644 --- a/main.go +++ b/main.go @@ -5,7 +5,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, @@ -16,10 +16,44 @@ limitations under the License. package main import ( + "fmt" "github.com/OpenSLO/slogen/cmd" + "runtime" + "runtime/debug" +) + +// nolint: gochecknoglobals +var ( + version = "dev" + commit = "" + date = "" + builtBy = "" ) func main() { + + fmt.Printf("\nrunning version: %s\n\n-------------------\n\n", + buildVersion(version, commit, date, builtBy), + ) + cmd.Execute() +} + +func buildVersion(version, commit, date, builtBy string) string { + result := version + if commit != "" { + result = fmt.Sprintf("%s\ncommit: %s", result, commit) + } + if date != "" { + result = fmt.Sprintf("%s\nbuilt at: %s", result, date) + } + if builtBy != "" { + result = fmt.Sprintf("%s\nbuilt by: %s", result, builtBy) + } + result = fmt.Sprintf("%s\ngoos: %s\ngoarch: %s", result, runtime.GOOS, runtime.GOARCH) + if info, ok := debug.ReadBuildInfo(); ok && info.Main.Sum != "" { + result = fmt.Sprintf("%s\nmodule version: %s, checksum: %s", result, info.Main.Version, info.Main.Sum) + } + return result }