From 3ef853aedff0ed144e1322fef3d3f49af65c536a Mon Sep 17 00:00:00 2001 From: Evsyukov Denis Date: Wed, 6 Dec 2023 09:17:24 +0300 Subject: [PATCH 1/9] feat: tests in parallel --- gobrew.go | 5 +---- gobrew_test.go | 54 ++++++++++++++++++++------------------------------ 2 files changed, 23 insertions(+), 36 deletions(-) diff --git a/gobrew.go b/gobrew.go index 56fc7b2..b80a43f 100644 --- a/gobrew.go +++ b/gobrew.go @@ -798,10 +798,7 @@ func (gb *GoBrew) getGolangVersions() (result []string) { func doRequest(url string) (data []byte) { client := &http.Client{} request, err := http.NewRequest("GET", url, nil) - if err != nil { - color.Errorln("==> [Error] Cannot create request:", err.Error()) - return - } + utils.CheckError(err, "==> [Error] Cannot create request") request.Header.Set("User-Agent", "gobrew") diff --git a/gobrew_test.go b/gobrew_test.go index 9039ace..e5bf86a 100644 --- a/gobrew_test.go +++ b/gobrew_test.go @@ -11,6 +11,7 @@ import ( ) func TestNewGobrewHomeDirUsesUserHomeDir(t *testing.T) { + t.Parallel() homeDir, err := os.UserHomeDir() if err != nil { @@ -23,13 +24,15 @@ func TestNewGobrewHomeDirUsesUserHomeDir(t *testing.T) { } func TestNewGobrewHomeDirDefaultsToHome(t *testing.T) { + t.Parallel() var envName string - if runtime.GOOS == "windows" { + switch runtime.GOOS { + case "windows": envName = "USERPROFILE" - } else if runtime.GOOS == "plan9" { + case "plan9": envName = "home" - } else { + default: envName = "HOME" } @@ -46,6 +49,7 @@ func TestNewGobrewHomeDirDefaultsToHome(t *testing.T) { } func TestNewGobrewHomeDirUsesGoBrewRoot(t *testing.T) { + t.Parallel() oldEnvValue := os.Getenv("GOBREW_ROOT") defer func() { _ = os.Setenv("GOBREW_ROOT", oldEnvValue) @@ -59,6 +63,7 @@ func TestNewGobrewHomeDirUsesGoBrewRoot(t *testing.T) { } func TestJudgeVersion(t *testing.T) { + t.Parallel() tests := []struct { version string wantVersion string @@ -88,8 +93,8 @@ func TestJudgeVersion(t *testing.T) { version: "1.18@dev-latest", wantVersion: "1.18.10", }, - // // following 2 tests fail upon new version release - // // commenting out for now as the tool is stable + // following 2 tests fail upon new version release + // commenting out for now as the tool is stable // { // version: "latest", // wantVersion: "1.19.1", @@ -100,7 +105,9 @@ func TestJudgeVersion(t *testing.T) { // }, } for _, test := range tests { + test := test t.Run(test.version, func(t *testing.T) { + t.Parallel() gb := NewGoBrew() version := gb.judgeVersion(test.version) assert.Equal(t, test.wantVersion, version) @@ -110,6 +117,7 @@ func TestJudgeVersion(t *testing.T) { } func TestListVersions(t *testing.T) { + t.Parallel() tempDir := t.TempDir() gb := NewGoBrewDirectory(tempDir) @@ -117,6 +125,7 @@ func TestListVersions(t *testing.T) { } func TestExistVersion(t *testing.T) { + t.Parallel() tempDir := t.TempDir() gb := NewGoBrewDirectory(tempDir) @@ -126,13 +135,8 @@ func TestExistVersion(t *testing.T) { } func TestInstallAndExistVersion(t *testing.T) { - tempDir := filepath.Join(os.TempDir(), "gobrew-test-install-uninstall") - err := os.MkdirAll(tempDir, os.ModePerm) - if err != nil { - t.Skip("could not create directory for gobrew update:", err) - return - } - + t.Parallel() + tempDir := t.TempDir() gb := NewGoBrewDirectory(tempDir) gb.Install("1.19") exists := gb.existsVersion("1.19") @@ -140,16 +144,8 @@ func TestInstallAndExistVersion(t *testing.T) { } func TestUnInstallThenNotExistVersion(t *testing.T) { - tempDir := filepath.Join(os.TempDir(), "gobrew-test-install-uninstall") - err := os.MkdirAll(tempDir, os.ModePerm) - if err != nil { - t.Skip("could not create directory for gobrew update:", err) - return - } - defer func() { - _ = os.RemoveAll(tempDir) - }() - + t.Parallel() + tempDir := t.TempDir() gb := NewGoBrewDirectory(tempDir) gb.Uninstall("1.19") exists := gb.existsVersion("1.19") @@ -157,6 +153,7 @@ func TestUnInstallThenNotExistVersion(t *testing.T) { } func TestUpgrade(t *testing.T) { + t.Parallel() tempDir := t.TempDir() gb := NewGoBrewDirectory(tempDir) @@ -183,6 +180,7 @@ func TestUpgrade(t *testing.T) { } func TestDoNotUpgradeLatestVersion(t *testing.T) { + t.Parallel() t.Skip("skipping test...needs to rewrite") tempDir := t.TempDir() @@ -211,16 +209,8 @@ func TestDoNotUpgradeLatestVersion(t *testing.T) { } func TestInteractive(t *testing.T) { - tempDir := filepath.Join(os.TempDir(), "gobrew-test-interactive") - err := os.MkdirAll(tempDir, os.ModePerm) - if err != nil { - t.Skip("could not create directory for gobrew update:", err) - return - } - - defer func() { - _ = os.RemoveAll(tempDir) - }() + t.Parallel() + tempDir := t.TempDir() gb := NewGoBrewDirectory(tempDir) currentVersion := gb.CurrentVersion() From f8d305ed0919177acc70e43f5e0676a787b0045e Mon Sep 17 00:00:00 2001 From: Evsyukov Denis Date: Wed, 6 Dec 2023 11:04:19 +0300 Subject: [PATCH 2/9] feat: improve gb.CurrentVersion() --- gobrew.go | 12 +++++++++--- gobrew_test.go | 28 +++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/gobrew.go b/gobrew.go index b80a43f..58d9565 100644 --- a/gobrew.go +++ b/gobrew.go @@ -11,6 +11,7 @@ import ( "path/filepath" "regexp" "runtime" + "slices" "sort" "strconv" "strings" @@ -431,9 +432,14 @@ func (gb *GoBrew) CurrentVersion() string { return "" } - version := strings.ReplaceAll(fp, strings.Join([]string{"go", "bin"}, string(os.PathSeparator)), "") - version = strings.ReplaceAll(version, gb.versionsDir, "") - version = strings.ReplaceAll(version, string(os.PathSeparator), "") + version := strings.TrimSuffix(fp, strings.Join([]string{"go", "bin"}, string(os.PathSeparator))) + paths := strings.Split(version, string(os.PathSeparator)) + slices.Reverse(paths) + for _, version = range paths { + if version != "" { + break + } + } return version } diff --git a/gobrew_test.go b/gobrew_test.go index e5bf86a..fb5adc9 100644 --- a/gobrew_test.go +++ b/gobrew_test.go @@ -63,7 +63,7 @@ func TestNewGobrewHomeDirUsesGoBrewRoot(t *testing.T) { } func TestJudgeVersion(t *testing.T) { - t.Parallel() + //t.Parallel() tests := []struct { version string wantVersion string @@ -107,7 +107,7 @@ func TestJudgeVersion(t *testing.T) { for _, test := range tests { test := test t.Run(test.version, func(t *testing.T) { - t.Parallel() + //t.Parallel() gb := NewGoBrew() version := gb.judgeVersion(test.version) assert.Equal(t, test.wantVersion, version) @@ -180,7 +180,7 @@ func TestUpgrade(t *testing.T) { } func TestDoNotUpgradeLatestVersion(t *testing.T) { - t.Parallel() + //t.Parallel() t.Skip("skipping test...needs to rewrite") tempDir := t.TempDir() @@ -239,3 +239,25 @@ func TestInteractive(t *testing.T) { currentVersion = strings.Replace(currentVersion, "private", "", -1) assert.Equal(t, currentVersion, latestVersion) } + +func TestPrune(t *testing.T) { + t.Parallel() + tempDir := t.TempDir() + gb := NewGoBrewDirectory(tempDir) + gb.Install("1.20") + gb.Install("1.19") + gb.Use("1.19") + gb.Prune() + assert.Equal(t, false, gb.existsVersion("1.20")) + assert.Equal(t, true, gb.existsVersion("1.19")) +} + +func TestGoBrew_CurrentVersion(t *testing.T) { + t.Parallel() + tempDir := t.TempDir() + gb := NewGoBrewDirectory(tempDir) + assert.Equal(t, true, gb.CurrentVersion() == "") + gb.Install("1.19") + gb.Use("1.19") + assert.Equal(t, true, gb.CurrentVersion() == "1.19") +} From e6860938839832e2c2cbcd82affd64f7b5a30b20 Mon Sep 17 00:00:00 2001 From: Evsyukov Denis Date: Wed, 6 Dec 2023 11:09:30 +0300 Subject: [PATCH 3/9] fix: do not run tests in Parallel --- gobrew_test.go | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/gobrew_test.go b/gobrew_test.go index fb5adc9..6a834b1 100644 --- a/gobrew_test.go +++ b/gobrew_test.go @@ -11,7 +11,6 @@ import ( ) func TestNewGobrewHomeDirUsesUserHomeDir(t *testing.T) { - t.Parallel() homeDir, err := os.UserHomeDir() if err != nil { @@ -24,7 +23,6 @@ func TestNewGobrewHomeDirUsesUserHomeDir(t *testing.T) { } func TestNewGobrewHomeDirDefaultsToHome(t *testing.T) { - t.Parallel() var envName string switch runtime.GOOS { @@ -49,7 +47,6 @@ func TestNewGobrewHomeDirDefaultsToHome(t *testing.T) { } func TestNewGobrewHomeDirUsesGoBrewRoot(t *testing.T) { - t.Parallel() oldEnvValue := os.Getenv("GOBREW_ROOT") defer func() { _ = os.Setenv("GOBREW_ROOT", oldEnvValue) @@ -63,7 +60,6 @@ func TestNewGobrewHomeDirUsesGoBrewRoot(t *testing.T) { } func TestJudgeVersion(t *testing.T) { - //t.Parallel() tests := []struct { version string wantVersion string @@ -107,7 +103,6 @@ func TestJudgeVersion(t *testing.T) { for _, test := range tests { test := test t.Run(test.version, func(t *testing.T) { - //t.Parallel() gb := NewGoBrew() version := gb.judgeVersion(test.version) assert.Equal(t, test.wantVersion, version) @@ -117,7 +112,6 @@ func TestJudgeVersion(t *testing.T) { } func TestListVersions(t *testing.T) { - t.Parallel() tempDir := t.TempDir() gb := NewGoBrewDirectory(tempDir) @@ -125,7 +119,6 @@ func TestListVersions(t *testing.T) { } func TestExistVersion(t *testing.T) { - t.Parallel() tempDir := t.TempDir() gb := NewGoBrewDirectory(tempDir) @@ -135,7 +128,6 @@ func TestExistVersion(t *testing.T) { } func TestInstallAndExistVersion(t *testing.T) { - t.Parallel() tempDir := t.TempDir() gb := NewGoBrewDirectory(tempDir) gb.Install("1.19") @@ -144,7 +136,6 @@ func TestInstallAndExistVersion(t *testing.T) { } func TestUnInstallThenNotExistVersion(t *testing.T) { - t.Parallel() tempDir := t.TempDir() gb := NewGoBrewDirectory(tempDir) gb.Uninstall("1.19") @@ -153,7 +144,6 @@ func TestUnInstallThenNotExistVersion(t *testing.T) { } func TestUpgrade(t *testing.T) { - t.Parallel() tempDir := t.TempDir() gb := NewGoBrewDirectory(tempDir) @@ -180,7 +170,6 @@ func TestUpgrade(t *testing.T) { } func TestDoNotUpgradeLatestVersion(t *testing.T) { - //t.Parallel() t.Skip("skipping test...needs to rewrite") tempDir := t.TempDir() @@ -209,7 +198,6 @@ func TestDoNotUpgradeLatestVersion(t *testing.T) { } func TestInteractive(t *testing.T) { - t.Parallel() tempDir := t.TempDir() gb := NewGoBrewDirectory(tempDir) @@ -241,7 +229,6 @@ func TestInteractive(t *testing.T) { } func TestPrune(t *testing.T) { - t.Parallel() tempDir := t.TempDir() gb := NewGoBrewDirectory(tempDir) gb.Install("1.20") @@ -253,7 +240,6 @@ func TestPrune(t *testing.T) { } func TestGoBrew_CurrentVersion(t *testing.T) { - t.Parallel() tempDir := t.TempDir() gb := NewGoBrewDirectory(tempDir) assert.Equal(t, true, gb.CurrentVersion() == "") From 01a10fa768eec8f0fc7eb7144271153ab4faab4c Mon Sep 17 00:00:00 2001 From: Evsyukov Denis Date: Thu, 7 Dec 2023 10:15:01 +0300 Subject: [PATCH 4/9] feat: use bash shell for github actions --- .github/workflows/build.yml | 2 ++ .github/workflows/coveritup.yml | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0eed19e..4552d8a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,5 +20,7 @@ jobs: - name: Go version run: go version + shell: bash - name: Build run: go build cmd/gobrew/main.go + shell: bash diff --git a/.github/workflows/coveritup.yml b/.github/workflows/coveritup.yml index d109a89..7b18a05 100644 --- a/.github/workflows/coveritup.yml +++ b/.github/workflows/coveritup.yml @@ -30,12 +30,13 @@ jobs: go install github.com/securego/gosec/v2/cmd/gosec@latest go install github.com/axw/gocov/gocov@latest go install github.com/AlekSi/gocov-xml@latest + shell: bash - name: Test run: | BUILD_START=$SECONDS go test -race -v ./... -count=1 -coverprofile=coverage.out echo SCORE=$(($SECONDS-BUILD_START)) >> "$GITHUB_ENV" - + shell: bash - uses: kevincobain2000/action-coveritup@v1 with: type: unit-test-run-time @@ -49,6 +50,7 @@ jobs: BUILD_START=$SECONDS go build -ldflags '-s -w' -o main cmd/gobrew/main.go echo SCORE=$(($SECONDS-BUILD_START)) >> "$GITHUB_ENV" + shell: bash - uses: kevincobain2000/action-coveritup@v1 with: @@ -58,6 +60,7 @@ jobs: run: | curl -sLk https://raw.githubusercontent.com/kevincobain2000/cover-totalizer/master/install.sh | sh echo SCORE=`./cover-totalizer coverage.xml` >> "$GITHUB_ENV" + shell: bash - uses: kevincobain2000/action-coveritup@v1 with: @@ -66,6 +69,7 @@ jobs: - name: Go Binary Size run: | echo SCORE=`du -sk main | awk '{print $1}'` >> "$GITHUB_ENV" + shell: bash - uses: kevincobain2000/action-coveritup@v1 with: @@ -74,6 +78,7 @@ jobs: - name: Number of dependencies run: | echo SCORE=`go list -m all|wc -l|awk '{$1=$1};1'` >> "$GITHUB_ENV" + shell: bash - uses: kevincobain2000/action-coveritup@v1 with: @@ -82,6 +87,7 @@ jobs: - name: Number of GO Sec issues run: | echo SCORE=`gosec -no-fail --quiet ./...|grep Issues | tail -1 |awk '{print $3}'` >> "$GITHUB_ENV" + shell: bash - uses: kevincobain2000/action-coveritup@v1 with: From cf33539a891fe60b92a3c95a87e471324fd77309 Mon Sep 17 00:00:00 2001 From: Evsyukov Denis Date: Thu, 7 Dec 2023 10:40:27 +0300 Subject: [PATCH 5/9] feat: do not use slices package for currentVersion --- gobrew.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/gobrew.go b/gobrew.go index 58d9565..ede6d14 100644 --- a/gobrew.go +++ b/gobrew.go @@ -11,7 +11,6 @@ import ( "path/filepath" "regexp" "runtime" - "slices" "sort" "strconv" "strings" @@ -434,8 +433,8 @@ func (gb *GoBrew) CurrentVersion() string { version := strings.TrimSuffix(fp, strings.Join([]string{"go", "bin"}, string(os.PathSeparator))) paths := strings.Split(version, string(os.PathSeparator)) - slices.Reverse(paths) - for _, version = range paths { + for i := len(paths) - 1; i >= 0; i-- { + version = paths[i] if version != "" { break } From 814b7e75ed07e2e4ba1fc64cdad36ebddcb757e5 Mon Sep 17 00:00:00 2001 From: Evsyukov Denis Date: Thu, 7 Dec 2023 11:44:08 +0300 Subject: [PATCH 6/9] feat: use filepath for process version --- gobrew.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/gobrew.go b/gobrew.go index ede6d14..5a1c053 100644 --- a/gobrew.go +++ b/gobrew.go @@ -425,19 +425,15 @@ func (gb *GoBrew) existsVersion(version string) bool { // CurrentVersion get current version from symb link func (gb *GoBrew) CurrentVersion() string { - fp, err := filepath.EvalSymlinks(gb.currentBinDir) if err != nil { return "" } - version := strings.TrimSuffix(fp, strings.Join([]string{"go", "bin"}, string(os.PathSeparator))) - paths := strings.Split(version, string(os.PathSeparator)) - for i := len(paths) - 1; i >= 0; i-- { - version = paths[i] - if version != "" { - break - } + version := strings.TrimSuffix(fp, filepath.Join("go", "bin")) + version = filepath.Base(version) + if version == "." { + return "" } return version } From 4a397d33e7a487206ba7705b25e4ce77e25723b1 Mon Sep 17 00:00:00 2001 From: Evsyukov Denis Date: Thu, 7 Dec 2023 12:12:16 +0300 Subject: [PATCH 7/9] fix: issue with no tests were run --- gobrew.go | 1 + gobrew_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/gobrew.go b/gobrew.go index 5a1c053..8d835c3 100644 --- a/gobrew.go +++ b/gobrew.go @@ -688,6 +688,7 @@ func (gb *GoBrew) mkDirs(version string) { func (gb *GoBrew) getVersionDir(version string) string { return filepath.Join(gb.versionsDir, version) } + func (gb *GoBrew) downloadAndExtract(version string) { tarName := "go" + version + "." + gb.getArch() diff --git a/gobrew_test.go b/gobrew_test.go index 6a834b1..e8ac581 100644 --- a/gobrew_test.go +++ b/gobrew_test.go @@ -20,6 +20,7 @@ func TestNewGobrewHomeDirUsesUserHomeDir(t *testing.T) { gobrew := NewGoBrew() assert.Equal(t, homeDir, gobrew.homeDir) + t.Log("test finished") } func TestNewGobrewHomeDirDefaultsToHome(t *testing.T) { @@ -44,6 +45,7 @@ func TestNewGobrewHomeDirDefaultsToHome(t *testing.T) { gobrew := NewGoBrew() assert.Equal(t, os.Getenv("HOME"), gobrew.homeDir) + t.Log("test finished") } func TestNewGobrewHomeDirUsesGoBrewRoot(t *testing.T) { @@ -57,6 +59,7 @@ func TestNewGobrewHomeDirUsesGoBrewRoot(t *testing.T) { gobrew := NewGoBrew() assert.Equal(t, "some_fancy_value", gobrew.homeDir) + t.Log("test finished") } func TestJudgeVersion(t *testing.T) { @@ -109,6 +112,7 @@ func TestJudgeVersion(t *testing.T) { }) } + t.Log("test finished") } func TestListVersions(t *testing.T) { @@ -116,6 +120,7 @@ func TestListVersions(t *testing.T) { gb := NewGoBrewDirectory(tempDir) gb.ListVersions() + t.Log("test finished") } func TestExistVersion(t *testing.T) { @@ -125,6 +130,7 @@ func TestExistVersion(t *testing.T) { exists := gb.existsVersion("1.19") assert.Equal(t, false, exists) + t.Log("test finished") } func TestInstallAndExistVersion(t *testing.T) { @@ -133,6 +139,7 @@ func TestInstallAndExistVersion(t *testing.T) { gb.Install("1.19") exists := gb.existsVersion("1.19") assert.Equal(t, true, exists) + t.Log("test finished") } func TestUnInstallThenNotExistVersion(t *testing.T) { @@ -141,6 +148,7 @@ func TestUnInstallThenNotExistVersion(t *testing.T) { gb.Uninstall("1.19") exists := gb.existsVersion("1.19") assert.Equal(t, false, exists) + t.Log("test finished") } func TestUpgrade(t *testing.T) { @@ -167,6 +175,7 @@ func TestUpgrade(t *testing.T) { if _, err := os.Stat(binaryFile); err != nil { t.Errorf("updated executable does not exist") } + t.Log("test finished") } func TestDoNotUpgradeLatestVersion(t *testing.T) { @@ -195,6 +204,7 @@ func TestDoNotUpgradeLatestVersion(t *testing.T) { if _, err := os.Stat(binaryFile); err == nil { t.Errorf("unexpected upgrade of latest version") } + t.Log("test finished") } func TestInteractive(t *testing.T) { @@ -226,6 +236,7 @@ func TestInteractive(t *testing.T) { currentVersion = gb.CurrentVersion() currentVersion = strings.Replace(currentVersion, "private", "", -1) assert.Equal(t, currentVersion, latestVersion) + t.Log("test finished") } func TestPrune(t *testing.T) { @@ -237,6 +248,7 @@ func TestPrune(t *testing.T) { gb.Prune() assert.Equal(t, false, gb.existsVersion("1.20")) assert.Equal(t, true, gb.existsVersion("1.19")) + t.Log("test finished") } func TestGoBrew_CurrentVersion(t *testing.T) { @@ -246,4 +258,5 @@ func TestGoBrew_CurrentVersion(t *testing.T) { gb.Install("1.19") gb.Use("1.19") assert.Equal(t, true, gb.CurrentVersion() == "1.19") + t.Log("test finished") } From 350ecf1e9126e97e7a130876c67faecacd756555 Mon Sep 17 00:00:00 2001 From: Evsyukov Denis Date: Thu, 7 Dec 2023 12:53:43 +0300 Subject: [PATCH 8/9] feat: os specific functions and vars --- gobrew.go | 20 ++------------------ gobrew_test.go | 10 ++-------- gobrew_unix.go | 18 ++++++++++++++++++ gobrew_windows.go | 17 +++++++++++++++++ 4 files changed, 39 insertions(+), 26 deletions(-) create mode 100644 gobrew_unix.go create mode 100644 gobrew_windows.go diff --git a/gobrew.go b/gobrew.go index 8d835c3..03a24ec 100644 --- a/gobrew.go +++ b/gobrew.go @@ -639,11 +639,6 @@ func (gb *GoBrew) Upgrade(currentVersion string) { return } - fileExt := "" - if runtime.GOOS == "windows" { - fileExt = ".exe" - } - mkdirTemp, _ := os.MkdirTemp("", "gobrew") tmpFile := filepath.Join(mkdirTemp, "gobrew"+fileExt) url := goBrewDownloadUrl + "gobrew-" + gb.getArch() + fileExt @@ -659,12 +654,7 @@ func (gb *GoBrew) Upgrade(currentVersion string) { }(source) goBrewFile := filepath.Join(gb.installDir, "bin", "gobrew"+fileExt) - if runtime.GOOS == "windows" { - goBrewOldFile := goBrewFile + ".old" - utils.CheckError(os.Rename(goBrewFile, goBrewOldFile), "==> [Error] Cannot rename binary file") - } else { - utils.CheckError(os.Remove(goBrewFile), "==> [Error] Cannot remove binary file") - } + removeFile(goBrewFile) destination, err := os.Create(goBrewFile) utils.CheckError(err, "==> [Error] Cannot open file") defer func(destination *os.File) { @@ -690,13 +680,7 @@ func (gb *GoBrew) getVersionDir(version string) string { } func (gb *GoBrew) downloadAndExtract(version string) { - tarName := "go" + version + "." + gb.getArch() - - if runtime.GOOS == "windows" { - tarName = tarName + ".zip" - } else { - tarName = tarName + ".tar.gz" - } + tarName := "go" + version + "." + gb.getArch() + tarNameExt registryPath := defaultRegistryPath if p := os.Getenv("GOBREW_REGISTRY"); p != "" { diff --git a/gobrew_test.go b/gobrew_test.go index e8ac581..2ba8316 100644 --- a/gobrew_test.go +++ b/gobrew_test.go @@ -159,10 +159,7 @@ func TestUpgrade(t *testing.T) { binaryDir := filepath.Join(gb.installDir, "bin") _ = os.MkdirAll(binaryDir, os.ModePerm) - baseName := "gobrew" - if runtime.GOOS == "windows" { - baseName = baseName + ".exe" - } + baseName := "gobrew" + fileExt binaryFile := filepath.Join(binaryDir, baseName) if oldFile, err := os.Create(binaryFile); err == nil { @@ -187,10 +184,7 @@ func TestDoNotUpgradeLatestVersion(t *testing.T) { binaryDir := filepath.Join(gb.installDir, "bin") _ = os.MkdirAll(binaryDir, os.ModePerm) - baseName := "gobrew" - if runtime.GOOS == "windows" { - baseName = baseName + ".exe" - } + baseName := "gobrew" + fileExt binaryFile := filepath.Join(binaryDir, baseName) currentVersion := gb.getGobrewVersion() diff --git a/gobrew_unix.go b/gobrew_unix.go new file mode 100644 index 0000000..478d185 --- /dev/null +++ b/gobrew_unix.go @@ -0,0 +1,18 @@ +//go:build unix + +package gobrew + +import ( + "os" + + "github.com/kevincobain2000/gobrew/utils" +) + +const ( + fileExt = "" + tarNameExt = ".tar.gz" +) + +func removeFile(goBrewFile string) { + utils.CheckError(os.Remove(goBrewFile), "==> [Error] Cannot remove binary file") +} diff --git a/gobrew_windows.go b/gobrew_windows.go new file mode 100644 index 0000000..e6a6331 --- /dev/null +++ b/gobrew_windows.go @@ -0,0 +1,17 @@ +package gobrew + +import ( + "os" + + "github.com/kevincobain2000/gobrew/utils" +) + +const ( + fileExt = ".exe" + tarNameExt = ".zip" +) + +func removeFile(goBrewFile string) { + goBrewOldFile := goBrewFile + ".old" + utils.CheckError(os.Rename(goBrewFile, goBrewOldFile), "==> [Error] Cannot rename binary file") +} From faba08b34b685139401e58526bdeed81bc9d0fd9 Mon Sep 17 00:00:00 2001 From: Evsyukov Denis Date: Thu, 7 Dec 2023 13:01:52 +0300 Subject: [PATCH 9/9] feat: rename github workflows add run test for windows platform --- .github/workflows/build.yml | 3 ++- .github/workflows/coveritup.yml | 3 ++- .github/workflows/release.yml | 3 +-- .github/workflows/sync-release-tags.yml | 2 +- .github/workflows/test.yml | 5 +++-- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4552d8a..eeae011 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,7 +4,8 @@ on: - '**/*.go' - '**/*.mod' - '**/*.sum' -name: CI + +name: "Build" jobs: build: strategy: diff --git a/.github/workflows/coveritup.yml b/.github/workflows/coveritup.yml index 7b18a05..f2ffe1c 100644 --- a/.github/workflows/coveritup.yml +++ b/.github/workflows/coveritup.yml @@ -11,7 +11,8 @@ on: - '**/*.mod' - '**/*.sum' - '**/*.yaml' -name: Cover It Up + +name: "Cover It Up" jobs: coveritup: strategy: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index cad2092..1eaa955 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,10 +1,9 @@ -name: goreleaser - on: push: tags: - '*' +name: "Create release" jobs: goreleaser: runs-on: ubuntu-latest diff --git a/.github/workflows/sync-release-tags.yml b/.github/workflows/sync-release-tags.yml index 060214f..e81b0aa 100644 --- a/.github/workflows/sync-release-tags.yml +++ b/.github/workflows/sync-release-tags.yml @@ -3,8 +3,8 @@ on: # hourly # This crontab is related to https://github.com/kevincobain2000/gobrew/issues/45 - cron: '0 * * * *' -name: "Sync Go releases" +name: "Sync Go releases" jobs: sync-tags: name: sync diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 416bb19..9e9080f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,13 +5,14 @@ on: - '**/*.mod' - '**/*.sum' - '**/*.yaml' -name: CI + +name: "Go test" jobs: test: strategy: matrix: go-version: [dev-latest] - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, windows-latest, macos-latest] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4