Centralize Go validation and build environments
This commit is contained in:
@@ -10,8 +10,8 @@ import (
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"gitea.maximumdirect.net/eric/ReleaseKit/internal/gotool"
|
||||
"gitea.maximumdirect.net/eric/ReleaseKit/internal/process"
|
||||
"gitea.maximumdirect.net/eric/ReleaseKit/internal/versioncontract"
|
||||
)
|
||||
@@ -216,35 +216,13 @@ func hasLocalTag(ctx context.Context, repositoryDir, version string) (bool, erro
|
||||
}
|
||||
|
||||
func runDefaultValidation(ctx context.Context, repositoryDir string, output io.Writer) error {
|
||||
environment := map[string]string{
|
||||
"GOWORK": "off",
|
||||
"GOPROXY": "off",
|
||||
"GONOPROXY": "none",
|
||||
"GOSUMDB": "off",
|
||||
"GOTOOLCHAIN": "local",
|
||||
tool, err := gotool.New(ctx, repositoryDir)
|
||||
if err != nil {
|
||||
return fmt.Errorf("prepare Go toolchain: %w", err)
|
||||
}
|
||||
var writer io.Writer = output
|
||||
if output != nil {
|
||||
writer = &synchronizedWriter{writer: output}
|
||||
}
|
||||
return process.Run(ctx, process.Invocation{
|
||||
Args: []string{"go", "test", "-mod=readonly", "-count=1", "./..."},
|
||||
Dir: repositoryDir,
|
||||
Env: environment,
|
||||
Stdout: writer,
|
||||
Stderr: writer,
|
||||
})
|
||||
}
|
||||
|
||||
type synchronizedWriter struct {
|
||||
mu sync.Mutex
|
||||
writer io.Writer
|
||||
}
|
||||
|
||||
func (w *synchronizedWriter) Write(p []byte) (int, error) {
|
||||
w.mu.Lock()
|
||||
defer w.mu.Unlock()
|
||||
return w.writer.Write(p)
|
||||
_, err = tool.Run(ctx, repositoryDir, gotool.Native, gotool.Target{}, output,
|
||||
"test", "-mod=readonly", "-count=1", "./...")
|
||||
return err
|
||||
}
|
||||
|
||||
func validStableVersion(version string) bool {
|
||||
|
||||
Reference in New Issue
Block a user