Skip to content

Commit

Permalink
feat: optimize version output (#412)
Browse files Browse the repository at this point in the history
* feat: optimize version output

Signed-off-by: yxxhero <aiopsclub@163.com>

* Update docs/index.md

Signed-off-by: yxxhero <aiopsclub@163.com>

Signed-off-by: yxxhero <aiopsclub@163.com>
Co-authored-by: Yusuke Kuoka <ykuoka@gmail.com>
  • Loading branch information
yxxhero and mumoshu committed Oct 8, 2022
1 parent 1449640 commit 8f7796b
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 96 deletions.
7 changes: 6 additions & 1 deletion .goreleaser.yml
Expand Up @@ -5,7 +5,12 @@ builds:
env:
- CGO_ENABLED=0
ldflags:
- -s -w -X github.com/helmfile/helmfile/pkg/app/version.Version={{.Version}}
- -s -w
- -X go.szostok.io/version.version={{.Version}}
- -X go.szostok.io/version.buildDate={{.Date}}
- -X go.szostok.io/version.commit={{.FullCommit}}
- -X go.szostok.io/version.commitDate={{.CommitDate}}
- -X go.szostok.io/version.dirtyBuild=false
goos:
- darwin
- linux
Expand Down
15 changes: 13 additions & 2 deletions Makefile
@@ -1,8 +1,19 @@
ORG ?= $(shell basename $(realpath ..))
PKGS := $(shell go list ./... | grep -v /vendor/)

VERSION?="dev"

# The ldflags for the Go build process to set the version related data
GO_BUILD_VERSION_LDFLAGS=\
-X go.szostok.io/version.version=$(VERSION) \
-X go.szostok.io/version.buildDate=$(shell date +"%Y-%m-%dT%H:%M:%S%z") \
-X go.szostok.io/version.commit=$(shell git rev-parse --short HEAD) \
-X go.szostok.io/version.commitDate=$(shell git log -1 --date=format:"%Y-%m-%dT%H:%M:%S%z" --format=%cd) \
-X go.szostok.io/version.dirtyBuild=false


build:
go build -ldflags '-X github.com/helmfile/helmfile/pkg/app/version.Version=${TAG}' ${TARGETS}
go build -ldflags="$(GO_BUILD_VERSION_LDFLAGS)" ${TARGETS}
.PHONY: build

generate:
Expand Down Expand Up @@ -48,7 +59,7 @@ static-linux:
.PHONY: static-linux

install:
env CGO_ENABLED=0 go install -ldflags '-X github.com/helmfile/helmfile/pkg/app/version.Version=${TAG}' ${TARGETS}
env CGO_ENABLED=0 go install -ldflags="$(GO_BUILD_VERSION_LDFLAGS)" ${TARGETS}
.PHONY: install

clean:
Expand Down
14 changes: 12 additions & 2 deletions cmd/root.go
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"go.szostok.io/version/extension"
"go.uber.org/zap"

"github.com/helmfile/helmfile/pkg/app"
Expand Down Expand Up @@ -45,7 +46,7 @@ func NewRootCmd(globalConfig *config.GlobalOptions, args []string) (*cobra.Comma
Short: globalUsage,
Long: globalUsage,
Args: cobra.MinimumNArgs(1),
Version: version.GetVersion(),
Version: version.Version(),
SilenceUsage: true,
SilenceErrors: true,
PersistentPreRunE: func(c *cobra.Command, args []string) error {
Expand All @@ -71,6 +72,13 @@ func NewRootCmd(globalConfig *config.GlobalOptions, args []string) (*cobra.Comma
flags.ParseErrorsWhitelist.UnknownFlags = true

globalImpl := config.NewGlobalImpl(globalConfig)

// when set environment HELMFILE_UPGRADE_NOTICE_DISABLED any value, skip upgrade notice.
var versionOpts []extension.CobraOption
if os.Getenv("HELMFILE_UPGRADE_NOTICE_DISABLED") == "" {
versionOpts = append(versionOpts, extension.WithUpgradeNotice("helmfile", "helmfile"))
}

cmd.AddCommand(
NewApplyCmd(globalImpl),
NewBuildCmd(globalImpl),
Expand All @@ -82,14 +90,16 @@ func NewRootCmd(globalConfig *config.GlobalOptions, args []string) (*cobra.Comma
NewFetchCmd(globalImpl),
NewListCmd(globalImpl),
NewReposCmd(globalImpl),
NewVersionCmd(),
NewLintCmd(globalImpl),
NewWriteValuesCmd(globalImpl),
NewTestCmd(globalImpl),
NewTemplateCmd(globalImpl),
NewSyncCmd(globalImpl),
NewDiffCmd(globalImpl),
NewStatusCmd(globalImpl),
extension.NewVersionCobraCmd(
versionOpts...,
),
)

return cmd, nil
Expand Down
23 changes: 0 additions & 23 deletions cmd/version.go

This file was deleted.

10 changes: 8 additions & 2 deletions docs/index.md
Expand Up @@ -495,7 +495,7 @@ Usage:
Available Commands:
apply Apply all resources from state file only when there are changes
build Build all resources from state file only when there are changes
build Build all resources from state file
cache Cache management
charts DEPRECATED: sync releases from state file (helm upgrade --install)
completion Generate the autocompletion script for the specified shell
Expand All @@ -512,7 +512,7 @@ Available Commands:
sync Sync releases defined in state file
template Template releases defined in state file
test Test charts from state file (helm test)
version Show the version for Helmfile.
version Print the CLI version
write-values Write values files for releases. Similar to `helmfile template`, write values files instead of manifests.
Flags:
Expand Down Expand Up @@ -626,6 +626,12 @@ The `helmfile list` sub-command lists releases defined in the manifest. Optional

If `--skip-charts` flag is not set, list would prepare all releases, by fetching charts and templating them.

### version

The `helmfile version` sub-command prints the version of Helmfile.Optional `-o` flag accepts `json` `yaml` `short` to output version in JSON, YAML or short format.

default it will check for the latest version of Helmfile and print a tip if the current version is not the latest. To disable this behavior, set environment variable `HELMFILE_UPGRADE_NOTICE_DISABLED` to any non-empty value.

## Paths Overview

Using manifest files in conjunction with command line argument can be a bit confusing.
Expand Down
18 changes: 13 additions & 5 deletions go.mod
Expand Up @@ -26,12 +26,12 @@ require (
github.com/variantdev/chartify v0.11.0
github.com/variantdev/dag v1.1.0
github.com/variantdev/vals v0.18.0
go.szostok.io/version v1.1.0
go.uber.org/multierr v1.6.0
go.uber.org/zap v1.23.0
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
gopkg.in/yaml.v3 v3.0.1
gotest.tools v2.2.0+incompatible
helm.sh/helm/v3 v3.10.0
k8s.io/apimachinery v0.25.2
)
Expand Down Expand Up @@ -92,9 +92,9 @@ require (
github.com/klauspost/compress v1.13.6 // indirect
github.com/lestrrat-go/strftime v1.0.1 // indirect
github.com/lib/pq v1.10.6 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-ieproxy v0.0.1 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.0.0 // indirect
Expand All @@ -117,10 +117,10 @@ require (
go.uber.org/atomic v1.7.0 // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8 // indirect
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20220411224347-583f2d630306 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.70.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20220502173005-c8bf987b8c21 // indirect
Expand All @@ -138,6 +138,8 @@ require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de // indirect
github.com/aymanbagabas/go-osc52 v1.0.3 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/containerd/containerd v1.6.6 // indirect
Expand All @@ -148,6 +150,7 @@ require (
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-metrics v0.0.1 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
github.com/evanphx/json-patch v5.6.0+incompatible // indirect
github.com/frankban/quicktest v1.14.3 // indirect
Expand All @@ -156,6 +159,7 @@ require (
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
github.com/go-openapi/swag v0.19.14 // indirect
github.com/goccy/go-yaml v1.9.5 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/btree v1.0.1 // indirect
github.com/google/gnostic v0.5.7-v3refs // indirect
Expand All @@ -164,10 +168,12 @@ require (
github.com/gorilla/mux v1.8.0 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
github.com/hashicorp/go-retryablehttp v0.7.1 // indirect
github.com/hokaccha/go-prettyjson v0.0.0-20211117102719-0474bc63780f // indirect
github.com/howeyc/gopass v0.0.0-20190910152052-7cb4b85ec19c // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mailru/easyjson v0.7.6 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
github.com/moby/locker v1.0.1 // indirect
Expand All @@ -176,6 +182,7 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/muesli/termenv v0.13.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.3-0.20211202183452-c5a74bcca799 // indirect
Expand All @@ -185,6 +192,7 @@ require (
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.32.1 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/xlab/treeprint v1.1.0 // indirect
go.starlark.net v0.0.0-20200306205701-8dd3e2ee1dd5 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
Expand Down

0 comments on commit 8f7796b

Please sign in to comment.