Skip to content

Commit f67fe71

Browse files
bug: fixes #221 wrong latest version (#222)
* bug: fixes #221 wrong latest version * ci: golang lint vup to latest for 1.25 * ci: golang lint vup to latest for 1.25 * ci: golang lint vup to latest for 1.25 * ci: golang lint vet * ci: fix tests new semantics * ci: fix tests new semantics
1 parent 1f7c473 commit f67fe71

File tree

12 files changed

+2026
-1506
lines changed

12 files changed

+2026
-1506
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
name: golangci-lint
22
on:
3-
push:
4-
branches:
5-
- '**'
63
pull_request:
74
branches:
85
- '**'
@@ -21,7 +18,5 @@ jobs:
2118
uses: kevincobain2000/action-gobrew@v2
2219
with:
2320
version: latest
24-
-
25-
uses: golangci/golangci-lint-action@v6
26-
with:
27-
version: latest
21+
- run: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.5.0
22+
- run: golangci-lint run ./...

.golangci.yaml

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,37 @@
1+
version: "2"
12
linters:
2-
# Disable all linters.
3-
# Default: false
4-
disable-all: true
5-
# Enable specific linter
6-
# https://golangci-lint.run/usage/linters/#enabled-by-default
3+
default: none
74
enable:
8-
- errcheck
9-
- gosimple
10-
- govet
11-
- ineffassign
12-
- staticcheck
5+
- copyloopvar
136
- dupl
7+
- errcheck
148
- errorlint
15-
- copyloopvar
169
- goconst
1710
- gocritic
1811
- gocyclo
1912
- goprintffuncname
2013
- gosec
14+
- govet
15+
- ineffassign
2116
- prealloc
2217
- revive
23-
- stylecheck
18+
- staticcheck
2419
- whitespace
20+
exclusions:
21+
generated: lax
22+
presets:
23+
- comments
24+
- common-false-positives
25+
- legacy
26+
- std-error-handling
27+
paths:
28+
- third_party$
29+
- builtin$
30+
- examples$
31+
formatters:
32+
exclusions:
33+
generated: lax
34+
paths:
35+
- third_party$
36+
- builtin$
37+
- examples$

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
module github.com/kevincobain2000/gobrew
22

3-
go 1.22.0
3+
go 1.25.1
44

55
require (
66
github.com/Masterminds/semver v1.5.0
77
github.com/c4milo/unpackit v1.0.0
88
github.com/gookit/color v1.5.4
99
github.com/schollz/progressbar/v3 v3.14.1
10+
github.com/spf13/pflag v1.0.5
1011
github.com/stretchr/testify v1.8.4
1112
)
1213

