Update goreleaser config and fix version string

parent 42efe848
Pipeline #86097776 passed with stage
in 53 seconds
......@@ -7,15 +7,15 @@ builds:
- darwin
goarch:
- amd64
archive:
replacements:
darwin: macos
linux: linux
amd64: x86_64
archives:
- replacements:
darwin: macos
linux: linux
amd64: x86_64
checksum:
name_template: 'checksums.txt'
sign:
artifacts: checksum
signs:
- artifacts: checksum
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
......@@ -26,8 +26,7 @@ changelog:
- '^test:'
release:
disable: true
s3:
- bucket: h10n-packages
region: eu-central-1
folder: container-inventory/{{ .Version }}
acl: public-read
blobs:
- provider: gs
bucket: h10n-public-releases
folder: "container-inventory/{{ .Version }}"
......@@ -19,11 +19,16 @@ var quiet bool
var sessions *sessionfile.Manager
var longNames bool
var showVersion bool
var (
version = "dev"
commit = "none"
date = "unknown"
)
// SetVersionInfo allows the main package to inject version information into the
// root command.
func SetVersionInfo(vers, com, dat string) {
if com == "none" {
rootCmd.Version = vers
return
}
rootCmd.Version = fmt.Sprintf("%s (based on commit %s, built on %s)", vers, com, dat)
}
func showSubcommandsList(cmd *cobra.Command) {
fmt.Println("Please use one of the following sub-commands:")
......@@ -33,15 +38,13 @@ func showSubcommandsList(cmd *cobra.Command) {
}
var rootCmd = &cobra.Command{
Use: "cinv",
Use: "container-inventory",
SilenceErrors: true,
SilenceUsage: true,
Run: func(cmd *cobra.Command, args []string) {
showSubcommandsList(cmd)
},
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if showVersion {
fmt.Printf("%v, commit %v, built at %v", version, commit, date)
os.Exit(0)
}
if quiet {
logger = logger.Level(zerolog.ErrorLevel)
} else {
......@@ -67,11 +70,12 @@ func init() {
rootCmd.PersistentFlags().BoolVarP(&longNames, "long", "l", false, "Display long names of tags and repositories including the registry path")
rootCmd.PersistentFlags().BoolVar(&verbose, "verbose", false, "Verbose logging")
rootCmd.PersistentFlags().BoolVar(&quiet, "quiet", false, "Quiet logging")
rootCmd.PersistentFlags().BoolVar(&showVersion, "version", false, "Show version information")
rootCmd.InitDefaultVersionFlag()
}
// MustExecute launches the root command and panics on error.
func MustExecute() {
if err := rootCmd.Execute(); err != nil {
logger.Fatal().Err(err).Msg("cinv failed")
logger.Fatal().Err(err).Msgf("%s failed", rootCmd.Use)
}
}
......@@ -2,6 +2,13 @@ package main
import "gitlab.com/zerok/container-inventory/cmd/container-inventory/cmd"
var (
version = "dev"
commit = "none"
date = "unknown"
)
func main() {
cmd.SetVersionInfo(version, commit, date)
cmd.MustExecute()
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment