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

kubernetes-sigs / kubebuilder / 10361131150

12 Aug 2024 11:52PM UTC coverage: 81.773%. Remained the same
10361131150

Pull #4073

github

web-flow
:seedling: Bump golang.org/x/tools from 0.23.0 to 0.24.0

Bumps [golang.org/x/tools](https://github.com/golang/tools) from 0.23.0 to 0.24.0.
- [Release notes](https://github.com/golang/tools/releases)
- [Commits](https://github.com/golang/tools/compare/v0.23.0...v0.24.0)

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

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

2288 of 2798 relevant lines covered (81.77%)

15.57 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 (
32
        goVerRegexp = regexp.MustCompile(goVerPattern)
33
)
34

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

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

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

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

65
        var err error
84✔
66

84✔
67
        v.major, err = strconv.Atoi(m[1])
84✔
68
        if err != nil {
84✔
69
                return fmt.Errorf("error parsing major version '%s': %s", m[1], err)
×
70
        }
×
71

72
        v.minor, err = strconv.Atoi(m[2])
84✔
73
        if err != nil {
84✔
74
                return fmt.Errorf("error parsing minor version '%s': %s", m[2], err)
×
75
        }
×
76

77
        if m[3] != "" {
144✔
78
                v.patch, err = strconv.Atoi(m[3])
60✔
79
                if err != nil {
60✔
80
                        return fmt.Errorf("error parsing patch version '%s': %s", m[2], err)
×
81
                }
×
82
        }
83

84
        v.prerelease = m[4]
84✔
85

84✔
86
        return nil
84✔
87
}
88

89
// Compare returns -1, 0, or 1 if v < other, v == other, or v > other, respectively.
90
func (v GoVersion) Compare(other GoVersion) int {
189✔
91
        if v.major > other.major {
194✔
92
                return 1
5✔
93
        }
5✔
94
        if v.major < other.major {
263✔
95
                return -1
79✔
96
        }
79✔
97

98
        if v.minor > other.minor {
161✔
99
                return 1
56✔
100
        }
56✔
101
        if v.minor < other.minor {
56✔
102
                return -1
7✔
103
        }
7✔
104

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

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

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

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

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

154
func checkGoVersion(verStr string, min, max GoVersion) error {
76✔
155
        var version GoVersion
76✔
156
        if err := version.parse(verStr); err != nil {
77✔
157
                return err
1✔
158
        }
1✔
159

160
        if version.Compare(min) < 0 || version.Compare(max) >= 0 {
80✔
161
                return fmt.Errorf("plugin requires %s <= version < %s", min, max)
5✔
162
        }
5✔
163

164
        return nil
70✔
165
}
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