Skip to content

Commit

Permalink
Add an environment varialbe which disables the parsing of Go version …
Browse files Browse the repository at this point in the history
…from module file

Signed-off-by: Cosmin Cojocar <cosmin@cojocar.ch>
  • Loading branch information
ccojocar committed May 22, 2024
1 parent b633c4c commit 9a03665
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ import (
"strings"
)

// noGoModVersion disables the parsing of go version from go module file present in the project
const noGoModVersion = "GOSECNOMODVERSION"

// MatchCallByPackage ensures that the specified package is imported,
// adjusts the name for any aliases and ignores cases that are
// initialization only imports.
Expand Down Expand Up @@ -498,12 +501,13 @@ func RootPath(root string) (string, error) {

// GoVersion returns parsed version of Go mod version and fallback to runtime version if not found.
func GoVersion() (int, int, int) {
goVersion, err := goModVersion()
if err != nil {
return parseGoVersion(strings.TrimPrefix(runtime.Version(), "go"))
_, ok := os.LookupEnv(noGoModVersion)
if ok {
if goModVersion, err := goModVersion(); err == nil {
return parseGoVersion(goModVersion)
}
}

return parseGoVersion(goVersion)
return parseGoVersion(strings.TrimPrefix(runtime.Version(), "go"))
}

type goListOutput struct {
Expand Down

0 comments on commit 9a03665

Please sign in to comment.