From ac70c6527238721c584195953ff79d39953c891a Mon Sep 17 00:00:00 2001 From: Beorn Facchini Date: Wed, 8 Feb 2023 03:46:10 +1100 Subject: [PATCH] Update go-version to support wildcards. --- go.mod | 4 ++-- go.sum | 6 ++++-- pack/common.go | 23 +++++++---------------- pack/node.go | 6 +++--- 4 files changed, 16 insertions(+), 23 deletions(-) diff --git a/go.mod b/go.mod index 313c97d..5751027 100644 --- a/go.mod +++ b/go.mod @@ -4,13 +4,13 @@ go 1.18 require ( github.com/ake-persson/mapslice-json v0.0.0-20210720081907-22c8edf57807 + github.com/aquasecurity/go-version v0.0.0-20210121072130-637058cfe492 github.com/bmatcuk/doublestar v1.3.4 github.com/cloudingcity/gomod v1.0.1 github.com/docker/distribution v2.8.1+incompatible github.com/docker/libcompose v0.4.1-0.20181019154650-213509acef0f github.com/google/go-github/v45 v45.2.0 github.com/gregjones/httpcache v0.0.0-20190212212710-3befbb6ad0cc - github.com/hashicorp/go-version v1.2.0 github.com/ory/dockertest/v3 v3.6.5 github.com/spf13/cobra v1.5.0 github.com/stretchr/testify v1.8.0 @@ -84,6 +84,6 @@ require ( replace ( github.com/Nvveen/Gotty => github.com/ijc/Gotty v0.0.0-20170406111628-a8b993ba6abd + github.com/aquasecurity/go-version => github.com/beornf/goversion v0.0.0-20230212045613-eac47a9c209d github.com/docker/libcompose => github.com/beornf/libcompose v0.4.1-0.20210215180846-a59802c0f07c - github.com/hashicorp/go-version => github.com/beornf/go-version v1.1.1-0.20200317142312-136b0131ea06 ) diff --git a/go.sum b/go.sum index cd6cde8..2f8a2b7 100644 --- a/go.sum +++ b/go.sum @@ -177,8 +177,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/beornf/go-version v1.1.1-0.20200317142312-136b0131ea06 h1:cfKucAEg3G/tffpQn0rMy+N5JqXa7kJIEczaOCDh+A8= -github.com/beornf/go-version v1.1.1-0.20200317142312-136b0131ea06/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/beornf/goversion v0.0.0-20230212045613-eac47a9c209d h1:BP1Y4UYwcLtyBognUrZRBqsY+/34Xs1eg/wqidQzpaM= +github.com/beornf/goversion v0.0.0-20230212045613-eac47a9c209d/go.mod h1:9Beu8XsUNNfzml7WBf3QmyPToP1wm1Gj/Vc5UJKqTzU= github.com/beornf/libcompose v0.4.1-0.20210215180846-a59802c0f07c h1:tDYcjKncxyn3Cj0UDnDxjy8oH0RruaMQSxXE5s7suzI= github.com/beornf/libcompose v0.4.1-0.20210215180846-a59802c0f07c/go.mod h1:9+ps1KKtVtRUdpVxJldssQItPf/S5t5bO0zh4A0Hy5g= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= @@ -670,6 +670,7 @@ github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerX github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= +github.com/hashicorp/go-version v1.2.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= @@ -1088,6 +1089,7 @@ github.com/urfave/cli v0.0.0-20171014202726-7bc6a0acffa5/go.mod h1:70zkFmudgCuE/ github.com/urfave/cli v1.20.0/go.mod h1:70zkFmudgCuE/ngEzBv17Jvp/497gISqfk5gWijbERA= github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= github.com/urfave/cli v1.22.2/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0= +github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= github.com/uudashr/gocognit v1.0.1/go.mod h1:j44Ayx2KW4+oB6SWMv8KsmHzZrOInQav7D3cQMJ5JUM= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.2.0/go.mod h1:4vX61m6KN+xDduDNwXrhIAVZaZaZiQ1luJk8LWSxF3s= diff --git a/pack/common.go b/pack/common.go index ad79b9a..c44250b 100644 --- a/pack/common.go +++ b/pack/common.go @@ -13,6 +13,7 @@ import ( "strings" "time" + "github.com/aquasecurity/go-version/pkg/version" "github.com/bmatcuk/doublestar" "github.com/cloudingcity/gomod" "github.com/docker/distribution/reference" @@ -20,7 +21,6 @@ import ( "github.com/google/go-github/v45/github" "github.com/gregjones/httpcache" "github.com/gregjones/httpcache/diskcache" - "github.com/hashicorp/go-version" "golang.org/x/oauth2" "gopkg.in/yaml.v3" ) @@ -259,8 +259,8 @@ func getVersion(meta *Metadata) error { versions := []string{} for _, tag := range tags { - var v *version.Version - v, err = version.NewVersion(tag) + var v version.Version + v, err = version.Parse(tag) if err != nil || v.Prerelease() != meta.Variant { continue } @@ -268,31 +268,22 @@ func getVersion(meta *Metadata) error { } sort.Slice(versions, func(i, j int) bool { - v1, _ := version.NewVersion(versions[i]) - v2, _ := version.NewVersion(versions[j]) + v1, _ := version.Parse(versions[i]) + v2, _ := version.Parse(versions[j]) if v1.Equal(v2) { return versions[i] > versions[j] } return v1.GreaterThan(v2) }) - meta.Version = strings.TrimRight(meta.Version, ".x*") - if meta.Version == "" { - meta.Version = ">0" - } - - constraints, err := version.NewConstraint(meta.Version) + constraints, err := version.NewConstraints(meta.Version) if err != nil { return err } for _, tag := range versions { ver := strings.Split(tag, "-")[0] - if meta.Version < ver { - continue - } - - v, _ := version.NewVersion(ver) + v, _ := version.Parse(ver) if constraints.Check(v) { meta.Version = tag return nil diff --git a/pack/node.go b/pack/node.go index dba2fcb..9ce04c2 100644 --- a/pack/node.go +++ b/pack/node.go @@ -4,7 +4,7 @@ import ( "encoding/json" "strings" - "github.com/hashicorp/go-version" + "github.com/aquasecurity/go-version/pkg/version" ) type NodePack struct { @@ -39,12 +39,12 @@ func (n *NodePack) Metadata() *Metadata { return nil } - constraints, err := version.NewConstraint("^8.12 || >=10.3") + constraints, err := version.NewConstraints("^8.12 || >=10.3") if err != nil { return err } - v, _ := version.NewVersion(meta.Version) + v, _ := version.Parse(meta.Version) if constraints.Check(v) { tool.Install = []string{"ci"} }