File tree Expand file tree Collapse file tree 3 files changed +10
-9
lines changed Expand file tree Collapse file tree 3 files changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -154,8 +154,7 @@ func getNeedGopath(workspace project.GoWorkspace, importpath string) bool {
154
154
// Try to update `go.mod` and `go.sum` if the go version is >= 1.16.
155
155
func tryUpdateGoModAndGoSum (workspace project.GoWorkspace ) {
156
156
// Go 1.16 and later won't automatically attempt to update go.mod / go.sum during package loading, so try to update them here:
157
- v1_16 := util .NewSemVer ("v1.16" )
158
- if workspace .ModMode != project .ModVendor && workspace .DepMode == project .GoGetWithModules && toolchain .GetEnvGoSemVer ().IsAtLeast (v1_16 ) {
157
+ if workspace .ModMode != project .ModVendor && workspace .DepMode == project .GoGetWithModules && toolchain .GetEnvGoSemVer ().IsAtLeast (toolchain .V1_16 ) {
159
158
for _ , goMod := range workspace .Modules {
160
159
// stat go.mod and go.sum
161
160
goModPath := goMod .Path
@@ -541,8 +540,7 @@ func installDependenciesAndBuild() {
541
540
542
541
// This diagnostic is not required if the system Go version is 1.21 or greater, since the
543
542
// Go tooling should install required Go versions as needed.
544
- v1_21 := util .NewSemVer ("v1.21.0" )
545
- if toolchain .GetEnvGoSemVer ().IsOlderThan (v1_21 ) && greatestGoVersion != nil && greatestGoVersion .IsNewerThan (toolchain .GetEnvGoSemVer ()) {
543
+ if toolchain .GetEnvGoSemVer ().IsOlderThan (toolchain .V1_21 ) && greatestGoVersion != nil && greatestGoVersion .IsNewerThan (toolchain .GetEnvGoSemVer ()) {
546
544
diagnostics .EmitNewerGoVersionNeeded (toolchain .GetEnvGoSemVer ().String (), greatestGoVersion .String ())
547
545
if val , _ := os .LookupEnv ("GITHUB_ACTIONS" ); val == "true" {
548
546
log .Printf (
Original file line number Diff line number Diff line change @@ -175,9 +175,8 @@ var toolchainVersionRe *regexp.Regexp = regexp.MustCompile(`(?m)^([0-9]+\.[0-9]+
175
175
// Returns true if the `go.mod` file specifies a Go language version, that version is `1.21` or greater, and
176
176
// there is no `toolchain` directive, and the Go language version is not a valid toolchain version.
177
177
func hasInvalidToolchainVersion (modFile * modfile.File ) bool {
178
- v1_21 := util .NewSemVer ("v1.21.0" )
179
178
return modFile .Toolchain == nil && modFile .Go != nil &&
180
- ! toolchainVersionRe .Match ([]byte (modFile .Go .Version )) && util .NewSemVer (modFile .Go .Version ).IsAtLeast (v1_21 )
179
+ ! toolchainVersionRe .Match ([]byte (modFile .Go .Version )) && util .NewSemVer (modFile .Go .Version ).IsAtLeast (toolchain . V1_21 )
181
180
}
182
181
183
182
// Given a list of `go.mod` file paths, try to parse them all. The resulting array of `GoModule` objects
@@ -538,8 +537,7 @@ func (m ModMode) ArgsForGoVersion(version util.SemVer) []string {
538
537
case ModReadonly :
539
538
return []string {"-mod=readonly" }
540
539
case ModMod :
541
- v1_14 := util .NewSemVer ("v1.14" )
542
- if version .IsOlderThan (v1_14 ) {
540
+ if version .IsOlderThan (toolchain .V1_14 ) {
543
541
return []string {} // -mod=mod is the default behaviour for go <= 1.13, and is not accepted as an argument
544
542
} else {
545
543
return []string {"-mod=mod" }
Original file line number Diff line number Diff line change @@ -13,6 +13,11 @@ import (
13
13
"github.com/github/codeql-go/extractor/util"
14
14
)
15
15
16
+ var V1_14 = util .NewSemVer ("v1.14.0" )
17
+ var V1_16 = util .NewSemVer ("v1.16.0" )
18
+ var V1_18 = util .NewSemVer ("v1.18.0" )
19
+ var V1_21 = util .NewSemVer ("v1.21.0" )
20
+
16
21
// Check if Go is installed in the environment.
17
22
func IsInstalled () bool {
18
23
_ , err := exec .LookPath ("go" )
@@ -128,7 +133,7 @@ func parseGoVersion(data string) string {
128
133
129
134
// Returns a value indicating whether the system Go toolchain supports workspaces.
130
135
func SupportsWorkspaces () bool {
131
- return GetEnvGoSemVer ().IsAtLeast (util . NewSemVer ( "v1.18.0" ) )
136
+ return GetEnvGoSemVer ().IsAtLeast (V1_18 )
132
137
}
133
138
134
139
// Run `go mod tidy -e` in the directory given by `path`.
You can’t perform that action at this time.
0 commit comments