mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 13:16:42 +00:00
build: run check_generate, lint, test for all modules
This commit is contained in:
parent
5af7c861c8
commit
29dedd91af
2 changed files with 73 additions and 60 deletions
95
build/ci.go
95
build/ci.go
|
|
@ -64,6 +64,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
goModules = []string{
|
||||||
|
".",
|
||||||
|
"./cmd/keeper",
|
||||||
|
}
|
||||||
|
|
||||||
// Files that end up in the geth*.zip archive.
|
// Files that end up in the geth*.zip archive.
|
||||||
gethArchiveFiles = []string{
|
gethArchiveFiles = []string{
|
||||||
"COPYING",
|
"COPYING",
|
||||||
|
|
@ -295,6 +300,7 @@ func doTest(cmdline []string) {
|
||||||
if *dlgo {
|
if *dlgo {
|
||||||
tc.Root = build.DownloadGo(csdb)
|
tc.Root = build.DownloadGo(csdb)
|
||||||
}
|
}
|
||||||
|
|
||||||
gotest := tc.Go("test")
|
gotest := tc.Go("test")
|
||||||
|
|
||||||
// CI needs a bit more time for the statetests (default 45m).
|
// CI needs a bit more time for the statetests (default 45m).
|
||||||
|
|
@ -323,11 +329,19 @@ func doTest(cmdline []string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
packages := flag.CommandLine.Args()
|
packages := flag.CommandLine.Args()
|
||||||
if len(packages) == 0 {
|
if len(packages) > 0 {
|
||||||
packages = workspacePackagePatterns()
|
|
||||||
}
|
|
||||||
gotest.Args = append(gotest.Args, packages...)
|
gotest.Args = append(gotest.Args, packages...)
|
||||||
build.MustRun(gotest)
|
build.MustRun(gotest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// No packages specified, run all tests for all modules.
|
||||||
|
gotest.Args = append(gotest.Args, ".")
|
||||||
|
for _, mod := range goModules {
|
||||||
|
test := *gotest
|
||||||
|
test.Dir = mod
|
||||||
|
build.MustRun(&test)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// downloadSpecTestFixtures downloads and extracts the execution-spec-tests fixtures.
|
// downloadSpecTestFixtures downloads and extracts the execution-spec-tests fixtures.
|
||||||
|
|
@ -364,13 +378,15 @@ func doCheckGenerate() {
|
||||||
protocPath = downloadProtoc(*cachedir)
|
protocPath = downloadProtoc(*cachedir)
|
||||||
protocGenGoPath = downloadProtocGenGo(*cachedir)
|
protocGenGoPath = downloadProtocGenGo(*cachedir)
|
||||||
)
|
)
|
||||||
c := tc.Go("generate", workspacePackagePatterns()...)
|
|
||||||
pathList := []string{filepath.Join(protocPath, "bin"), protocGenGoPath, os.Getenv("PATH")}
|
pathList := []string{filepath.Join(protocPath, "bin"), protocGenGoPath, os.Getenv("PATH")}
|
||||||
c.Env = append(c.Env, "PATH="+strings.Join(pathList, string(os.PathListSeparator)))
|
|
||||||
build.MustRun(c)
|
|
||||||
|
|
||||||
|
for _, mod := range goModules {
|
||||||
|
c := tc.Go("generate", "./...")
|
||||||
|
c.Env = append(c.Env, "PATH="+strings.Join(pathList, string(os.PathListSeparator)))
|
||||||
|
c.Dir = mod
|
||||||
|
build.MustRun(c)
|
||||||
// Check if generate file hashes have changed
|
// Check if generate file hashes have changed
|
||||||
generated, err := build.HashFolder(".", []string{"tests/testdata", "build/cache", ".git"})
|
generated, err := build.HashFolder(mod, []string{"tests/testdata", "build/cache", ".git"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error re-computing hashes: %v", err)
|
log.Fatalf("Error re-computing hashes: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -381,10 +397,16 @@ func doCheckGenerate() {
|
||||||
if len(updates) != 0 {
|
if len(updates) != 0 {
|
||||||
log.Fatal("One or more generated files were updated by running 'go generate ./...'")
|
log.Fatal("One or more generated files were updated by running 'go generate ./...'")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
fmt.Println("No stale files detected.")
|
fmt.Println("No stale files detected.")
|
||||||
|
|
||||||
// Run go mod tidy check.
|
// Run go mod tidy check.
|
||||||
build.MustRun(tc.Go("mod", "tidy", "-diff"))
|
for _, mod := range goModules {
|
||||||
|
tidy := tc.Go("mod", "tidy", "-diff")
|
||||||
|
tidy.Dir = mod
|
||||||
|
build.MustRun(tidy)
|
||||||
|
}
|
||||||
fmt.Println("No untidy module files detected.")
|
fmt.Println("No untidy module files detected.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -425,20 +447,29 @@ func doLint(cmdline []string) {
|
||||||
)
|
)
|
||||||
flag.CommandLine.Parse(cmdline)
|
flag.CommandLine.Parse(cmdline)
|
||||||
|
|
||||||
packages := flag.CommandLine.Args()
|
linter := downloadLinter(*cachedir)
|
||||||
if len(packages) == 0 {
|
linter, err := filepath.Abs(linter)
|
||||||
// Get module directories in workspace.
|
if err != nil {
|
||||||
packages = []string{"./..."}
|
log.Fatal(err)
|
||||||
modules := workspaceModules()
|
|
||||||
for _, m := range modules[1:] {
|
|
||||||
dir := strings.TrimPrefix(m, modules[0])
|
|
||||||
packages = append(packages, "."+dir+"/...")
|
|
||||||
}
|
}
|
||||||
|
config, err := filepath.Abs(".golangci.yml")
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
linter := downloadLinter(*cachedir)
|
lflags := []string{"run", "--config", config}
|
||||||
lflags := []string{"run", "--config", ".golangci.yml"}
|
packages := flag.CommandLine.Args()
|
||||||
|
if len(packages) > 0 {
|
||||||
build.MustRunCommandWithOutput(linter, append(lflags, packages...)...)
|
build.MustRunCommandWithOutput(linter, append(lflags, packages...)...)
|
||||||
|
} else {
|
||||||
|
// Run for all modules in workspace.
|
||||||
|
for _, mod := range goModules {
|
||||||
|
args := append(lflags, "./...")
|
||||||
|
lintcmd := exec.Command(linter, args...)
|
||||||
|
lintcmd.Dir = mod
|
||||||
|
build.MustRunWithOutput(lintcmd)
|
||||||
|
}
|
||||||
|
}
|
||||||
fmt.Println("You have achieved perfection.")
|
fmt.Println("You have achieved perfection.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1176,31 +1207,3 @@ func doSanityCheck() {
|
||||||
csdb := download.MustLoadChecksums("build/checksums.txt")
|
csdb := download.MustLoadChecksums("build/checksums.txt")
|
||||||
csdb.DownloadAndVerifyAll()
|
csdb.DownloadAndVerifyAll()
|
||||||
}
|
}
|
||||||
|
|
||||||
// workspaceModules lists the module paths in the current work.
|
|
||||||
func workspaceModules() []string {
|
|
||||||
listing, err := new(build.GoToolchain).Go("list", "-m").Output()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("go list failed:", err)
|
|
||||||
}
|
|
||||||
var modules []string
|
|
||||||
for _, m := range bytes.Split(listing, []byte("\n")) {
|
|
||||||
m = bytes.TrimSpace(m)
|
|
||||||
if len(m) > 0 {
|
|
||||||
modules = append(modules, string(m))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(modules) == 0 {
|
|
||||||
panic("no modules found")
|
|
||||||
}
|
|
||||||
return modules
|
|
||||||
}
|
|
||||||
|
|
||||||
func workspacePackagePatterns() []string {
|
|
||||||
modules := workspaceModules()
|
|
||||||
patterns := make([]string, len(modules))
|
|
||||||
for i, m := range modules {
|
|
||||||
patterns[i] = m + "/..."
|
|
||||||
}
|
|
||||||
return patterns
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -39,6 +39,9 @@ var DryRunFlag = flag.Bool("n", false, "dry run, don't execute commands")
|
||||||
// MustRun executes the given command and exits the host process for
|
// MustRun executes the given command and exits the host process for
|
||||||
// any error.
|
// any error.
|
||||||
func MustRun(cmd *exec.Cmd) {
|
func MustRun(cmd *exec.Cmd) {
|
||||||
|
if cmd.Dir != "" && cmd.Dir != "." {
|
||||||
|
fmt.Printf("(in %s) ", cmd.Dir)
|
||||||
|
}
|
||||||
fmt.Println(">>>", printArgs(cmd.Args))
|
fmt.Println(">>>", printArgs(cmd.Args))
|
||||||
if !*DryRunFlag {
|
if !*DryRunFlag {
|
||||||
cmd.Stderr = os.Stderr
|
cmd.Stderr = os.Stderr
|
||||||
|
|
@ -71,6 +74,13 @@ func MustRunCommand(cmd string, args ...string) {
|
||||||
// printed while it runs. This is useful for CI builds where the process will be stopped
|
// printed while it runs. This is useful for CI builds where the process will be stopped
|
||||||
// when there is no output.
|
// when there is no output.
|
||||||
func MustRunCommandWithOutput(cmd string, args ...string) {
|
func MustRunCommandWithOutput(cmd string, args ...string) {
|
||||||
|
MustRunWithOutput(exec.Command(cmd, args...))
|
||||||
|
}
|
||||||
|
|
||||||
|
// MustRunWithOutput runs the given command, and ensures that some output will be printed
|
||||||
|
// while it runs. This is useful for CI builds where the process will be stopped when
|
||||||
|
// there is no output.
|
||||||
|
func MustRunWithOutput(cmd *exec.Cmd) {
|
||||||
interval := time.NewTicker(time.Minute)
|
interval := time.NewTicker(time.Minute)
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
defer interval.Stop()
|
defer interval.Stop()
|
||||||
|
|
@ -85,7 +95,7 @@ func MustRunCommandWithOutput(cmd string, args ...string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
MustRun(exec.Command(cmd, args...))
|
MustRun(cmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
var warnedAboutGit bool
|
var warnedAboutGit bool
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue