Skip to content

Commit

Permalink
cleaner version checking code and actually enabling it to run
Browse files Browse the repository at this point in the history
  • Loading branch information
rue-nsilverman committed Jan 3, 2024
1 parent a1ae420 commit 3e30582
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ builds:
- -s -w -X github.com/ruelala/arconn/pkg/utils.binary=arconn
- -s -w -X github.com/ruelala/arconn/pkg/utils.commit={{.Commit}}
- -s -w -X github.com/ruelala/arconn/pkg/utils.date={{.Date}}
- -s -w -X github.com/ruelala/arconn/pkg/utils.version={{.Version}}
- -s -w -X github.com/ruelala/arconn/pkg/utils.version=v{{.Version}}

changelog:
sort: desc
Expand All @@ -25,4 +25,4 @@ changelog:
archives:
- id: default
format: zip
name_template: "{{.ProjectName}}-{{.Version}}-{{.Os}}-{{.Arch}}"
name_template: "{{.ProjectName}}-v{{.Version}}-{{.Os}}-{{.Arch}}"
1 change: 1 addition & 0 deletions cmd/arconn/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

func main() {
utils.IsLatest()
args := utils.ParseFlags()
target := utils.Target{}

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ require (
github.com/twinj/uuid v1.0.0
github.com/xtaci/smux v1.5.24
golang.org/x/crypto v0.17.0
golang.org/x/mod v0.14.0
golang.org/x/sync v0.5.0
golang.org/x/sys v0.15.0
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ github.com/xtaci/smux v1.5.24 h1:77emW9dtnOxxOQ5ltR+8BbsX1kzcOxQ5gB+aaV9hXOY=
github.com/xtaci/smux v1.5.24/go.mod h1:OMlQbT5vcgl2gb49mFkYo6SMf+zP3rcjcwQz7ZU7IGY=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
Expand Down
15 changes: 11 additions & 4 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

"github.com/buger/jsonparser"
"github.com/integrii/flaggy"
"golang.org/x/mod/semver"
)

// these get passed in as ldflags by goreleaser
Expand All @@ -21,7 +22,7 @@ var binary string

func IsLatest() {
var client http.Client
url := fmt.Sprintf("https://api.github.com/repos/RueLaLa/%s/releases/latest", BinaryName())
url := fmt.Sprintf("https://api.github.com/repos/RueLaLa/%s/releases/latest", binary)
resp, err := client.Get(url)
if err != nil {
return
Expand All @@ -37,9 +38,15 @@ func IsLatest() {
if err != nil {
return
}
fmt.Printf("v%s\n", version)
if latest != fmt.Sprintf("v%s", version) {
fmt.Printf("A new version of %s is available (%s), head to https://github.com/RueLaLa/%s/releases/latest to get the latest binary\n", binary, latest, binary)

// this function returns 0 for equality, 1 if left value is greater, and -1 if right value is greater
comparison := semver.Compare(latest, version)
html_url, err := jsonparser.GetString(bodyBytes, "html_url")
if err != nil {
return
}
if comparison == 1 {
fmt.Printf("A new version is available (%s), head to %s to get the latest binary\n", latest, html_url)
}
}

Expand Down

0 comments on commit 3e30582

Please sign in to comment.