From 56cd77ac112a5152cfc84ad59d9adb8444440eb8 Mon Sep 17 00:00:00 2001 From: xucong053 Date: Tue, 31 May 2022 13:09:32 +0800 Subject: [PATCH 1/2] fix: failed to build debugtalk.go without go.mod --- examples/demo-empty-project/proj.json | 4 ++-- examples/demo-with-go-plugin/proj.json | 4 ++-- examples/demo-with-py-plugin/proj.json | 4 ++-- examples/demo-without-plugin/proj.json | 4 ++-- hrp/build.go | 22 +++++++++++++++++----- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/examples/demo-empty-project/proj.json b/examples/demo-empty-project/proj.json index 38a8dbce..89891403 100644 --- a/examples/demo-empty-project/proj.json +++ b/examples/demo-empty-project/proj.json @@ -1,6 +1,6 @@ { "project_name": "demo-empty-project", - "project_path": "/Users/debugtalk/MyProjects/HttpRunner-dev/httprunner/examples/demo-empty-project", - "create_time": "2022-05-29T13:24:31.960615+08:00", + "project_path": "/Users/xxxxx/go/src/github.com/httprunner/httprunner/examples/demo-empty-project", + "create_time": "2022-05-31T13:12:05.552655+08:00", "hrp_version": "v4.1.0" } \ No newline at end of file diff --git a/examples/demo-with-go-plugin/proj.json b/examples/demo-with-go-plugin/proj.json index ea8c1534..1d013463 100644 --- a/examples/demo-with-go-plugin/proj.json +++ b/examples/demo-with-go-plugin/proj.json @@ -1,6 +1,6 @@ { "project_name": "demo-with-go-plugin", - "project_path": "/Users/debugtalk/MyProjects/HttpRunner-dev/httprunner/examples/demo-with-go-plugin", - "create_time": "2022-05-29T13:24:29.431434+08:00", + "project_path": "/Users/xxxxx/go/src/github.com/httprunner/httprunner/examples/demo-with-go-plugin", + "create_time": "2022-05-31T13:12:04.150418+08:00", "hrp_version": "v4.1.0" } \ No newline at end of file diff --git a/examples/demo-with-py-plugin/proj.json b/examples/demo-with-py-plugin/proj.json index 847d146d..ccec7c84 100644 --- a/examples/demo-with-py-plugin/proj.json +++ b/examples/demo-with-py-plugin/proj.json @@ -1,6 +1,6 @@ { "project_name": "demo-with-py-plugin", - "project_path": "/Users/debugtalk/MyProjects/HttpRunner-dev/httprunner/examples/demo-with-py-plugin", - "create_time": "2022-05-29T13:24:29.566414+08:00", + "project_path": "/Users/xxxxx/go/src/github.com/httprunner/httprunner/examples/demo-with-py-plugin", + "create_time": "2022-05-31T13:12:04.292557+08:00", "hrp_version": "v4.1.0" } \ No newline at end of file diff --git a/examples/demo-without-plugin/proj.json b/examples/demo-without-plugin/proj.json index bd9b8d79..bf08ffc7 100644 --- a/examples/demo-without-plugin/proj.json +++ b/examples/demo-without-plugin/proj.json @@ -1,6 +1,6 @@ { "project_name": "demo-without-plugin", - "project_path": "/Users/debugtalk/MyProjects/HttpRunner-dev/httprunner/examples/demo-without-plugin", - "create_time": "2022-05-29T13:24:31.840718+08:00", + "project_path": "/Users/xxxxx/go/src/github.com/httprunner/httprunner/examples/demo-without-plugin", + "create_time": "2022-05-31T13:12:05.424068+08:00", "hrp_version": "v4.1.0" } \ No newline at end of file diff --git a/hrp/build.go b/hrp/build.go index d77c6b3c..beeafd90 100644 --- a/hrp/build.go +++ b/hrp/build.go @@ -12,10 +12,10 @@ import ( "strings" "text/template" - "github.com/httprunner/funplugin/shared" "github.com/pkg/errors" "github.com/rs/zerolog/log" + "github.com/httprunner/funplugin/shared" "github.com/httprunner/httprunner/v4/hrp/internal/builtin" "github.com/httprunner/httprunner/v4/hrp/internal/version" ) @@ -209,10 +209,22 @@ func buildGo(path string, output string) error { return err } - // download plugin dependency - // funplugin version should be locked - funplugin := fmt.Sprintf("github.com/httprunner/funplugin@%s", shared.Version) - if err := builtin.ExecCommandInDir(exec.Command("go", "get", funplugin), pluginDir); err != nil { + if !builtin.IsFilePathExists(filepath.Join(pluginDir, "go.mod")) { + // create go mod + if err := builtin.ExecCommandInDir(exec.Command("go", "mod", "init", "main"), pluginDir); err != nil { + return err + } + + // download plugin dependency + // funplugin version should be locked + funplugin := fmt.Sprintf("github.com/httprunner/funplugin@%s", shared.Version) + if err := builtin.ExecCommandInDir(exec.Command("go", "get", funplugin), pluginDir); err != nil { + return err + } + } + + // add missing and remove unused modules + if err := builtin.ExecCommandInDir(exec.Command("go", "mod", "tidy"), pluginDir); err != nil { return err } From 2c2ed04b749d3b5d00ca351840d6ad41112e06eb Mon Sep 17 00:00:00 2001 From: xucong053 Date: Tue, 31 May 2022 15:07:08 +0800 Subject: [PATCH 2/2] remove project_path info from proj.json in project dir --- examples/demo-empty-project/proj.json | 3 +-- examples/demo-with-go-plugin/proj.json | 3 +-- examples/demo-with-py-plugin/proj.json | 3 +-- examples/demo-without-plugin/proj.json | 3 +-- hrp/internal/scaffold/main.go | 10 +--------- 5 files changed, 5 insertions(+), 17 deletions(-) diff --git a/examples/demo-empty-project/proj.json b/examples/demo-empty-project/proj.json index 89891403..4ce79550 100644 --- a/examples/demo-empty-project/proj.json +++ b/examples/demo-empty-project/proj.json @@ -1,6 +1,5 @@ { "project_name": "demo-empty-project", - "project_path": "/Users/xxxxx/go/src/github.com/httprunner/httprunner/examples/demo-empty-project", - "create_time": "2022-05-31T13:12:05.552655+08:00", + "create_time": "2022-05-31T15:05:51.196187+08:00", "hrp_version": "v4.1.0" } \ No newline at end of file diff --git a/examples/demo-with-go-plugin/proj.json b/examples/demo-with-go-plugin/proj.json index 1d013463..1dc616b6 100644 --- a/examples/demo-with-go-plugin/proj.json +++ b/examples/demo-with-go-plugin/proj.json @@ -1,6 +1,5 @@ { "project_name": "demo-with-go-plugin", - "project_path": "/Users/xxxxx/go/src/github.com/httprunner/httprunner/examples/demo-with-go-plugin", - "create_time": "2022-05-31T13:12:04.150418+08:00", + "create_time": "2022-05-31T15:05:49.894029+08:00", "hrp_version": "v4.1.0" } \ No newline at end of file diff --git a/examples/demo-with-py-plugin/proj.json b/examples/demo-with-py-plugin/proj.json index ccec7c84..c854eeb0 100644 --- a/examples/demo-with-py-plugin/proj.json +++ b/examples/demo-with-py-plugin/proj.json @@ -1,6 +1,5 @@ { "project_name": "demo-with-py-plugin", - "project_path": "/Users/xxxxx/go/src/github.com/httprunner/httprunner/examples/demo-with-py-plugin", - "create_time": "2022-05-31T13:12:04.292557+08:00", + "create_time": "2022-05-31T15:05:50.036068+08:00", "hrp_version": "v4.1.0" } \ No newline at end of file diff --git a/examples/demo-without-plugin/proj.json b/examples/demo-without-plugin/proj.json index bf08ffc7..afe69717 100644 --- a/examples/demo-without-plugin/proj.json +++ b/examples/demo-without-plugin/proj.json @@ -1,6 +1,5 @@ { "project_name": "demo-without-plugin", - "project_path": "/Users/xxxxx/go/src/github.com/httprunner/httprunner/examples/demo-without-plugin", - "create_time": "2022-05-31T13:12:05.424068+08:00", + "create_time": "2022-05-31T15:05:51.066376+08:00", "hrp_version": "v4.1.0" } \ No newline at end of file diff --git a/hrp/internal/scaffold/main.go b/hrp/internal/scaffold/main.go index 941ab14c..04ad8ac5 100644 --- a/hrp/internal/scaffold/main.go +++ b/hrp/internal/scaffold/main.go @@ -28,7 +28,6 @@ const ( type ProjectInfo struct { ProjectName string `json:"project_name,omitempty" yaml:"project_name,omitempty"` - ProjectPath string `json:"project_path,omitempty" yaml:"project_path,omitempty"` CreateTime time.Time `json:"create_time,omitempty" yaml:"create_time,omitempty"` Version string `json:"hrp_version,omitempty" yaml:"hrp_version,omitempty"` } @@ -78,12 +77,6 @@ func CreateScaffold(projectName string, pluginType PluginType, force bool) error os.RemoveAll(projectName) } - // get project abs path - projectPath, err := filepath.Abs(projectName) - if err != nil { - projectPath = projectName - } - // create project folders if err := builtin.CreateFolder(projectName); err != nil { return err @@ -106,13 +99,12 @@ func CreateScaffold(projectName string, pluginType PluginType, force bool) error projectInfo := &ProjectInfo{ ProjectName: filepath.Base(projectName), - ProjectPath: projectPath, CreateTime: time.Now(), Version: version.VERSION, } // dump project information to file - err = builtin.Dump2JSON(projectInfo, filepath.Join(projectName, "proj.json")) + err := builtin.Dump2JSON(projectInfo, filepath.Join(projectName, "proj.json")) if err != nil { return err }