Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
9 changes: 2 additions & 7 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
name: golangci-lint
on:
push:
branches:
- '**'
pull_request:
branches:
- '**'
Expand All @@ -21,7 +18,5 @@ jobs:
uses: kevincobain2000/action-gobrew@v2
with:
version: latest
-
uses: golangci/golangci-lint-action@v6
with:
version: latest
- run: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.5.0
- run: golangci-lint run ./...
37 changes: 25 additions & 12 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,37 @@
version: "2"
linters:
# Disable all linters.
# Default: false
disable-all: true
# Enable specific linter
# https://golangci-lint.run/usage/linters/#enabled-by-default
default: none
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- copyloopvar
- dupl
- errcheck
- errorlint
- copyloopvar
- goconst
- gocritic
- gocyclo
- goprintffuncname
- gosec
- govet
- ineffassign
- prealloc
- revive
- stylecheck
- staticcheck
- whitespace
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- third_party$
- builtin$
- examples$
formatters:
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module github.com/kevincobain2000/gobrew

go 1.22.0
go 1.25.1

require (
github.com/Masterminds/semver v1.5.0
github.com/c4milo/unpackit v1.0.0
github.com/gookit/color v1.5.4
github.com/schollz/progressbar/v3 v3.14.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
)

Expand All @@ -19,7 +20,6 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/ulikunitz/xz v0.5.11 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/sys v0.17.0 // indirect
Expand Down
18 changes: 13 additions & 5 deletions gobrew.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func (gb *GoBrew) Interactive(ask bool) {
modVersion := NoneVersion
if gb.hasModFile() {
modVersion = gb.getModVersion()
modVersion = extractMajorVersion(modVersion)
// modVersion = extractMajorVersion(modVersion)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

no longer needed, should provide full version

}

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

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

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

if currentVersion != latestVersion {
color.Warnf("⚠️ GO Installed Version (%s) and GO Latest Version (%s) are different.\n", currentVersion, latestVersion)
color.Warnf("⚠️ GO Installed Version (%s) and GO Latest Version (%s) are different.\n", currentVersion, latestVersion)
c := true
if ask {
c = askForConfirmation("🤔 Do you want to update GO to latest version (" + latestVersion + ")?")
Expand Down Expand Up @@ -321,9 +321,17 @@ func (gb *GoBrew) Install(version string) string {
color.Errorln("[Error] No version provided")
os.Exit(1)
}
// if version has 3 dots, then remove the @latest or @dev-latest
if strings.Count(version, ".") == 2 {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

not sure when this was pushed by GO but seems like all the old versions are now following proper semantics.
Example in the past 1.9 was just 1.9 and hitting a 1.9.0 ended up in 404 and was not in tags either.

Current remote tags are as:

~/g/gobrew (feature/latest)> go run ./cmd/gobrew ls-remote                                                            (base)
==> [Info] Fetching remote versions
1.5     1.5.0  1.5.1  1.5.2  1.5.3  1.5.4
        1.5beta1  1.5beta2  1.5beta3  1.5rc1

1.6     1.6.0  1.6.1  1.6.2  1.6.3  1.6.4
        1.6beta1  1.6beta2  1.6rc1  1.6rc2

1.7     1.7.0  1.7.1  1.7.2  1.7.3  1.7.4
        1.7.5  1.7.6
        1.7beta1  1.7beta2  1.7rc1  1.7rc2  1.7rc3  1.7rc4
        1.7rc5  1.7rc6

1.8     1.8.0  1.8.1  1.8.2  1.8.3  1.8.4
        1.8.5  1.8.6  1.8.7
        1.8.5rc4  1.8.5rc5  1.8beta1  1.8beta2  1.8rc1  1.8rc2
        1.8rc3

1.9     1.9.0  1.9.1  1.9.2  1.9.3  1.9.4
        1.9.5  1.9.6  1.9.7
        1.9beta1  1.9beta2  1.9rc1  1.9rc2

1.10    1.10.0  1.10.1  1.10.2  1.10.3  1.10.4
        1.10.5  1.10.6  1.10.7  1.10.8
        1.10beta1  1.10beta2  1.10rc1  1.10rc2

1.11    1.11.0  1.11.1  1.11.2  1.11.3  1.11.4
        1.11.5  1.11.6  1.11.7  1.11.8  1.11.9  1.11.10
        1.11.11  1.11.12  1.11.13
        1.11beta1  1.11beta2  1.11beta3  1.11rc1  1.11rc2

1.12    1.12.0  1.12.1  1.12.2  1.12.3  1.12.4
        1.12.5  1.12.6  1.12.7  1.12.8  1.12.9  1.12.10
        1.12.11  1.12.12  1.12.13  1.12.14  1.12.15  1.12.16
        1.12.17
        1.12beta1  1.12beta2  1.12rc1

1.13    1.13.0  1.13.1  1.13.2  1.13.3  1.13.4
        1.13.5  1.13.6  1.13.7  1.13.8  1.13.9  1.13.10
        1.13.11  1.13.12  1.13.13  1.13.14  1.13.15
        1.13beta1  1.13rc1  1.13rc2

1.14    1.14.0  1.14.1  1.14.2  1.14.3  1.14.4
        1.14.5  1.14.6  1.14.7  1.14.8  1.14.9  1.14.10
        1.14.11  1.14.12  1.14.13  1.14.14  1.14.15
        1.14beta1  1.14rc1

1.15    1.15.0  1.15.1  1.15.2  1.15.3  1.15.4
        1.15.5  1.15.6  1.15.7  1.15.8  1.15.9  1.15.10
        1.15.11  1.15.12  1.15.13  1.15.14  1.15.15
        1.15beta1  1.15rc1  1.15rc2

1.16    1.16.0  1.16.1  1.16.2  1.16.3  1.16.4
        1.16.5  1.16.6  1.16.7  1.16.8  1.16.9  1.16.10
        1.16.11  1.16.12  1.16.13  1.16.14  1.16.15
        1.16beta1  1.16rc1

1.17    1.17.0  1.17.1  1.17.2  1.17.3  1.17.4
        1.17.5  1.17.6  1.17.7  1.17.8  1.17.9  1.17.10
        1.17.11  1.17.12  1.17.13
        1.17beta1  1.17rc1  1.17rc2

1.18    1.18.0  1.18.1  1.18.2  1.18.3  1.18.4
        1.18.5  1.18.6  1.18.7  1.18.8  1.18.9  1.18.10
        1.18beta1  1.18beta2  1.18rc1

1.19    1.19.0  1.19.1  1.19.2  1.19.3  1.19.4
        1.19.5  1.19.6  1.19.7  1.19.8  1.19.9  1.19.10
        1.19.11  1.19.12  1.19.13
        1.19beta1  1.19rc1  1.19rc2

1.20    1.20.0  1.20.1  1.20.2  1.20.3  1.20.4
        1.20.5  1.20.6  1.20.7  1.20.8  1.20.9  1.20.10
        1.20.11  1.20.12  1.20.13  1.20.14
        1.20rc1  1.20rc2  1.20rc3

1.21    1.21.0  1.21.1  1.21.2  1.21.3  1.21.4
        1.21.5  1.21.6  1.21.7  1.21.8  1.21.9  1.21.10
        1.21.11  1.21.12  1.21.13
        1.21rc1  1.21rc2  1.21rc3  1.21rc4

1.22    1.22.0  1.22.1  1.22.2  1.22.3  1.22.4
        1.22.5  1.22.6  1.22.7  1.22.8  1.22.9  1.22.10
        1.22.11  1.22.12
        1.22rc1  1.22rc2

1.23    1.23.0  1.23.1  1.23.2  1.23.3  1.23.4
        1.23.5  1.23.6  1.23.7  1.23.8  1.23.9  1.23.10
        1.23.11  1.23.12
        1.23rc1  1.23rc2

1.24    1.24.0  1.24.1  1.24.2  1.24.3  1.24.4
        1.24.5  1.24.6  1.24.7
        1.24rc1  1.24rc2  1.24rc3

1.25    1.25.0  1.25.1
        1.25rc1  1.25rc2  1.25rc3

if strings.HasSuffix(version, "@latest") || strings.HasSuffix(version, "@dev-latest") {
version = strings.TrimSuffix(version, "@latest")
version = strings.TrimSuffix(version, "@dev-latest")
}
}
tmpVersion := version
version = gb.judgeVersion(version)
if version == NoneVersion {
color.Errorln("[Error] Version non exists")
color.Errorln("[Error] Version", tmpVersion, "does not exists")
os.Exit(1)
}
if gb.existsVersion(version) {
Expand Down
25 changes: 19 additions & 6 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,28 @@ import (

func (gb *GoBrew) getLatestVersion() string {
getGolangVersions := gb.getGolangVersions()
// loop through reverse and ignore beta and rc versions to get latest version
for i := len(getGolangVersions) - 1; i >= 0; i-- {

// Filter out beta and rc versions and create semantic versions
var validVersions []*semver.Version
for _, version := range getGolangVersions {
r := regexp.MustCompile("beta.*|rc.*")
matches := r.FindAllString(getGolangVersions[i], -1)
matches := r.FindAllString(version, -1)
if len(matches) == 0 {
return getGolangVersions[i]
if v, err := semver.NewVersion(version); err == nil {
validVersions = append(validVersions, v)
}
}
}
return ""

if len(validVersions) == 0 {
return ""
}

// Sort semantic versions
sort.Sort(semver.Collection(validVersions))

// Return the latest version (last in sorted order)
return validVersions[len(validVersions)-1].String()
}

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

for {
color.Successf(s) // nolint:govet
color.Successln(s)
fmt.Print(" [y/n]: ")

response, err := reader.ReadString('\n')
Expand Down
4 changes: 2 additions & 2 deletions helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ func TestJudgeVersion(t *testing.T) {
},
{
version: "1.18@latest",
wantVersion: "1.18.10",
wantVersion: "1.18.9",
},
{
version: "1.18@dev-latest",
wantVersion: "1.18.10",
wantVersion: "1.18.9",
},
{
version: "go1.18",
Expand Down
Binary file added testdata/go1.25.1.darwin-amd64.tar.gz
Binary file not shown.
Binary file added testdata/go1.25.1.darwin-arm64.tar.gz
Binary file not shown.
Binary file added testdata/go1.25.1.linux-amd64.tar.gz
Binary file not shown.
Binary file added testdata/go1.25.1.windows-amd64.zip
Binary file not shown.
Loading
Loading