diff --git a/.travis.yml b/.travis.yml index 96490883a6a..ddeb794dc2c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -191,17 +191,16 @@ jobs: stage: test # Generators - # https://github.com/elastic/beats/issues/16951 - #- os: linux - # before_install: .ci/scripts/travis_has_changes.sh generator metricbeat libbeat || travis_terminate 0 - # env: TARGETS="-C generator/_templates/metricbeat test test-package" - # go: $TRAVIS_GO_VERSION - # stage: test - #- os: linux - # before_install: .ci/scripts/travis_has_changes.sh generator libbeat || travis_terminate 0 - # env: TARGETS="-C generator/_templates/beat test test-package" - # go: $TRAVIS_GO_VERSION - # stage: test + - os: linux + before_install: .ci/scripts/travis_has_changes.sh generator metricbeat libbeat || travis_terminate 0 + env: TARGETS="-C generator/_templates/metricbeat test test-package" + go: $TRAVIS_GO_VERSION + stage: test + - os: linux + before_install: .ci/scripts/travis_has_changes.sh generator libbeat || travis_terminate 0 + env: TARGETS="-C generator/_templates/beat test test-package" + go: $TRAVIS_GO_VERSION + stage: test - os: osx before_install: .ci/scripts/travis_has_changes.sh generator metricbeat libbeat || travis_terminate 0 diff --git a/dev-tools/mage/gomod.go b/dev-tools/mage/gomod.go index ae136665b1b..dcff94563ae 100644 --- a/dev-tools/mage/gomod.go +++ b/dev-tools/mage/gomod.go @@ -21,33 +21,35 @@ import ( "os" "path/filepath" + "github.com/pkg/errors" + "github.com/elastic/beats/v7/dev-tools/mage/gotool" ) -// copyModule contains a module name and the list of files or directories +// CopyModule contains a module name and the list of files or directories // to copy recursively. -type copyModule struct { - name string - filesToCopy []string +type CopyModule struct { + Name string + FilesToCopy []string } var ( - copyAll = []copyModule{ - copyModule{ - name: "github.com/godror/godror", - filesToCopy: []string{ - "odpi", + copyAll = []CopyModule{ + CopyModule{ + Name: "github.com/tsg/go-daemon", + FilesToCopy: []string{ + "src", }, }, - copyModule{ - name: "github.com/tsg/go-daemon", - filesToCopy: []string{ - "src", + CopyModule{ + Name: "github.com/godror/godror", + FilesToCopy: []string{ + "odpi", }, }, } filesToRemove = []string{ - filepath.Join("vendor", "github.com", "yuin", "gopher-lua", "parse", "Makefile"), + filepath.Join("github.com", "yuin", "gopher-lua", "parse", "Makefile"), } ) @@ -57,49 +59,57 @@ func Vendor() error { err := mod.Tidy() if err != nil { - return err + return errors.Wrap(err, "error while running go mod tidy") } err = mod.Vendor() if err != nil { - return err + return errors.Wrap(err, "error while running go mod vendor") } err = mod.Verify() if err != nil { - return err + return errors.Wrap(err, "error while running go mod verify") } repo, err := GetProjectRepoInfo() if err != nil { - return err + return errors.Wrap(err, "error while getting repository information") } + vendorFolder := filepath.Join(repo.RootDir, "vendor") + err = CopyFilesToVendor(vendorFolder, copyAll) + if err != nil { + return errors.Wrap(err, "error copying required files") + } + + for _, p := range filesToRemove { + p = filepath.Join(vendorFolder, p) + err = os.RemoveAll(p) + if err != nil { + return errors.Wrapf(err, "error while removing file: %s", p) + } + } + return nil +} - // copy packages which require the whole tree - for _, p := range copyAll { - path, err := gotool.ListModuleCacheDir(p.name) +// CopyFilesToVendor copies packages which require the whole tree +func CopyFilesToVendor(vendorFolder string, modulesToCopy []CopyModule) error { + for _, p := range modulesToCopy { + path, err := gotool.ListModuleCacheDir(p.Name) if err != nil { - return err + return errors.Wrapf(err, "error while looking up cached dir of module: %s", p.Name) } - for _, f := range p.filesToCopy { + for _, f := range p.FilesToCopy { from := filepath.Join(path, f) - to := filepath.Join(vendorFolder, p.name, f) - copyTask := &CopyTask{Source: from, Dest: to, DirMode: os.ModeDir | 0750} + to := filepath.Join(vendorFolder, p.Name, f) + copyTask := &CopyTask{Source: from, Dest: to, Mode: 0600, DirMode: os.ModeDir | 0750} err = copyTask.Execute() if err != nil { - return err + return errors.Wrapf(err, "error while copying file from %s to %s", from, to) } } } - - for _, p := range filesToRemove { - p = filepath.Join(repo.RootDir, p) - err = os.RemoveAll(p) - if err != nil { - return err - } - } return nil } diff --git a/generator/_templates/beat/{beat}/tools/tools.go b/generator/_templates/beat/{beat}/tools/tools.go index d816e58647f..edd121e211b 100644 --- a/generator/_templates/beat/{beat}/tools/tools.go +++ b/generator/_templates/beat/{beat}/tools/tools.go @@ -6,6 +6,7 @@ package tools import ( _ "github.com/pierrre/gotestcover" + _ "github.com/tsg/go-daemon" _ "golang.org/x/tools/cmd/goimports" _ "github.com/mitchellh/gox" diff --git a/generator/_templates/metricbeat/{beat}/tools/tools.go b/generator/_templates/metricbeat/{beat}/tools/tools.go index d816e58647f..edd121e211b 100644 --- a/generator/_templates/metricbeat/{beat}/tools/tools.go +++ b/generator/_templates/metricbeat/{beat}/tools/tools.go @@ -6,6 +6,7 @@ package tools import ( _ "github.com/pierrre/gotestcover" + _ "github.com/tsg/go-daemon" _ "golang.org/x/tools/cmd/goimports" _ "github.com/mitchellh/gox" diff --git a/generator/common/beatgen/setup/setup.go b/generator/common/beatgen/setup/setup.go index b372660971d..42098c40f4d 100644 --- a/generator/common/beatgen/setup/setup.go +++ b/generator/common/beatgen/setup/setup.go @@ -29,16 +29,6 @@ import ( "github.com/elastic/beats/v7/dev-tools/mage/gotool" ) -var ( - makefileDeps = []string{ - "dev-tools", - "libbeat", - "licenses", - "metricbeat", - "script", - } -) - func InitModule() error { err := gotool.Mod.Init() if err != nil { @@ -109,24 +99,35 @@ func copyReplacedModules() error { func CopyVendor() error { err := gotool.Mod.Vendor() if err != nil { - return err + return errors.Wrapf(err, "error while running go mod vendor") } - path, err := gotool.ListModuleCacheDir("github.com/elastic/beats/v7") + err = devtools.CopyFilesToVendor( + "./vendor", + []devtools.CopyModule{ + devtools.CopyModule{ + Name: "github.com/elastic/beats/v7", + FilesToCopy: []string{ + "dev-tools", + "libbeat", + "licenses", + "metricbeat", + "script", + ".go-version", + }, + }, + devtools.CopyModule{ + Name: "github.com/tsg/go-daemon", + FilesToCopy: []string{ + "src", + }, + }, + }, + ) if err != nil { - return err + return errors.Wrapf(err, "error while copying required files to vendor") } - vendorPath := "./vendor/github.com/elastic/beats/v7" - for _, d := range makefileDeps { - from := filepath.Join(path, d) - to := filepath.Join(vendorPath, d) - copyTask := &devtools.CopyTask{Source: from, Dest: to, Mode: 0640, DirMode: os.ModeDir | 0750} - err = copyTask.Execute() - if err != nil { - return err - } - } return nil }