• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kubernetes-sigs / kubebuilder / 14345918131

09 Apr 2025 12:02AM UTC coverage: 71.57%. Remained the same
14345918131

Pull #4772

github

web-flow
:seedling: Bump golang.org/x/tools from 0.31.0 to 0.32.0

Bumps [golang.org/x/tools](https://github.com/golang/tools) from 0.31.0 to 0.32.0.
- [Release notes](https://github.com/golang/tools/releases)
- [Commits](https://github.com/golang/tools/compare/v0.31.0...v0.32.0)

---
updated-dependencies:
- dependency-name: golang.org/x/tools
  dependency-version: 0.32.0
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Pull Request #4772: :seedling: Bump golang.org/x/tools from 0.31.0 to 0.32.0

2311 of 3229 relevant lines covered (71.57%)

16.53 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.75
/pkg/plugins/golang/go_version.go
1
/*
2
Copyright 2018 The Kubernetes Authors.
3

4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7

8
    http://www.apache.org/licenses/LICENSE-2.0
9

10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16

17
package golang
18

19
import (
20
        "fmt"
21
        "os/exec"
22
        "regexp"
23
        "strconv"
24
        "strings"
25
)
26

27
const (
28
        goVerPattern = `^go(?P<major>[0-9]+)\.(?P<minor>[0-9]+)(?:\.(?P<patch>[0-9]+)|(?P<pre>(?:alpha|beta|rc)[0-9]+))?$`
29
)
30

31
var goVerRegexp = regexp.MustCompile(goVerPattern)
32

33
// GoVersion describes a Go version.
34
type GoVersion struct {
35
        major, minor, patch int
36
        prerelease          string
37
}
38

39
func (v GoVersion) String() string {
10✔
40
        switch {
10✔
41
        case v.patch != 0:
×
42
                return fmt.Sprintf("go%d.%d.%d", v.major, v.minor, v.patch)
×
43
        case v.prerelease != "":
5✔
44
                return fmt.Sprintf("go%d.%d%s", v.major, v.minor, v.prerelease)
5✔
45
        }
46
        return fmt.Sprintf("go%d.%d", v.major, v.minor)
5✔
47
}
48

49
// MustParse will panic if verStr does not match the expected Go version string spec.
50
func MustParse(verStr string) (v GoVersion) {
158✔
51
        if err := v.parse(verStr); err != nil {
158✔
52
                panic(err)
×
53
        }
54
        return v
158✔
55
}
56

57
func (v *GoVersion) parse(verStr string) error {
248✔
58
        m := goVerRegexp.FindStringSubmatch(verStr)
248✔
59
        if m == nil {
256✔
60
                return fmt.Errorf("invalid version string")
8✔
61
        }
8✔
62

63
        var err error
240✔
64

240✔
65
        v.major, err = strconv.Atoi(m[1])
240✔
66
        if err != nil {
240✔
67
                return fmt.Errorf("error parsing major version %q: %w", m[1], err)
×
68
        }
×
69

70
        v.minor, err = strconv.Atoi(m[2])
240✔
71
        if err != nil {
240✔
72
                return fmt.Errorf("error parsing minor version %q: %w", m[2], err)
×
73
        }
×
74

75
        if m[3] != "" {
300✔
76
                v.patch, err = strconv.Atoi(m[3])
60✔
77
                if err != nil {
60✔
78
                        return fmt.Errorf("error parsing patch version %q: %w", m[2], err)
×
79
                }
×
80
        }
81

82
        v.prerelease = m[4]
240✔
83

240✔
84
        return nil
240✔
85
}
86

87
// Compare returns -1, 0, or 1 if v < other, v == other, or v > other, respectively.
88
func (v GoVersion) Compare(other GoVersion) int {
193✔
89
        if v.major > other.major {
198✔
90
                return 1
5✔
91
        }
5✔
92
        if v.major < other.major {
269✔
93
                return -1
81✔
94
        }
81✔
95

96
        if v.minor > other.minor {
165✔
97
                return 1
58✔
98
        }
58✔
99
        if v.minor < other.minor {
56✔
100
                return -1
7✔
101
        }
7✔
102

103
        if v.patch > other.patch {
61✔
104
                return 1
19✔
105
        }
19✔
106
        if v.patch < other.patch {
25✔
107
                return -1
2✔
108
        }
2✔
109

110
        if v.prerelease == other.prerelease {
23✔
111
                return 0
2✔
112
        }
2✔
113
        if v.prerelease == "" {
23✔
114
                return 1
4✔
115
        }
4✔
116
        if other.prerelease == "" {
19✔
117
                return -1
4✔
118
        }
4✔
119
        if v.prerelease > other.prerelease {
16✔
120
                return 1
5✔
121
        }
5✔
122
        return -1
6✔
123
}
124

125
// ValidateGoVersion verifies that Go is installed and the current go version is supported by a plugin.
126
func ValidateGoVersion(minVersion, maxVersion GoVersion) error {
×
127
        err := fetchAndCheckGoVersion(minVersion, maxVersion)
×
128
        if err != nil {
×
129
                return fmt.Errorf("you can skip this check using the --skip-go-version-check flag: %w", err)
×
130
        }
×
131
        return nil
×
132
}
133

134
func fetchAndCheckGoVersion(minVersion, maxVersion GoVersion) error {
×
135
        cmd := exec.Command("go", "version")
×
136
        out, err := cmd.Output()
×
137
        if err != nil {
×
138
                return fmt.Errorf("failed to retrieve 'go version': %v", string(out))
×
139
        }
×
140

141
        split := strings.Split(string(out), " ")
×
142
        if len(split) < 3 {
×
143
                return fmt.Errorf("found invalid Go version: %q", string(out))
×
144
        }
×
145
        goVer := split[2]
×
146
        if err := checkGoVersion(goVer, minVersion, maxVersion); err != nil {
×
147
                return fmt.Errorf("go version %q is incompatible: %w", goVer, err)
×
148
        }
×
149
        return nil
×
150
}
151

152
func checkGoVersion(verStr string, minVersion, maxVersion GoVersion) error {
78✔
153
        var version GoVersion
78✔
154
        if err := version.parse(verStr); err != nil {
79✔
155
                return err
1✔
156
        }
1✔
157

158
        if version.Compare(minVersion) < 0 || version.Compare(maxVersion) >= 0 {
82✔
159
                return fmt.Errorf("plugin requires %q <= version < %q", minVersion, maxVersion)
5✔
160
        }
5✔
161

162
        return nil
72✔
163
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc