Skip to content

Commit

Permalink
Fix modified go.sum issue in beat generators (elastic#28375)
Browse files Browse the repository at this point in the history
* 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.

* Re-enable generator tests

Relates elastic#28361
  • Loading branch information
andrewkroh authored and wiwen committed Nov 1, 2021
1 parent de70210 commit 8eb103c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
3 changes: 1 addition & 2 deletions Jenkinsfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ projects:
- "auditbeat"
- "deploy/kubernetes"
- "filebeat"
# temporarly disable generator tests: https://github.com/elastic/beats/issues/28361
# - "generator"
- "generator"
- "heartbeat"
- "journalbeat"
- "libbeat"
Expand Down
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 8eb103c

Please sign in to comment.