Skip to content

build(deps): bump github.com/ldez/grignotin from 0.7.0 to 0.8.0 #5295

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

Merged
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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ require (
github.com/lasiar/canonicalheader v1.1.2
github.com/ldez/exptostd v0.3.1
github.com/ldez/gomoddirectives v0.6.0
github.com/ldez/grignotin v0.7.0
github.com/ldez/grignotin v0.8.0
github.com/ldez/tagliatelle v0.7.1
github.com/ldez/usetesting v0.4.2
github.com/leonklingele/grouper v1.1.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 29 additions & 14 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

hcversion "github.com/hashicorp/go-version"
"github.com/ldez/grignotin/goenv"
"github.com/ldez/grignotin/gomod"
"golang.org/x/mod/modfile"
)
Expand Down Expand Up @@ -80,43 +81,57 @@ func IsGoGreaterThanOrEqual(current, limit string) bool {
}

func detectGoVersion() string {
goVersion := detectGoVersionFromGoMod()
if goVersion != "" {
return goVersion
}

return cmp.Or(os.Getenv("GOVERSION"), "1.17")
return cmp.Or(detectGoVersionFromGoMod(), "1.17")
}

// detectGoVersionFromGoMod tries to get Go version from go.mod.
// It returns `toolchain` version if present,
// else it returns `go` version if present,
// else it returns `GOVERSION` version if present,
// else it returns empty.
func detectGoVersionFromGoMod() string {
modPath, err := gomod.GetGoModPath()
values, err := goenv.Get(goenv.GOMOD, goenv.GOVERSION)
if err != nil {
modPath = detectGoModFallback()
if modPath == "" {
return ""
values = map[string]string{
goenv.GOMOD: detectGoModFallback(),
}
}

file, err := parseGoMod(modPath)
if values[goenv.GOMOD] == "" {
return parseGoVersion(values[goenv.GOVERSION])
}

file, err := parseGoMod(values[goenv.GOMOD])
if err != nil {
return ""
return parseGoVersion(values[goenv.GOVERSION])
}

// The toolchain exists only if 'toolchain' version > 'go' version.
// If 'toolchain' version <= 'go' version, `go mod tidy` will remove 'toolchain' version from go.mod.
if file.Toolchain != nil && file.Toolchain.Name != "" {
return strings.TrimPrefix(file.Toolchain.Name, "go")
return parseGoVersion(file.Toolchain.Name)
}

if file.Go != nil && file.Go.Version != "" {
return file.Go.Version
}

return ""
return parseGoVersion(values[goenv.GOVERSION])
}

func parseGoVersion(v string) string {
raw := strings.TrimPrefix(v, "go")

// prerelease version (ex: go1.24rc1)
idx := strings.IndexFunc(raw, func(r rune) bool {
return (r < '0' || r > '9') && r != '.'
})

if idx != -1 {
raw = raw[:idx]
}

return raw
}

func parseGoMod(goMod string) (*modfile.File, error) {
Expand Down
44 changes: 44 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,47 @@ func TestIsGoGreaterThanOrEqual(t *testing.T) {
})
}
}

func Test_parseGoVersion(t *testing.T) {
testCases := []struct {
desc string
version string
expected string
}{
{
desc: "empty version",
version: "",
expected: "",
},
{
desc: "no prefixed version",
version: "1.23.0",
expected: "1.23.0",
},
{
desc: "semver version",
version: "go1.23.0",
expected: "1.23.0",
},
{
desc: "family version",
version: "go1.23",
expected: "1.23",
},
{
desc: "prerelease version",
version: "go1.24rc1",
expected: "1.24",
},
}

for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
t.Parallel()

v := parseGoVersion(test.version)

assert.Equal(t, test.expected, v)
})
}
}
Loading