Skip to content

Commit

Permalink
feat: update version cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
ysicing committed Sep 24, 2020
1 parent f023b9a commit c18e753
Show file tree
Hide file tree
Showing 5 changed files with 419 additions and 14 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ sealos
oss-config
ossutil64
main.exe
main
main
dist
.vscode
18 changes: 14 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
COMMIT_SHA1 ?= $(shell git rev-parse --short HEAD || echo "0.0.0")
BUILD_VERSION ?= $(shell cat version.txt || echo "3.0.2")
BUILD_VERSION ?= $(shell cat version.txt || echo "local")
BUILD_TIME ?= $(shell date "+%F %T")

.PHONY: fmt vet lint default
Expand Down Expand Up @@ -67,15 +67,25 @@ vet: ## vet

default: fmt lint vet

.PHONY: local
local: ## 构建二进制
docker run --rm -v ${PWD}:/go/src/github.com/fanux/sealos -w /go/src/github.com/fanux/sealos golang:1.12-stretch go build -ldflags "-X 'github.com/fanux/sealos/version.Version=${BUILD_VERSION}' -X 'github.com/fanux/sealos/version.Build=${COMMIT_SHA1}' -X 'github.com/fanux/sealos/version.BuildTime=${BUILD_TIME}'"
local: clean ## 构建二进制
@echo "build bin ${BUILD_VERSION} ${BUILD_TIME} ${COMMIT_SHA1}"
# go get github.com/mitchellh/gox
# eg darwin/amd64 linux/amd64 windows/amd64
@gox -osarch="linux/amd64" \
-output="dist/{{.Dir}}_{{.OS}}_{{.Arch}}" \
-ldflags "-X 'github.com/fanux/sealos/version.Version=${BUILD_VERSION}' \
-X 'github.com/fanux/sealos/version.Build=${COMMIT_SHA1}' \
-X 'github.com/fanux/sealos/version.BuildTime=${BUILD_TIME}'"

help: ## this help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {sub("\\\\n",sprintf("\n%22c"," "), $$2);printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

clean: ## clean
rm -rf dist

.EXPORT_ALL_VARIABLES:

GO111MODULE = on

GOPROXY = https://goproxy.cn
GOSUMDB = sum.golang.google.cn
20 changes: 20 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ package cmd

import (
"fmt"

"github.com/fanux/sealos/version"
"github.com/spf13/cobra"
"github.com/wangle201210/githubapi/repos"
"github.com/ysicing/ext/utils/exmisc"
)

// versionCmd represents the version command
Expand All @@ -27,6 +30,10 @@ var versionCmd = &cobra.Command{
Long: `show sealos version`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(version.VersionStr)
lastversion := GetVersion()
if lastversion != nil {
fmt.Printf("sealos current latest version is %v\n", exmisc.SGreen(*lastversion))
}
},
}

Expand All @@ -43,3 +50,16 @@ func init() {
// is called directly, e.g.:
// versionCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

// GetVersion 获取最新版本
func GetVersion() *string {
pkg := repos.Pkg{
Owner: "fanux",
Repo: "sealos",
}
lasttag, _ := pkg.LastTag()
if lasttag.Name != version.Version {
return &lasttag.Name
}
return nil
}
23 changes: 17 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,30 @@ require (
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/fanux/lvscare v0.0.0-00010101000000-000000000000
github.com/fanux/sealgate v0.0.5
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/ghodss/yaml v1.0.0
github.com/magiconair/properties v1.8.4 // indirect
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/errors v0.8.1
github.com/mitchellh/mapstructure v1.3.3 // indirect
github.com/pelletier/go-toml v1.8.1 // indirect
github.com/pkg/errors v0.9.1
github.com/pkg/sftp v1.11.0
github.com/satori/go.uuid v1.2.0 // indirect
github.com/spf13/cobra v0.0.6
github.com/spf13/viper v1.6.2
github.com/spf13/afero v1.4.0 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/cobra v1.0.0
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.7.1
github.com/vishvananda/netlink v1.1.0
github.com/wangle201210/githubapi v0.0.0-20200804144924-cde7bbdc36ab
github.com/wonderivan/logger v1.0.0
github.com/ysicing/ext v0.0.0-20200924074735-656a6ff80db4
go.etcd.io/etcd v0.0.0-20200716221620-18dfb9cca345
go.uber.org/zap v1.10.0
golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975
gopkg.in/yaml.v2 v2.2.8
go.uber.org/zap v1.13.0
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d // indirect
gopkg.in/ini.v1 v1.61.0 // indirect
gopkg.in/yaml.v2 v2.3.0
k8s.io/api v0.18.0
k8s.io/apimachinery v0.18.0
k8s.io/client-go v0.18.0
Expand Down
Loading

0 comments on commit c18e753

Please sign in to comment.