mirror of
https://github.com/dolthub/dolt.git
synced 2026-04-24 11:39:03 -05:00
Merge pull request #7105 from dolthub/steph/version
Add of out date warning to `dolt version`
This commit is contained in:
Generated
+68
@@ -5034,6 +5034,74 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
= LICENSE bda64ae869be18b50125d9cfe5c370eb7248e84a2324823e4d7f2295 =
|
||||
================================================================================
|
||||
|
||||
================================================================================
|
||||
= github.com/google/go-github/v57 licensed under: =
|
||||
|
||||
Copyright (c) 2013 The go-github AUTHORS. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
= LICENSE 4f95ee9c8c81d66113b4c4fe66b684ae243884b5947ee854319dd9cc =
|
||||
================================================================================
|
||||
|
||||
================================================================================
|
||||
= github.com/google/go-querystring licensed under: =
|
||||
|
||||
Copyright (c) 2013 Google. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
= LICENSE 7b97c9585df42dc638169348f6350b491fc35fe50884a7e6cf41aa58 =
|
||||
================================================================================
|
||||
|
||||
================================================================================
|
||||
= github.com/google/s2a-go licensed under: =
|
||||
|
||||
|
||||
@@ -16,9 +16,18 @@ package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/google/go-github/v57/github"
|
||||
|
||||
"github.com/dolthub/dolt/go/cmd/dolt/cli"
|
||||
"github.com/dolthub/dolt/go/cmd/dolt/errhand"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/dbfactory"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dfunctions"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/argparser"
|
||||
@@ -27,8 +36,17 @@ import (
|
||||
const (
|
||||
featureVersionFlag = "feature"
|
||||
verboseFlag = "verbose"
|
||||
versionCheckFile = "version_check.txt"
|
||||
)
|
||||
|
||||
var versionDocs = cli.CommandDocumentationContent{
|
||||
ShortDesc: "Displays the version for the Dolt binary.",
|
||||
LongDesc: `Displays the version for the Dolt binary.`,
|
||||
Synopsis: []string{
|
||||
`[--verbose] [--feature]`,
|
||||
},
|
||||
}
|
||||
|
||||
type VersionCmd struct {
|
||||
VersionStr string
|
||||
}
|
||||
@@ -40,7 +58,7 @@ func (cmd VersionCmd) Name() string {
|
||||
|
||||
// Description returns a description of the command
|
||||
func (cmd VersionCmd) Description() string {
|
||||
return "Displays the current Dolt cli version."
|
||||
return versionDocs.ShortDesc
|
||||
}
|
||||
|
||||
// RequiresRepo should return false if this interface is implemented, and the command does not have the requirement
|
||||
@@ -50,7 +68,8 @@ func (cmd VersionCmd) RequiresRepo() bool {
|
||||
}
|
||||
|
||||
func (cmd VersionCmd) Docs() *cli.CommandDocumentation {
|
||||
return nil
|
||||
ap := cmd.ArgParser()
|
||||
return cli.NewCommandDocumentation(versionDocs, ap)
|
||||
}
|
||||
|
||||
func (cmd VersionCmd) ArgParser() *argparser.ArgParser {
|
||||
@@ -63,11 +82,18 @@ func (cmd VersionCmd) ArgParser() *argparser.ArgParser {
|
||||
// Version displays the version of the running dolt client
|
||||
// Exec executes the command
|
||||
func (cmd VersionCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv, cliCtx cli.CliContext) int {
|
||||
ap := cmd.ArgParser()
|
||||
help, usage := cli.HelpAndUsagePrinters(cli.CommandDocsForCommandString(commandStr, versionDocs, ap))
|
||||
apr := cli.ParseArgsOrDie(ap, args, help)
|
||||
|
||||
cli.Println("dolt version", cmd.VersionStr)
|
||||
|
||||
usage := func() {}
|
||||
ap := cmd.ArgParser()
|
||||
apr := cli.ParseArgsOrDie(ap, args, usage)
|
||||
var verr errhand.VerboseError
|
||||
verr = checkAndPrintVersionOutOfDateWarning(cmd.VersionStr, dEnv)
|
||||
if verr != nil {
|
||||
// print error but don't fail
|
||||
cli.PrintErrf(color.YellowString(verr.Verbose()))
|
||||
}
|
||||
|
||||
if apr.Contains(verboseFlag) {
|
||||
if dEnv.HasDoltDir() && dEnv.RSLoadErr == nil && !cli.CheckEnvIsValid(dEnv) {
|
||||
@@ -78,7 +104,6 @@ func (cmd VersionCmd) Exec(ctx context.Context, commandStr string, args []string
|
||||
}
|
||||
}
|
||||
|
||||
var verr errhand.VerboseError
|
||||
if apr.Contains(featureVersionFlag) {
|
||||
if !cli.CheckEnvIsValid(dEnv) {
|
||||
return 2
|
||||
@@ -92,12 +117,84 @@ func (cmd VersionCmd) Exec(ctx context.Context, commandStr string, args []string
|
||||
fv, ok, err := wr.GetFeatureVersion(ctx)
|
||||
if err != nil {
|
||||
verr = errhand.BuildDError("error reading feature version").AddCause(err).Build()
|
||||
return HandleVErrAndExitCode(verr, usage)
|
||||
} else if !ok {
|
||||
verr = errhand.BuildDError("the current head does not have a feature version").Build()
|
||||
return HandleVErrAndExitCode(verr, usage)
|
||||
} else {
|
||||
cli.Println("feature version:", fv)
|
||||
}
|
||||
}
|
||||
|
||||
return HandleVErrAndExitCode(verr, usage)
|
||||
return HandleVErrAndExitCode(nil, usage)
|
||||
}
|
||||
|
||||
// checkAndPrintVersionOutOfDateWarning checks if the current version of Dolt is out of date and prints a warning if it
|
||||
// is. Restricts this check to at most once per week.
|
||||
func checkAndPrintVersionOutOfDateWarning(curVersion string, dEnv *env.DoltEnv) errhand.VerboseError {
|
||||
var latestRelease string
|
||||
var verr errhand.VerboseError
|
||||
|
||||
homeDir, err := dEnv.GetUserHomeDir()
|
||||
if err != nil {
|
||||
return errhand.BuildDError("error: failed to get user home directory").AddCause(err).Build()
|
||||
}
|
||||
path := filepath.Join(homeDir, dbfactory.DoltDir, versionCheckFile)
|
||||
|
||||
if exists, _ := dEnv.FS.Exists(path); exists {
|
||||
vCheck, err := dEnv.FS.ReadFile(path)
|
||||
if err != nil {
|
||||
return errhand.BuildDError("error: failed to read version check file").AddCause(err).Build()
|
||||
}
|
||||
|
||||
vCheckData := strings.Split(string(vCheck), ",")
|
||||
if len(vCheckData) != 2 {
|
||||
// formatting or data is wrong, so just overwrite
|
||||
latestRelease, verr = getLatestDoltReleaseAndRecord(path, dEnv)
|
||||
if verr != nil {
|
||||
return verr
|
||||
}
|
||||
} else {
|
||||
latestRelease = vCheckData[0]
|
||||
lastCheckDate, err := time.Parse(time.DateOnly, vCheckData[1])
|
||||
if err != nil {
|
||||
return errhand.BuildDError("error: failed to parse version check file").AddCause(err).Build()
|
||||
}
|
||||
if lastCheckDate.Before(time.Now().AddDate(0, 0, -7)) {
|
||||
latestRelease, verr = getLatestDoltReleaseAndRecord(path, dEnv)
|
||||
if verr != nil {
|
||||
return verr
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
latestRelease, verr = getLatestDoltReleaseAndRecord(path, dEnv)
|
||||
if verr != nil {
|
||||
return verr
|
||||
}
|
||||
}
|
||||
|
||||
if curVersion != latestRelease {
|
||||
cli.Printf(color.YellowString("Warning: you are on an old version of Dolt. The newest version is %s.\n", latestRelease))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// getLatestDoltRelease returns the latest release of Dolt from GitHub and records the release and current date in the
|
||||
// version check file.
|
||||
func getLatestDoltReleaseAndRecord(path string, dEnv *env.DoltEnv) (string, errhand.VerboseError) {
|
||||
client := github.NewClient(nil)
|
||||
release, resp, err := client.Repositories.GetLatestRelease(context.Background(), "dolthub", "dolt")
|
||||
if err != nil || resp.StatusCode != 200 {
|
||||
return "", errhand.BuildDError("error: failed to verify latest release").AddCause(err).Build()
|
||||
}
|
||||
releaseName := strings.TrimPrefix(*release.TagName, "v")
|
||||
|
||||
err = dEnv.FS.WriteFile(path, []byte(fmt.Sprintf("%s,%s", releaseName, time.Now().UTC().Format(time.DateOnly))), os.ModePerm)
|
||||
if err != nil {
|
||||
return "", errhand.BuildDError("error: failed to update version check file").AddCause(err).Build()
|
||||
}
|
||||
|
||||
return releaseName, nil
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ require (
|
||||
github.com/dolthub/go-mysql-server v0.17.1-0.20231205222834-2eb85072ed9d
|
||||
github.com/dolthub/swiss v0.1.0
|
||||
github.com/goccy/go-json v0.10.2
|
||||
github.com/google/go-github/v57 v57.0.0
|
||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
|
||||
github.com/hashicorp/golang-lru/v2 v2.0.2
|
||||
github.com/jmoiron/sqlx v1.3.4
|
||||
@@ -113,7 +114,8 @@ require (
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
|
||||
github.com/golang/protobuf v1.5.3 // indirect
|
||||
github.com/google/go-cmp v0.5.9 // indirect
|
||||
github.com/google/go-cmp v0.6.0 // indirect
|
||||
github.com/google/go-querystring v1.1.0 // indirect
|
||||
github.com/google/s2a-go v0.1.4 // indirect
|
||||
github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
|
||||
github.com/googleapis/gax-go/v2 v2.11.0 // indirect
|
||||
|
||||
@@ -321,13 +321,18 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
|
||||
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
|
||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/go-github/v57 v57.0.0 h1:L+Y3UPTY8ALM8x+TV0lg+IEBI+upibemtBD8Q9u7zHs=
|
||||
github.com/google/go-github/v57 v57.0.0/go.mod h1:s0omdnye0hvK/ecLvpsGfJMiRt85PimQh4oygmLIxHw=
|
||||
github.com/google/go-querystring v1.1.0 h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
|
||||
github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17icRSOU623lUBU=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/google/martian v2.1.0+incompatible h1:/CP5g8u/VJHijgedC/Legn3BAbAaWPgecwXBIDzw5no=
|
||||
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
||||
|
||||
@@ -59,7 +59,7 @@ teardown() {
|
||||
[[ "$output" =~ "gc - Cleans up unreferenced data from the repository." ]] || false
|
||||
[[ "$output" =~ "filter-branch - Edits the commit history using the provided query." ]] || false
|
||||
[[ "$output" =~ "merge-base - Find the common ancestor of two commits." ]] || false
|
||||
[[ "$output" =~ "version - Displays the current Dolt cli version." ]] || false
|
||||
[[ "$output" =~ "version - Displays the version for the Dolt binary." ]] || false
|
||||
[[ "$output" =~ "dump - Export all tables in the working set into a file." ]] || false
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user