mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-15 20:44:01 +02:00
Update to Go 1.17
Go 1.17 now lazy-loads dependencies when `go.mod` is version `go17`. This does not work for us for new projects started with `hugo mod init`. Before this commit, starting a project with Go 1.17 with `hugo mod init` and then start adding dependencies with transitive dependenies to `config.toml` would treat the transitive dependencies as new, and you would potentially get a too recent version of those. Note that this does not effect existing projects, where all dependencies are already recorded in `go.mod`. Fixes #8930
This commit is contained in:
@@ -16,7 +16,9 @@ package htesting
|
||||
import (
|
||||
"math/rand"
|
||||
"os"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -103,3 +105,28 @@ func IsGitHubAction() bool {
|
||||
func SupportsAll() bool {
|
||||
return IsGitHubAction()
|
||||
}
|
||||
|
||||
// GoMinorVersion returns the minor version of the current Go version,
|
||||
// e.g. 16 for Go 1.16.
|
||||
func GoMinorVersion() int {
|
||||
return extractMinorVersionFromGoTag(runtime.Version())
|
||||
}
|
||||
|
||||
var goMinorVersionRe = regexp.MustCompile(`go1.(\d*)`)
|
||||
|
||||
func extractMinorVersionFromGoTag(tag string) int {
|
||||
// The tag may be on the form go1.17, go1.17.5 go1.17rc2 -- or just a commit hash.
|
||||
match := goMinorVersionRe.FindStringSubmatch(tag)
|
||||
|
||||
if len(match) == 2 {
|
||||
i, err := strconv.Atoi(match[1])
|
||||
if err != nil {
|
||||
return -1
|
||||
}
|
||||
return i
|
||||
}
|
||||
|
||||
// a commit hash, not useful.
|
||||
return -1
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user