forked from forks/go-ethereum
build: simplify go mod tidy check (#31266)
This changes the go mod tidy check to use the go mod tidy -diff command, removing the custom diffing for go.mod. The check for go.mod/go.sum is now performed in the check_generate action. Also included is a change where check_generate and check_baddeps will now run on the GitHub Actions lint step. --------- Co-authored-by: Felix Lange <fjl@twurst.com>
This commit is contained in:
parent
fa16d497bc
commit
f005d95b55
3 changed files with 8 additions and 23 deletions
2
.github/workflows/go.yml
vendored
2
.github/workflows/go.yml
vendored
|
|
@ -29,7 +29,7 @@ jobs:
|
||||||
- name: Run linters
|
- name: Run linters
|
||||||
run: |
|
run: |
|
||||||
go run build/ci.go lint
|
go run build/ci.go lint
|
||||||
go run build/ci.go check_tidy
|
go run build/ci.go check_generate
|
||||||
go run build/ci.go check_baddeps
|
go run build/ci.go check_baddeps
|
||||||
|
|
||||||
build:
|
build:
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@ for:
|
||||||
- image: Ubuntu
|
- image: Ubuntu
|
||||||
build_script:
|
build_script:
|
||||||
- go run build/ci.go lint
|
- go run build/ci.go lint
|
||||||
- go run build/ci.go check_tidy
|
|
||||||
- go run build/ci.go check_generate
|
- go run build/ci.go check_generate
|
||||||
- go run build/ci.go check_baddeps
|
- go run build/ci.go check_baddeps
|
||||||
- go run build/ci.go install -dlgo
|
- go run build/ci.go install -dlgo
|
||||||
|
|
|
||||||
28
build/ci.go
28
build/ci.go
|
|
@ -25,8 +25,7 @@ Usage: go run build/ci.go <command> <command flags/arguments>
|
||||||
Available commands are:
|
Available commands are:
|
||||||
|
|
||||||
lint -- runs certain pre-selected linters
|
lint -- runs certain pre-selected linters
|
||||||
check_tidy -- verifies that everything is 'go mod tidy'-ed
|
check_generate -- verifies that 'go generate' and 'go mod tidy' do not produce changes
|
||||||
check_generate -- verifies that everything is 'go generate'-ed
|
|
||||||
check_baddeps -- verifies that certain dependencies are avoided
|
check_baddeps -- verifies that certain dependencies are avoided
|
||||||
|
|
||||||
install [ -arch architecture ] [ -cc compiler ] [ packages... ] -- builds packages and executables
|
install [ -arch architecture ] [ -cc compiler ] [ packages... ] -- builds packages and executables
|
||||||
|
|
@ -155,8 +154,6 @@ func main() {
|
||||||
doTest(os.Args[2:])
|
doTest(os.Args[2:])
|
||||||
case "lint":
|
case "lint":
|
||||||
doLint(os.Args[2:])
|
doLint(os.Args[2:])
|
||||||
case "check_tidy":
|
|
||||||
doCheckTidy()
|
|
||||||
case "check_generate":
|
case "check_generate":
|
||||||
doCheckGenerate()
|
doCheckGenerate()
|
||||||
case "check_baddeps":
|
case "check_baddeps":
|
||||||
|
|
@ -352,22 +349,6 @@ func downloadSpecTestFixtures(csdb *build.ChecksumDB, cachedir string) string {
|
||||||
|
|
||||||
// doCheckTidy assets that the Go modules files are tidied already.
|
// doCheckTidy assets that the Go modules files are tidied already.
|
||||||
func doCheckTidy() {
|
func doCheckTidy() {
|
||||||
targets := []string{"go.mod", "go.sum"}
|
|
||||||
|
|
||||||
hashes, err := build.HashFiles(targets)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("failed to hash go.mod/go.sum: %v", err)
|
|
||||||
}
|
|
||||||
build.MustRun(new(build.GoToolchain).Go("mod", "tidy"))
|
|
||||||
|
|
||||||
tidied, err := build.HashFiles(targets)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("failed to rehash go.mod/go.sum: %v", err)
|
|
||||||
}
|
|
||||||
if updates := build.DiffHashes(hashes, tidied); len(updates) > 0 {
|
|
||||||
log.Fatalf("files changed on running 'go mod tidy': %v", updates)
|
|
||||||
}
|
|
||||||
fmt.Println("No untidy module files detected.")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// doCheckGenerate ensures that re-generating generated files does not cause
|
// doCheckGenerate ensures that re-generating generated files does not cause
|
||||||
|
|
@ -375,6 +356,7 @@ func doCheckTidy() {
|
||||||
func doCheckGenerate() {
|
func doCheckGenerate() {
|
||||||
var (
|
var (
|
||||||
cachedir = flag.String("cachedir", "./build/cache", "directory for caching binaries.")
|
cachedir = flag.String("cachedir", "./build/cache", "directory for caching binaries.")
|
||||||
|
tc = new(build.GoToolchain)
|
||||||
)
|
)
|
||||||
// Compute the origin hashes of all the files
|
// Compute the origin hashes of all the files
|
||||||
var hashes map[string][32]byte
|
var hashes map[string][32]byte
|
||||||
|
|
@ -389,7 +371,7 @@ func doCheckGenerate() {
|
||||||
protocPath = downloadProtoc(*cachedir)
|
protocPath = downloadProtoc(*cachedir)
|
||||||
protocGenGoPath = downloadProtocGenGo(*cachedir)
|
protocGenGoPath = downloadProtocGenGo(*cachedir)
|
||||||
)
|
)
|
||||||
c := new(build.GoToolchain).Go("generate", "./...")
|
c := tc.Go("generate", "./...")
|
||||||
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)))
|
c.Env = append(c.Env, "PATH="+strings.Join(pathList, string(os.PathListSeparator)))
|
||||||
build.MustRun(c)
|
build.MustRun(c)
|
||||||
|
|
@ -407,6 +389,10 @@ func doCheckGenerate() {
|
||||||
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.
|
||||||
|
build.MustRun(tc.Go("mod", "tidy", "-diff"))
|
||||||
|
fmt.Println("No untidy module files detected.")
|
||||||
}
|
}
|
||||||
|
|
||||||
// doCheckBadDeps verifies whether certain unintended dependencies between some
|
// doCheckBadDeps verifies whether certain unintended dependencies between some
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue