Skip to content

Commit

Permalink
Fix modified go.sum issue in beat generators
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
andrewkroh committed Oct 12, 2021
1 parent 058c405 commit a851b7c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
7 changes: 4 additions & 3 deletions generator/_templates/beat/{beat}/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
7 changes: 4 additions & 3 deletions generator/_templates/metricbeat/{beat}/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
2 changes: 0 additions & 2 deletions generator/common/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions generator/common/beatgen/beatgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit a851b7c

Please sign in to comment.