Skip to content

Commit

Permalink
Switch to go 1.23
Browse files Browse the repository at this point in the history
Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
  • Loading branch information
saschagrunert committed Sep 12, 2024
1 parent 0790ab4 commit 5e795d2
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 22 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ linters:
# - errorlint
# - exhaustive
# - exhaustruct
# - exportloopref
# - forbidigo
# - forcetypeassert
# - funlen
Expand Down
4 changes: 2 additions & 2 deletions command/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ func TestCommandsFailure(t *testing.T) {
}

func TestEnv(t *testing.T) {
require.NoError(t, os.Setenv("ABC", "test")) // preserved
require.NoError(t, os.Setenv("FOO", "test")) // overwritten
t.Setenv("ABC", "test") // preserved
t.Setenv("FOO", "test") // overwritten
res, err := New("sh", "-c", "echo $TEST; echo $FOO; echo $ABC").
Env("TEST=123").
Env("FOO=bar").
Expand Down
2 changes: 1 addition & 1 deletion dependencies.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
dependencies:
# golangci/golangci-lint
- name: "golangci-lint"
version: 1.59.1
version: 1.61.0
refPaths:
- path: mage/golangci-lint.go
match: defaultGolangCILintVersion\s+=\s+"v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?"
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module sigs.k8s.io/release-utils

go 1.21
go 1.23

require (
github.com/blang/semver/v4 v4.0.0
Expand Down
25 changes: 13 additions & 12 deletions http/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (a *Agent) WithFailOnHTTPError(flag bool) *Agent {

// WithMaxParallel controls how many requests we do when fetching groups.
func (a *Agent) WithMaxParallel(workers int) *Agent {
//nolint:gosec // integer overflow highly unlikely
a.options.MaxParallel = uint(workers)
return a
}
Expand All @@ -139,11 +140,11 @@ func (a *Agent) Get(url string) (content []byte, err error) {
// GetRequest sends a GET request to a URL and returns the request and response.
func (a *Agent) GetRequest(url string) (response *http.Response, err error) {
logrus.Debugf("Sending GET request to %s", url)
try := 0
var try uint
for {
response, err = a.AgentImplementation.SendGetRequest(a.Client(), url)
try++
if err == nil || try >= int(a.options.Retries) {
if err == nil || try >= a.options.Retries {
return response, err
}
// Do exponential backoff...
Expand All @@ -154,7 +155,7 @@ func (a *Agent) GetRequest(url string) (response *http.Response, err error) {
}
logrus.Errorf(
"Error getting URL (will retry %d more times in %.0f secs): %s",
int(a.options.Retries)-try, waitTime, err.Error(),
a.options.Retries-try, waitTime, err.Error(),
)
time.Sleep(time.Duration(waitTime) * time.Second)
}
Expand All @@ -174,11 +175,11 @@ func (a *Agent) Post(url string, postData []byte) (content []byte, err error) {
// PostRequest sends the postData in a POST request to a URL and returns the request object.
func (a *Agent) PostRequest(url string, postData []byte) (response *http.Response, err error) {
logrus.Debugf("Sending POST request to %s", url)
try := 0
var try uint
for {
response, err = a.AgentImplementation.SendPostRequest(a.Client(), url, postData, a.options.PostContentType)
try++
if err == nil || try >= int(a.options.Retries) {
if err == nil || try >= a.options.Retries {
return response, err
}
// Do exponential backoff...
Expand All @@ -189,7 +190,7 @@ func (a *Agent) PostRequest(url string, postData []byte) (response *http.Respons
}
logrus.Errorf(
"Error getting URL (will retry %d more times in %.0f secs): %s",
int(a.options.Retries)-try, waitTime, err.Error(),
a.options.Retries-try, waitTime, err.Error(),
)
time.Sleep(time.Duration(waitTime) * time.Second)
}
Expand All @@ -209,11 +210,11 @@ func (a *Agent) Head(url string) (content []byte, err error) {
// HeadRequest sends a HEAD request to a URL and returns the request and response.
func (a *Agent) HeadRequest(url string) (response *http.Response, err error) {
logrus.Debugf("Sending HEAD request to %s", url)
try := 0
var try uint
for {
response, err = a.AgentImplementation.SendHeadRequest(a.Client(), url)
try++
if err == nil || try >= int(a.options.Retries) {
if err == nil || try >= a.options.Retries {
return response, err
}
// Do exponential backoff...
Expand All @@ -224,7 +225,7 @@ func (a *Agent) HeadRequest(url string) (response *http.Response, err error) {
}
logrus.Errorf(
"Error getting URL (will retry %d more times in %.0f secs): %s",
int(a.options.Retries)-try, waitTime, err.Error(),
a.options.Retries-try, waitTime, err.Error(),
)
time.Sleep(time.Duration(waitTime) * time.Second)
}
Expand Down Expand Up @@ -324,12 +325,12 @@ func (a *Agent) PostToWriter(w io.Writer, url string, postData []byte) error {
// and performs the requests in parallel. The number of simultaneous requests is
// controlled by options.MaxParallel.
func (a *Agent) GetRequestGroup(urls []string) ([]*http.Response, []error) {
//nolint:gosec // integer overflow highly unlikely
t := throttler.New(int(a.options.MaxParallel), len(urls))
ret := make([]*http.Response, len(urls))
errs := make([]error, len(urls))
m := sync.Mutex{}
for i := range urls {
i := i
go func(url string) {
//nolint: bodyclose // We don't close here as we're returning the response
resp, err := a.AgentImplementation.SendGetRequest(a.Client(), url)
Expand Down Expand Up @@ -360,16 +361,16 @@ func (a *Agent) PostRequestGroup(urls []string, postData [][]byte) ([]*http.Resp
// URLs and postData arrays must be equal in length. If not exit now.
if len(postData) != len(urls) {
err := errors.New("unable to perform requests, same number URLs and POST payloads required")
for i := 0; i < len(urls); i++ {
for i := range urls {
errs[i] = err
}
return ret, errs
}

//nolint:gosec // integer overflow highly unlikely
t := throttler.New(int(a.options.MaxParallel), len(urls))
m := sync.Mutex{}
for i := range urls {
i := i
go func(url string, pdata []byte) {
//nolint: bodyclose // We don't close here as we're returning the raw response
resp, err := a.AgentImplementation.SendPostRequest(
Expand Down
2 changes: 0 additions & 2 deletions http/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ func TestAgentGet(t *testing.T) {
},
},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
fake := &httpfakes.FakeAgentImplementation{}
Expand Down Expand Up @@ -418,7 +417,6 @@ func TestAgentPostRequestGroup(t *testing.T) {
{"http-error", 5, true, []string{noErrorURL, httpErrorURL, noErrorURL}, make([][]byte, 3)},
{"software-error", 5, true, []string{noErrorURL, errorURL, noErrorURL}, make([][]byte, 3)},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
// No retries as the errors are synthetic
Expand Down
2 changes: 1 addition & 1 deletion log/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (f *FileNameHook) findCaller() (file, function string, line int) {
var pc uintptr
// The maximum amount of frames to be iterated
const maxFrames = 10
for i := 0; i < maxFrames; i++ {
for i := range maxFrames {
// The amount of frames to be skipped to land at the actual caller
const skipFrames = 5
pc, file, line = caller(skipFrames + i)
Expand Down
2 changes: 1 addition & 1 deletion mage/golangci-lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import (

const (
// golangci-lint.
defaultGolangCILintVersion = "v1.59.1"
defaultGolangCILintVersion = "v1.61.0"
golangciCmd = "golangci-lint"
golangciConfig = ".golangci.yml"
golangciURLBase = "https://raw.githubusercontent.com/golangci/golangci-lint"
Expand Down
1 change: 1 addition & 0 deletions tar/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func Extract(tarFilePath, destinationPath string) error {
if err != nil {
return false, fmt.Errorf("create target file: %w", err)
}
//nolint:gosec // integer overflow highly unlikely
if err := outFile.Chmod(os.FileMode(header.Mode)); err != nil {
return false, fmt.Errorf("chmod target file: %w", err)
}
Expand Down
1 change: 0 additions & 1 deletion util/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,6 @@ func TestIsDir(t *testing.T) {
expected: false,
},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
path := tc.prepare(t)
Expand Down

0 comments on commit 5e795d2

Please sign in to comment.