Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
admpub committed Aug 22, 2022
1 parent 82ed159 commit 1c6f839
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ tmp
/tower_windows_amd64.exe
/.vscode
/debug.test
tower-app-*
tower-app-*
/tower
37 changes: 37 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type App struct {
buildErr error
startErr error
restartErr error
_goVersion string
}

type StderrCapturer struct {
Expand Down Expand Up @@ -493,6 +494,42 @@ func (this *App) fetchPkg(matches [][]string, isRetry bool, args ...string) bool
return alldl
}

func (this *App) goVersion() (string, error) {
if len(this._goVersion) > 0 {
return this._goVersion, nil
}
b, err := exec.Command("go", "version").CombinedOutput()
if err != nil {
return "", err
}
v := string(b)
v = strings.TrimPrefix(v, `go version go`)
v = strings.SplitN(v, ` `, 2)[0]
this._goVersion = v
return v, nil
}

func (this *App) fillDefaultBuildParams(args []string) ([]string, error) {
gover, err := this.goVersion()
if err != nil {
return args, err
}
if com.VersionComparex(gover, `1.18.0`, ">=") {
var hasBuildVCSArg bool
for _, arg := range args {
arg = strings.TrimLeft(arg, `-`)
if strings.HasPrefix(arg, `buildvcs=`) {
hasBuildVCSArg = true
break
}
}
if !hasBuildVCSArg {
args = append(args, "-buildvcs=false")
}
}
return args, nil
}

func (this *App) Build() (err error) {
if this.DisabledBuild {
return nil
Expand Down
20 changes: 20 additions & 0 deletions app_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
"github.com/webx-top/com"
)

func TestGoVersion(t *testing.T) {
a := &App{}
gover, err := a.goVersion()
assert.NoError(t, err)
assert.Equal(t, true, len(gover) > 0)
fmt.Println(gover)

assert.True(t, com.VersionComparex(`1.18`, `1.18.0`, ">="))
assert.True(t, com.VersionComparex(`1.18.1`, `1.18.0`, ">="))
}
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ func startTower() {
}
if len(c.Conf.App.BuildParams) > 0 {
app.BuildParams = parseParams(c.Conf.App.BuildParams)
app.BuildParams, err = app.fillDefaultBuildParams(app.BuildParams)
if err != nil {
log.Error(err)
}
}
app.BeforeBuildGenerate = c.Conf.App.Generate
watchedDir := app.Root
Expand Down

0 comments on commit 1c6f839

Please sign in to comment.