Skip to content

Commit 8e8a5cf

Browse files
Upgrade golang v1.23 (kubernetes-sigs#350)
* chore: update go v1.23 in go.mod * chore: update go v1.23 in hack/tools/go.mod * chore: update go v1.23 in site/go.mod * chore(site): update google/docsy * chore: update go v1.23 in .go-version * chore: udpate golangci-lint v1.62.2 * wip(lint): fix lint errors * fix(lint): deprecate ast.NewPackage * chore: update hugo v0.140.0
1 parent 1d2c3b9 commit 8e8a5cf

File tree

24 files changed

+561
-478
lines changed

24 files changed

+561
-478
lines changed

.go-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.21.0
1+
1.23.0

cmd/checkconfig/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1526,7 +1526,7 @@ func validateRequiredJobAnnotations(a []string, c config.JobConfig) error {
15261526
var errs []error
15271527
for _, annotation := range annotations {
15281528
if _, ok := job.Annotations[annotation]; !ok {
1529-
errs = append(errs, fmt.Errorf(annotation))
1529+
errs = append(errs, fmt.Errorf("%s", annotation))
15301530
}
15311531
}
15321532
return utilerrors.NewAggregate(errs)

cmd/peribolos/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,7 +1287,7 @@ func configureTeamMembers(client teamMembersClient, orgName string, gt github.Te
12871287
if err != nil {
12881288
// Augment the error with the operation we attempted so that the error makes sense after return
12891289
err = fmt.Errorf("UpdateTeamMembership(%s(%s), %s, %t) failed: %w", gt.Slug, gt.Name, user, super, err)
1290-
logrus.Warnf(err.Error())
1290+
logrus.Warnf("%s", err.Error())
12911291
} else if tm.State == github.StatePending {
12921292
logrus.Infof("Invited %s to %s(%s) as a %s", user, gt.Slug, gt.Name, role)
12931293
} else {
@@ -1301,7 +1301,7 @@ func configureTeamMembers(client teamMembersClient, orgName string, gt github.Te
13011301
if err != nil {
13021302
// Augment the error with the operation we attempted so that the error makes sense after return
13031303
err = fmt.Errorf("RemoveTeamMembership(%s(%s), %s) failed: %w", gt.Slug, gt.Name, user, err)
1304-
logrus.Warnf(err.Error())
1304+
logrus.Warnf("%s", err.Error())
13051305
} else {
13061306
logrus.Infof("Removed %s from team %s(%s)", user, gt.Slug, gt.Name)
13071307
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module sigs.k8s.io/prow
22

3-
go 1.22.3
3+
go 1.23
44

55
require (
66
cloud.google.com/go/cloudbuild v1.16.5

hack/gen-prow-documented/main.go

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,14 @@ limitations under the License.
1717
package main
1818

1919
import (
20+
"errors"
2021
"flag"
2122
"fmt"
2223
"os"
2324
"path"
2425
"path/filepath"
26+
"runtime/debug"
27+
"strings"
2528

2629
"github.com/sirupsen/logrus"
2730
"sigs.k8s.io/prow/pkg/config"
@@ -58,7 +61,7 @@ type genConfig struct {
5861
out string
5962
}
6063

61-
func (g *genConfig) gen(rootDir string) error {
64+
func (g *genConfig) gen(rootDir string, importPathResolver genyaml.ImportPathResolver) error {
6265
var inputFiles []string
6366
for _, goGlob := range g.in {
6467
ifs, err := filepath.Glob(path.Join(rootDir, goGlob))
@@ -68,7 +71,7 @@ func (g *genConfig) gen(rootDir string) error {
6871
inputFiles = append(inputFiles, ifs...)
6972
}
7073

71-
commentMap, err := genyaml.NewCommentMap(nil, inputFiles...)
74+
commentMap, err := genyaml.NewCommentMap(importPathResolver, nil, inputFiles...)
7275
if err != nil {
7376
return fmt.Errorf("failed to construct commentMap: %w", err)
7477
}
@@ -82,12 +85,37 @@ func (g *genConfig) gen(rootDir string) error {
8285
return nil
8386
}
8487

88+
func importPathResolverFunc(root string) (genyaml.ImportPathResolver, error) {
89+
info, ok := debug.ReadBuildInfo()
90+
if !ok {
91+
return nil, errors.New("module support needed")
92+
}
93+
modName := info.Main.Path
94+
resolved := make(map[string]string)
95+
96+
return func(dir string) (string, error) {
97+
if importPath, ok := resolved[dir]; ok {
98+
return importPath, nil
99+
}
100+
packageName := strings.TrimPrefix(dir, root)
101+
importPath := path.Join(modName, packageName)
102+
resolved[dir] = importPath
103+
return importPath, nil
104+
}, nil
105+
}
106+
85107
func main() {
86108
rootDir := flag.String("root-dir", defaultRootDir, "Repo root dir.")
87109
flag.Parse()
88110

111+
importPathResolver, err := importPathResolverFunc(*rootDir)
112+
if err != nil {
113+
logrus.WithError(err).Error("Failed to create the import path resolver.")
114+
os.Exit(1)
115+
}
116+
89117
for _, g := range genConfigs {
90-
if err := g.gen(*rootDir); err != nil {
118+
if err := g.gen(*rootDir, importPathResolver); err != nil {
91119
logrus.WithError(err).WithField("fixture", g.out).Error("Failed generating.")
92120
os.Exit(1)
93121
}

hack/gen-prow-documented/main_test.go

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ skip_report: true
6161
tc := tc
6262
t.Run(tc.name, func(t *testing.T) {
6363
tmpDir := t.TempDir()
64-
in, out := tc.name+".in", tc.name+".out"
64+
in, out := tc.name+".go", tc.name+".yaml"
6565
if err := os.WriteFile(path.Join(tmpDir, in), tc.rawContents, 0644); err != nil {
6666
t.Fatalf("Failed creating input: %v", err)
6767
}
@@ -73,7 +73,9 @@ skip_report: true
7373
out: out,
7474
}
7575

76-
if err := g.gen(tmpDir); err != nil {
76+
if err := g.gen(tmpDir, func(dir string) (string, error) {
77+
return "fake", nil
78+
}); err != nil {
7779
t.Fatalf("Got unexpected error: %v", err)
7880
}
7981

@@ -87,3 +89,41 @@ skip_report: true
8789
})
8890
}
8991
}
92+
93+
func TestImportPathResolver(t *testing.T) {
94+
for _, testCase := range []struct {
95+
name string
96+
root string
97+
dir string
98+
wantImportPath string
99+
}{
100+
{
101+
name: "Resolve successfully",
102+
root: "/usr/src/prow",
103+
dir: "/usr/src/prow/cmd/deck",
104+
wantImportPath: "sigs.k8s.io/prow/cmd/deck",
105+
},
106+
{
107+
name: "Root with leading slash",
108+
root: "/usr/src/prow/",
109+
dir: "/usr/src/prow/cmd/deck",
110+
wantImportPath: "sigs.k8s.io/prow/cmd/deck",
111+
},
112+
} {
113+
t.Run(testCase.name, func(tt *testing.T) {
114+
resolver, err := importPathResolverFunc(testCase.root)
115+
if err != nil {
116+
tt.Fatalf("Failed to create resolver func: %s", err)
117+
}
118+
119+
importPath, err := resolver(testCase.dir)
120+
if err != nil {
121+
tt.Fatalf("Failed to resolve %s: %s", testCase.dir, err)
122+
}
123+
124+
if testCase.wantImportPath != importPath {
125+
tt.Fatalf("Expected %s but got %s", testCase.wantImportPath, importPath)
126+
}
127+
})
128+
}
129+
}

0 commit comments

Comments
 (0)