mirror of
https://github.com/go-gitea/gitea
synced 2024-11-18 08:04:25 +00:00
d1353e1f7c
* update code.gitea.io/sdk/gitea v0.13.1 -> v0.13.2 * update github.com/go-swagger/go-swagger v0.25.0 -> v0.26.0 * update github.com/google/uuid v1.1.2 -> v1.2.0 * update github.com/klauspost/compress v1.11.3 -> v1.11.7 * update github.com/lib/pq 083382b7e6fc -> v1.9.0 * update github.com/markbates/goth v1.65.0 -> v1.66.1 * update github.com/mattn/go-sqlite3 v1.14.4 -> v1.14.6 * update github.com/mgechev/revive 246eac737dc7 -> v1.0.3 * update github.com/minio/minio-go/v7 v7.0.6 -> v7.0.7 * update github.com/niklasfasching/go-org v1.3.2 -> v1.4.0 * update github.com/olivere/elastic/v7 v7.0.21 -> v7.0.22 * update github.com/pquerna/otp v1.2.0 -> v1.3.0 * update github.com/xanzy/go-gitlab v0.39.0 -> v0.42.0 * update github.com/yuin/goldmark v1.2.1 -> v1.3.1
52 lines
1.5 KiB
Go
Vendored
52 lines
1.5 KiB
Go
Vendored
// Copyright 2020 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package gocommand
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
)
|
|
|
|
// GoVersion checks the go version by running "go list" with modules off.
|
|
// It returns the X in Go 1.X.
|
|
func GoVersion(ctx context.Context, inv Invocation, r *Runner) (int, error) {
|
|
inv.Verb = "list"
|
|
inv.Args = []string{"-e", "-f", `{{context.ReleaseTags}}`}
|
|
inv.Env = append(append([]string{}, inv.Env...), "GO111MODULE=off")
|
|
// Unset any unneeded flags, and remove them from BuildFlags, if they're
|
|
// present.
|
|
inv.ModFile = ""
|
|
inv.ModFlag = ""
|
|
var buildFlags []string
|
|
for _, flag := range inv.BuildFlags {
|
|
// Flags can be prefixed by one or two dashes.
|
|
f := strings.TrimPrefix(strings.TrimPrefix(flag, "-"), "-")
|
|
if strings.HasPrefix(f, "mod=") || strings.HasPrefix(f, "modfile=") {
|
|
continue
|
|
}
|
|
buildFlags = append(buildFlags, flag)
|
|
}
|
|
inv.BuildFlags = buildFlags
|
|
stdoutBytes, err := r.Run(ctx, inv)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
stdout := stdoutBytes.String()
|
|
if len(stdout) < 3 {
|
|
return 0, fmt.Errorf("bad ReleaseTags output: %q", stdout)
|
|
}
|
|
// Split up "[go1.1 go1.15]"
|
|
tags := strings.Fields(stdout[1 : len(stdout)-2])
|
|
for i := len(tags) - 1; i >= 0; i-- {
|
|
var version int
|
|
if _, err := fmt.Sscanf(tags[i], "go1.%d", &version); err != nil {
|
|
continue
|
|
}
|
|
return version, nil
|
|
}
|
|
return 0, fmt.Errorf("no parseable ReleaseTags in %v", tags)
|
|
}
|