modules: Add GOAUTH to module config

Closes #13385
This commit is contained in:
Bjørn Erik Pedersen
2025-02-13 11:00:02 +01:00
parent d89b9d891c
commit 2c77719cd6
4 changed files with 83 additions and 19 deletions

View File

@@ -32,6 +32,7 @@ import (
"github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/common/hexec"
"github.com/gohugoio/hugo/common/loggers"
"github.com/gohugoio/hugo/config"
hglob "github.com/gohugoio/hugo/hugofs/glob"
@@ -41,8 +42,6 @@ import (
"github.com/gohugoio/hugo/hugofs/files"
"github.com/gohugoio/hugo/config"
"golang.org/x/mod/module"
"github.com/gohugoio/hugo/common/hugio"
@@ -79,21 +78,6 @@ func NewClient(cfg ClientConfig) *Client {
goModFilename = n
}
var env []string
mcfg := cfg.ModuleConfig
config.SetEnvVars(&env,
"PWD", cfg.WorkingDir,
"GO111MODULE", "on",
"GOPROXY", mcfg.Proxy,
"GOPRIVATE", mcfg.Private,
"GONOPROXY", mcfg.NoProxy,
"GOPATH", cfg.CacheDir,
"GOWORK", mcfg.Workspace, // Requires Go 1.18, see https://tip.golang.org/doc/go1.18
// GOCACHE was introduced in Go 1.15. This matches the location derived from GOPATH above.
"GOCACHE", filepath.Join(cfg.CacheDir, "pkg", "mod"),
)
logger := cfg.Logger
if logger == nil {
logger = loggers.NewDefault()
@@ -109,8 +93,8 @@ func NewClient(cfg ClientConfig) *Client {
ccfg: cfg,
logger: logger,
noVendor: noVendor,
moduleConfig: mcfg,
environ: env,
moduleConfig: cfg.ModuleConfig,
environ: cfg.toEnv(),
GoModulesFilename: goModFilename,
}
}
@@ -785,6 +769,37 @@ func (c ClientConfig) shouldIgnoreVendor(path string) bool {
return c.IgnoreVendor != nil && c.IgnoreVendor.Match(path)
}
func (cfg ClientConfig) toEnv() []string {
mcfg := cfg.ModuleConfig
var env []string
keyVals := []string{
"PWD", cfg.WorkingDir,
"GO111MODULE", "on",
"GOPATH", cfg.CacheDir,
"GOWORK", mcfg.Workspace, // Requires Go 1.18, see https://tip.golang.org/doc/go1.18
// GOCACHE was introduced in Go 1.15. This matches the location derived from GOPATH above.
"GOCACHE", filepath.Join(cfg.CacheDir, "pkg", "mod"),
}
if mcfg.Proxy != "" {
keyVals = append(keyVals, "GOPROXY", mcfg.Proxy)
}
if mcfg.Private != "" {
keyVals = append(keyVals, "GOPRIVATE", mcfg.Private)
}
if mcfg.NoProxy != "" {
keyVals = append(keyVals, "GONOPROXY", mcfg.NoProxy)
}
if mcfg.Auth != "" {
// GOAUTH was introduced in Go 1.24, see https://tip.golang.org/doc/go1.24.
keyVals = append(keyVals, "GOAUTH", mcfg.Auth)
}
config.SetEnvVars(&env, keyVals...)
return env
}
type goBinaryStatus int
type goModule struct {