diff --git a/.gitignore b/.gitignore index a36102e..cbb8249 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ tmp /tower_windows_amd64.exe /.vscode /debug.test -tower-app-* \ No newline at end of file +tower-app-* +/tower \ No newline at end of file diff --git a/app.go b/app.go index 5b8ced1..524d3ff 100644 --- a/app.go +++ b/app.go @@ -59,6 +59,7 @@ type App struct { buildErr error startErr error restartErr error + _goVersion string } type StderrCapturer struct { @@ -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 diff --git a/app_test.go b/app_test.go new file mode 100644 index 0000000..7a69597 --- /dev/null +++ b/app_test.go @@ -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`, ">=")) +} diff --git a/main.go b/main.go index a9e816c..0dfde1b 100644 --- a/main.go +++ b/main.go @@ -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