-
Notifications
You must be signed in to change notification settings - Fork 198
Expand file tree
/
Copy pathmain.go
More file actions
88 lines (79 loc) · 2.33 KB
/
Copy pathmain.go
File metadata and controls
88 lines (79 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
"golang.org/x/mod/modfile"
)
// pinnedVersions is the source of truth for dependencies that must not be
// accidentally upgraded. Each entry maps a module path to the exact version
// that should appear in go.mod.
//
// To update a pinned dependency, change both go.mod, this map AND
// the Renovate package rules in renovate.json that skips automated updates for that dependency.
var pinnedVersions = map[string]string{
"github.com/aws/aws-sdk-go-v2/feature/s3/manager": "v1.21.0",
"github.com/tikv/pd/client": "v0.0.0-20251229071808-6173d50c004c",
}
func main() {
_, thisFile, _, ok := runtime.Caller(0)
if !ok {
fmt.Fprintln(os.Stderr, "failed to determine source file path")
os.Exit(1)
}
goModPath := filepath.Join(filepath.Dir(thisFile), "..", "..", "go.mod")
data, err := os.ReadFile(goModPath)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to read go.mod: %v\n", err)
os.Exit(1)
}
f, err := modfile.Parse("go.mod", data, nil)
if err != nil {
fmt.Fprintf(os.Stderr, "failed to parse go.mod: %v\n", err)
os.Exit(1)
}
found := make(map[string]string)
for _, req := range f.Require {
for _, comment := range req.Syntax.Suffix {
if strings.Contains(comment.Token, "PINNED") {
found[req.Mod.Path] = req.Mod.Version
break
}
}
}
for _, rep := range f.Replace {
for _, comment := range rep.Syntax.Suffix {
if strings.Contains(comment.Token, "PINNED") {
found[rep.Old.Path] = rep.New.Version
break
}
}
}
failed := false
for mod, pinnedVer := range pinnedVersions {
ver, ok := found[mod]
if !ok {
fmt.Fprintf(os.Stderr, "pinned module %s (expected %s) not found with"+
" PINNED comment in go.mod — was the comment removed?\n", mod, pinnedVer)
failed = true
continue
}
if ver != pinnedVer {
fmt.Fprintf(os.Stderr, "pinned module %s: go.mod has %s, expected %s —"+
" if this upgrade is intentional, update pinnedVersions in cmd/check_pinned_versions/main.go\n", mod, ver, pinnedVer)
failed = true
}
}
for mod := range found {
if _, ok := pinnedVersions[mod]; !ok {
fmt.Fprintf(os.Stderr, "module %s has a PINNED comment in go.mod but is"+
" not in pinnedVersions — add it to cmd/check_pinned_versions/main.go\n", mod)
failed = true
}
}
if failed {
os.Exit(1)
}
}