@@ -19,7 +20,6 @@ require (
1920
github.com/pkg/errors v0.9.1 // indirect
2021
github.com/pmezard/go-difflib v1.0.0 // indirect
2122
github.com/rivo/uniseg v0.4.7 // indirect
22-
github.com/spf13/pflag v1.0.5 // indirect
2323
github.com/ulikunitz/xz v0.5.11 // indirect
2424
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
2525
golang.org/x/sys v0.17.0 // indirect

gobrew.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func (gb *GoBrew) Interactive(ask bool) {
108108
modVersion := NoneVersion
109109
if gb.hasModFile() {
110110
modVersion = gb.getModVersion()
111-
modVersion = extractMajorVersion(modVersion)
111+
// modVersion = extractMajorVersion(modVersion)
112112
}
113113

114114
fmt.Println()
@@ -135,7 +135,7 @@ func (gb *GoBrew) Interactive(ask bool) {
135135
}
136136

137137
if modVersion != NoneVersion && latestMajorVersion != modVersion {
138-
label := " " + color.FgYellow.Render("\t⚠️ not latest")
138+
label := " " + color.FgYellow.Render("\t⚠️ not latest")
139139
color.Successln("📄 go.mod Version", " .......", modVersion+label)
140140
} else {
141141
color.Successln("📄 go.mod Version", " .......", modVersion)
@@ -156,7 +156,7 @@ func (gb *GoBrew) Interactive(ask bool) {
156156
}
157157

158158
if modVersion != NoneVersion && currentMajorVersion != modVersion {
159-
color.Warnf("⚠️ GO Installed Version (%s) and go.mod Version (%s) are different.\n", currentMajorVersion, modVersion)
159+
color.Warnf("⚠️ GO Installed Version (%s) and go.mod Version (%s) are different.\n", currentMajorVersion, modVersion)
160160
fmt.Println(" Please consider updating your go.mod file")
161161
c := true
162162
if ask {
@@ -169,7 +169,7 @@ func (gb *GoBrew) Interactive(ask bool) {
169169
}
170170

171171
if currentVersion != latestVersion {
172-
color.Warnf("⚠️ GO Installed Version (%s) and GO Latest Version (%s) are different.\n", currentVersion, latestVersion)
172+
color.Warnf("⚠️ GO Installed Version (%s) and GO Latest Version (%s) are different.\n", currentVersion, latestVersion)
173173
c := true
174174
if ask {
175175
c = askForConfirmation("🤔 Do you want to update GO to latest version (" + latestVersion + ")?")
@@ -321,9 +321,17 @@ func (gb *GoBrew) Install(version string) string {
321321
color.Errorln("[Error] No version provided")
322322
os.Exit(1)
323323
}
324+
// if version has 2 dots, then remove the @latest or @dev-latest
325+
if strings.Count(version, ".") == 2 {
326+
if strings.HasSuffix(version, "@latest") || strings.HasSuffix(version, "@dev-latest") {
327+
version = strings.TrimSuffix(version, "@latest")
328+
version = strings.TrimSuffix(version, "@dev-latest")
329+
}
330+
}
331+
tmpVersion := version
324332
version = gb.judgeVersion(version)
325333
if version == NoneVersion {
326-
color.Errorln("[Error] Version non exists")
334+
color.Errorln("[Error] Version", tmpVersion, "does not exists")
327335
os.Exit(1)
328336
}
329337
if gb.existsVersion(version) {

helpers.go

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,28 @@ import (
2626

2727
func (gb *GoBrew) getLatestVersion() string {
2828
getGolangVersions := gb.getGolangVersions()
29-
// loop through reverse and ignore beta and rc versions to get latest version
30-
for i := len(getGolangVersions) - 1; i >= 0; i-- {
29+
30+
// Filter out beta and rc versions and create semantic versions
31+
var validVersions []*semver.Version
32+
for _, version := range getGolangVersions {
3133
r := regexp.MustCompile("beta.*|rc.*")
32-
matches := r.FindAllString(getGolangVersions[i], -1)
34+
matches := r.FindAllString(version, -1)
3335
if len(matches) == 0 {
34-
return getGolangVersions[i]
36+
if v, err := semver.NewVersion(version); err == nil {
37+
validVersions = append(validVersions, v)
38+
}
3539
}
3640
}
37-
return ""
41+
42+
if len(validVersions) == 0 {
43+
return ""
44+
}
45+
46+
// Sort semantic versions
47+
sort.Sort(semver.Collection(validVersions))
48+
49+
// Return the latest version (last in sorted order)
50+
return validVersions[len(validVersions)-1].String()
3851
}
3952

4053
func (gb *GoBrew) getArch() string {
@@ -503,7 +516,7 @@ func askForConfirmation(s string) bool {
503516
reader := bufio.NewReader(os.Stdin)
504517

505518
for {
506-
color.Successf(s) // nolint:govet
519+
color.Successln(s)
507520
fmt.Print(" [y/n]: ")
508521

509522
response, err := reader.ReadString('\n')

helpers_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ func TestJudgeVersion(t *testing.T) {
3636
},
3737
{
3838
version: "1.18@latest",
39-
wantVersion: "1.18.10",
39+
wantVersion: "1.18.9",
4040
},
4141
{
4242
version: "1.18@dev-latest",
43-
wantVersion: "1.18.10",
43+
wantVersion: "1.18.9",
4444
},
4545
{
4646
version: "go1.18",
756 Bytes
Binary file not shown.
756 Bytes
Binary file not shown.
756 Bytes
Binary file not shown.
156 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)