Skip to content

Commit 105709b

Browse files
authored
Merge pull request #2118 from CortexFoundation/dev
build: run 'go mod tidy' check as part of lint
2 parents ec25014 + d795fc6 commit 105709b

File tree

14 files changed

+116
-37
lines changed

14 files changed

+116
-37
lines changed

build/ci.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,11 @@ package main
4242
import (
4343
"bufio"
4444
"bytes"
45+
"crypto/sha256"
4546
"encoding/base64"
4647
"flag"
4748
"fmt"
49+
"io"
4850
"log"
4951
"os"
5052
"os/exec"
@@ -353,6 +355,8 @@ func doLint(cmdline []string) {
353355
linter := downloadLinter(*cachedir)
354356
lflags := []string{"run", "--config", ".golangci.yml"}
355357
build.MustRunCommandWithOutput(linter, append(lflags, packages...)...)
358+
359+
doGoModTidy()
356360
fmt.Println("You have achieved perfection.")
357361
}
358362

@@ -1290,3 +1294,53 @@ func doPurge(cmdline []string) {
12901294
log.Fatal(err)
12911295
}
12921296
}
1297+
1298+
// hashSourceFiles iterates the provided set of filepaths (relative to the top-level geth project directory)
1299+
// computing the hash of each file.
1300+
func hashSourceFiles(files []string) (map[string]common.Hash, error) {
1301+
res := make(map[string]common.Hash)
1302+
for _, filePath := range files {
1303+
f, err := os.OpenFile(filePath, os.O_RDONLY, 0666)
1304+
if err != nil {
1305+
return nil, err
1306+
}
1307+
hasher := sha256.New()
1308+
if _, err := io.Copy(hasher, f); err != nil {
1309+
return nil, err
1310+
}
1311+
res[filePath] = common.Hash(hasher.Sum(nil))
1312+
}
1313+
return res, nil
1314+
}
1315+
1316+
// compareHashedFilesets compares two maps (key is relative file path to top-level geth directory, value is its hash)
1317+
// and returns the list of file paths whose hashes differed.
1318+
func compareHashedFilesets(preHashes map[string]common.Hash, postHashes map[string]common.Hash) []string {
1319+
updates := []string{}
1320+
for path, postHash := range postHashes {
1321+
preHash, ok := preHashes[path]
1322+
if !ok || preHash != postHash {
1323+
updates = append(updates, path)
1324+
}
1325+
}
1326+
return updates
1327+
}
1328+
1329+
func doGoModTidy() {
1330+
targetFiles := []string{"go.mod", "go.sum"}
1331+
preHashes, err := hashSourceFiles(targetFiles)
1332+
if err != nil {
1333+
log.Fatal("failed to hash go.mod/go.sum", "err", err)
1334+
}
1335+
tc := new(build.GoToolchain)
1336+
c := tc.Go("mod", "tidy")
1337+
build.MustRun(c)
1338+
postHashes, err := hashSourceFiles(targetFiles)
1339+
updates := compareHashedFilesets(preHashes, postHashes)
1340+
for _, updatedFile := range updates {
1341+
fmt.Fprintf(os.Stderr, "changed file %s\n", updatedFile)
1342+
}
1343+
if len(updates) != 0 {
1344+
log.Fatal("go.sum and/or go.mod were updated by running 'go mod tidy'")
1345+
}
1346+
}

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.4.0
77
github.com/CortexFoundation/inference v1.0.2-0.20230307032835-9197d586a4e8
88
github.com/CortexFoundation/statik v0.0.0-20210315012922-8bb8a7b5dc66
9-
github.com/CortexFoundation/torrentfs v1.0.68-0.20240811180800-b0f9325d515a
9+
github.com/CortexFoundation/torrentfs v1.0.68-0.20240813135702-315fce92764b
1010
github.com/VictoriaMetrics/fastcache v1.12.2
1111
github.com/arsham/figurine v1.3.0
1212
github.com/aws/aws-sdk-go-v2 v1.30.3
@@ -98,7 +98,7 @@ require (
9898
github.com/anacrolix/multiless v0.3.1-0.20221221005021-2d12701f83f7 // indirect
9999
github.com/anacrolix/stm v0.5.0 // indirect
100100
github.com/anacrolix/sync v0.5.1 // indirect
101-
github.com/anacrolix/torrent v1.56.2-0.20240810044131-b7b97a6666eb // indirect
101+
github.com/anacrolix/torrent v1.56.2-0.20240813010934-f4711825e84e // indirect
102102
github.com/anacrolix/upnp v0.1.4 // indirect
103103
github.com/anacrolix/utp v0.2.0 // indirect
104104
github.com/antlabs/stl v0.0.2 // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ github.com/CortexFoundation/statik v0.0.0-20210315012922-8bb8a7b5dc66/go.mod h1:
7070
github.com/CortexFoundation/torrentfs v1.0.13-0.20200623060705-ce027f43f2f8/go.mod h1:Ma+tGhPPvz4CEZHaqEJQMOEGOfHeQBiAoNd1zyc/w3Q=
7171
github.com/CortexFoundation/torrentfs v1.0.14-0.20200703071639-3fcabcabf274/go.mod h1:qnb3YlIJmuetVBtC6Lsejr0Xru+1DNmDCdTqnwy7lhk=
7272
github.com/CortexFoundation/torrentfs v1.0.20-0.20200810031954-d36d26f82fcc/go.mod h1:N5BsicP5ynjXIi/Npl/SRzlJ630n1PJV2sRj0Z0t2HA=
73-
github.com/CortexFoundation/torrentfs v1.0.68-0.20240811180800-b0f9325d515a h1:P6r8eX+rAHMycl2IOcTBSM4Si2sTiteEdsgN7K0O4wI=
74-
github.com/CortexFoundation/torrentfs v1.0.68-0.20240811180800-b0f9325d515a/go.mod h1:85ab5Vf0VV/dnGSmscQWN1Ldkz6IQIF3nluqxcnOA9A=
73+
github.com/CortexFoundation/torrentfs v1.0.68-0.20240813135702-315fce92764b h1:NDEYatjLRJw5rs6mK3dAB6rzpCXBTwOfrWPIWUqJOi4=
74+
github.com/CortexFoundation/torrentfs v1.0.68-0.20240813135702-315fce92764b/go.mod h1:iez5s4nITZbagFXWdqP38eEyM4bpACDlX1dB7js2FLM=
7575
github.com/CortexFoundation/wormhole v0.0.2-0.20240624201423-33e289eb7662 h1:rmM5WDx5UX7V4LF1D8LtAOPDzcCKulpZ++NkP8/+Ook=
7676
github.com/CortexFoundation/wormhole v0.0.2-0.20240624201423-33e289eb7662/go.mod h1:ipzmPabDgzYKUbXkGVe2gTkBEp+MsDx6pXGiuYzmP6s=
7777
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
@@ -216,8 +216,8 @@ github.com/anacrolix/torrent v1.15.0/go.mod h1:MFc6KcbpAyfwGqOyRkdarUK9QnKA/FkVg
216216
github.com/anacrolix/torrent v1.15.1-0.20200504230043-cc5d2abe18e5/go.mod h1:QlOfgrCz5kbvhOz8M58dUwHY5SfZ9VbIvReZ0z0MdIk=
217217
github.com/anacrolix/torrent v1.15.1-0.20200619022403-dd51e99b88cc/go.mod h1:wuopQPC5+/M+zHYvhcA2vp5UCTm9rUc+VqjyBa882Q8=
218218
github.com/anacrolix/torrent v1.15.1-0.20200715061614-dd906f8fa72e/go.mod h1:XWo/fJN1oKgcjgxM+pUZpvalHfqHDs27BY5mBZjIQWo=
219-
github.com/anacrolix/torrent v1.56.2-0.20240810044131-b7b97a6666eb h1:5ucgBdrVFSWm+RQntPvMSN9fGG8ZQFam9QPL7MoOHQU=
220-
github.com/anacrolix/torrent v1.56.2-0.20240810044131-b7b97a6666eb/go.mod h1:EWjXWEwDpaeG07SFdVWIMgknrjSuL8rRF1BbEYZsC+I=
219+
github.com/anacrolix/torrent v1.56.2-0.20240813010934-f4711825e84e h1:gfu86Ozd6rvq4mwSgy1s6SRlS8UeeCORKoqnXvlXtY0=
220+
github.com/anacrolix/torrent v1.56.2-0.20240813010934-f4711825e84e/go.mod h1:m6Jl1mdUG3wcapLuvn8ZwENi49DUCmiacom6plQ5rcI=
221221
github.com/anacrolix/upnp v0.1.1/go.mod h1:LXsbsp5h+WGN7YR+0A7iVXm5BL1LYryDev1zuJMWYQo=
222222
github.com/anacrolix/upnp v0.1.2-0.20200416075019-5e9378ed1425/go.mod h1:Pz94W3kl8rf+wxH3IbCa9Sq+DTJr8OSbV2Q3/y51vYs=
223223
github.com/anacrolix/upnp v0.1.4 h1:+2t2KA6QOhm/49zeNyeVwDu1ZYS9dB9wfxyVvh/wk7U=

vendor/github.com/anacrolix/torrent/client.go

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/anacrolix/torrent/global.go

Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/anacrolix/torrent/mse/ctxrw.go renamed to vendor/github.com/anacrolix/torrent/internal/ctxrw/ctxrw.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/anacrolix/torrent/mse/mse.go

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/anacrolix/torrent/peer.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/anacrolix/torrent/peer_protocol/handshake.go

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/anacrolix/torrent/torrent.go

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)