Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add bin check #24

Merged
merged 5 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
*~
bin
/.idea
/.idea
10 changes: 6 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ VERSION=$(shell git describe --always --match "v*")
GOOS=$(shell go env GOOS)
GOARCH=$(shell go env GOARCH)

BUILD_TIME=$(shell date +'%Y-%m-%d_%T')
BRANCH=$(shell git rev-parse --abbrev-ref HEAD)
GIT_COMMIT=$(shell git log -n1 --pretty='%h')

# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
ifeq (,$(shell go env GOBIN))
GOBIN=$(shell go env GOPATH)/bin
Expand All @@ -16,10 +20,8 @@ unit-tests:
CGO_ENABLED=0 go test -v ./cmd/...

# Build wego binary
# wego: fmt vet unit-tests
wego:
CGO_ENABLED=0 go build -o bin/$(BINARY_NAME) cmd/wego/*.go

wego: fmt vet unit-tests
go build -ldflags "-X github.com/weaveworks/weave-gitops/cmd/wego/version.BuildTime=$(BUILD_TIME) -X github.com/weaveworks/weave-gitops/cmd/wego/version.Branch=$(BRANCH) -X github.com/weaveworks/weave-gitops/cmd/wego/version.GitCommit=$(GIT_COMMIT)" -o bin/wego cmd/wego/*.go
# Clean up images and binaries
clean:
rm -f bin/wego
Expand Down
4 changes: 3 additions & 1 deletion cmd/wego/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package main

import (
"fmt"
log "github.com/sirupsen/logrus"
"os"

log "github.com/sirupsen/logrus"

"github.com/spf13/cobra"
"github.com/weaveworks/weave-gitops/cmd/wego/version"
)
Expand Down Expand Up @@ -33,6 +34,7 @@ func configureLogger() {
func main() {
rootCmd.PersistentFlags().BoolVarP(&options.verbose, "verbose", "v", false, "Enable verbose output")
rootCmd.AddCommand(version.Cmd)

if err := rootCmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(1)
Expand Down
44 changes: 18 additions & 26 deletions cmd/wego/version/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,35 @@ package version

import (
"fmt"
"os"
log "github.com/sirupsen/logrus"
"github.com/weaveworks/go-checkpoint"

"github.com/spf13/cobra"
)

// The current wego version
var Version = "v0.0.0"
Copy link
Contributor

@josecordaz josecordaz Mar 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@josecordaz josecordaz Mar 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@J-Thompson12 I just saw that you had this already. I wonder why we did change it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we had a conversation at standup yesterday and we need to use checkpoint because it does metrics as well as the version check

var GitCommit = ""
var Branch = ""
var BuildTime = ""

var Cmd = &cobra.Command{
Use: "version",
Short: "Display wego version",
Run: runCmd,
}

// exitOnError prints an error to stderr and exit; if error is nil, does nothing
func exitOnError(err interface{}, msgs ...string) {
if err == nil {
return
}
if len(msgs) > 0 {
fmt.Fprintf(os.Stderr, "Error: %s\n", msgs[0])
} else {
fmt.Fprintf(os.Stderr, "Error: %v\n", err)
}
os.Exit(1)
}

func runCmd(cmd *cobra.Command, args []string) {
releases, err := GetReleases()
exitOnError(err)

latestRelease, err := ExtractLatestRelease(releases)
exitOnError(err, fmt.Sprintf("Failed to extract version information; local version is: %s\n", Version))

lt, err := LessThan(Version, latestRelease)
exitOnError(err, fmt.Sprintf("Failed comparing versions; local version is: %s\n", Version))

if lt {
fmt.Printf("Current version is: %s. A newer version (%s) is available.\n", Version, latestRelease)
if checkResponse, err := checkpoint.Check(&checkpoint.CheckParams{
Product: "weave-gitops",
Version: Version,
}); err == nil && checkResponse.Outdated {
log.Infof("wego version %s is available; please update at %s",
checkResponse.CurrentVersion, checkResponse.CurrentDownloadURL)
} else {
fmt.Println(Version)
fmt.Println("Version", Version)
fmt.Println("GitCommit:", GitCommit)
fmt.Println("BuildTime:", BuildTime)
fmt.Println("Branch:", Branch)
}
}
78 changes: 0 additions & 78 deletions cmd/wego/version/version.go

This file was deleted.

93 changes: 0 additions & 93 deletions cmd/wego/version/version_test.go

This file was deleted.

8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ module github.com/weaveworks/weave-gitops
go 1.16

require (
github.com/blang/semver v3.5.1+incompatible // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/kr/pretty v0.2.0 // indirect
github.com/sirupsen/logrus v1.2.0
github.com/spf13/cobra v1.1.3
github.com/stretchr/testify v1.7.0
k8s.io/apimachinery v0.20.5
github.com/weaveworks/go-checkpoint v0.0.0-20170503165305-ebbb8b0518ab
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 // indirect
golang.org/x/sys v0.0.0-20201112073958-5cba982894dd // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
)
Loading