From a851b7c2ac0b83839cd42458d80f5dad1d8c7948 Mon Sep 17 00:00:00 2001 From: Andrew Kroh Date: Tue, 12 Oct 2021 19:39:38 -0400 Subject: [PATCH] Fix modified go.sum issue in beat generators There were two issues: `go mod download` was run after the newly generated beat was committed. This modified the go.sum because it adds hashes for the downloaded dependencies. The caused `mage check` to fail because the git project has pending changes. The dependencies of package_test.go were missing from go.sum. When running `mage testPackages` it was failing because github.com/blakesmith/ar and github.com/cavaliercoder/go-rpm were missing. --- generator/_templates/beat/{beat}/tools/tools.go | 7 ++++--- generator/_templates/metricbeat/{beat}/tools/tools.go | 7 ++++--- generator/common/Makefile | 2 -- generator/common/beatgen/beatgen.go | 10 ++++++++++ 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/generator/_templates/beat/{beat}/tools/tools.go b/generator/_templates/beat/{beat}/tools/tools.go index 9c1319194d0..1ddaba8a29d 100644 --- a/generator/_templates/beat/{beat}/tools/tools.go +++ b/generator/_templates/beat/{beat}/tools/tools.go @@ -6,12 +6,13 @@ package tools import ( + _ "github.com/blakesmith/ar" + _ "github.com/cavaliercoder/go-rpm" _ "github.com/magefile/mage" + _ "github.com/mitchellh/gox" _ "github.com/pierrre/gotestcover" _ "github.com/tsg/go-daemon" + _ "golang.org/x/lint/golint" _ "golang.org/x/tools/cmd/goimports" _ "gotest.tools/gotestsum/cmd" - - _ "github.com/mitchellh/gox" - _ "golang.org/x/lint/golint" ) diff --git a/generator/_templates/metricbeat/{beat}/tools/tools.go b/generator/_templates/metricbeat/{beat}/tools/tools.go index 9c1319194d0..1ddaba8a29d 100644 --- a/generator/_templates/metricbeat/{beat}/tools/tools.go +++ b/generator/_templates/metricbeat/{beat}/tools/tools.go @@ -6,12 +6,13 @@ package tools import ( + _ "github.com/blakesmith/ar" + _ "github.com/cavaliercoder/go-rpm" _ "github.com/magefile/mage" + _ "github.com/mitchellh/gox" _ "github.com/pierrre/gotestcover" _ "github.com/tsg/go-daemon" + _ "golang.org/x/lint/golint" _ "golang.org/x/tools/cmd/goimports" _ "gotest.tools/gotestsum/cmd" - - _ "github.com/mitchellh/gox" - _ "golang.org/x/lint/golint" ) diff --git a/generator/common/Makefile b/generator/common/Makefile index ba3eb1af477..8d82a444e84 100644 --- a/generator/common/Makefile +++ b/generator/common/Makefile @@ -22,8 +22,6 @@ test: prepare-test test-package: test cd ${BEAT_PATH} ; \ export PATH=$${GOPATH}/bin:$${PATH}; \ - go mod tidy && \ - go mod download all && \ mage package .PHONY: prepare-test diff --git a/generator/common/beatgen/beatgen.go b/generator/common/beatgen/beatgen.go index 3cb101aa625..c16b1e309ae 100644 --- a/generator/common/beatgen/beatgen.go +++ b/generator/common/beatgen/beatgen.go @@ -126,6 +126,16 @@ func Generate() error { return errors.Wrap(err, "error while getting required beats version") } + // After fully populating go.mod download the deps to set the hashes + // within the go.sum. + if err = gotool.Mod.Download(); err != nil { + return errors.Wrap(err, "failed to download go.mod deps") + } + // Finally, cleanup any formatting issues in the go.mod/go.sum. + if err = gotool.Mod.Tidy(); err != nil { + return errors.Wrap(err, "error running 'go mod tidy'") + } + mg.Deps(setup.GitInit) if cfg["type"] == "metricbeat" {