From 58f86e8d548139b5ec68933cd746763fb44ec258 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Qi=CE=BC=24hi=D0=AFu=C3=AD?= <39378935+srstack@users.noreply.github.com> Date: Wed, 13 Apr 2022 15:22:36 +0800 Subject: [PATCH] tiup: mirror clone support specify latest version of a component (#1835) --- pkg/repository/clone_mirror.go | 33 +++++++++++++++++++++--------- pkg/repository/v1manifest/types.go | 22 ++++++++++++++++++++ 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/pkg/repository/clone_mirror.go b/pkg/repository/clone_mirror.go index 9965c8be2f..2a958ef1a1 100644 --- a/pkg/repository/clone_mirror.go +++ b/pkg/repository/clone_mirror.go @@ -28,7 +28,6 @@ import ( "github.com/pingcap/tiup/pkg/repository/v1manifest" "github.com/pingcap/tiup/pkg/set" "github.com/pingcap/tiup/pkg/utils" - "golang.org/x/mod/semver" "golang.org/x/sync/errgroup" ) @@ -267,6 +266,7 @@ func cloneComponents(repo *V1Repository, } vs := combineVersions(options.Components[name], tidbClusterVersionMapper, manifest, options.OSs, options.Archs, selectedVersions) + var newManifest *v1manifest.Component if options.Full { newManifest = manifest @@ -446,24 +446,37 @@ func combineVersions(versions *[]string, if versions == nil { continue } + + // set specified version with latest tag + if result.Exist(utils.LatestVersionAlias) { + latest := manifest.LatestVersion(platform) + if latest != "" { + result.Insert(latest) + } + } + for _, selectedVersion := range selectedVersions { if selectedVersion == utils.NightlyVersionAlias { selectedVersion = manifest.Nightly } + + if selectedVersion == utils.LatestVersionAlias { + latest := manifest.LatestVersion(platform) + if latest == "" { + continue + } + + fmt.Printf("%s %s/%s found the lastest version %s\n", manifest.ID, os, arch, latest) + // set latest version + selectedVersion = latest + } + _, found := versions[selectedVersion] // Some TiUP components won't be bound version with TiDB, if cannot find // selected version we download the latest version to as a alternative if !found && !coreSuites.Exist(manifest.ID) { // Use the latest stable versionS if the selected version doesn't exist in specific platform - var latest string - for v := range versions { - if utils.Version(v).IsNightly() { - continue - } - if latest == "" || semver.Compare(v, latest) > 0 { - latest = v - } - } + latest := manifest.LatestVersion(platform) if latest == "" { continue } diff --git a/pkg/repository/v1manifest/types.go b/pkg/repository/v1manifest/types.go index b4ac60da7f..9803e790dd 100644 --- a/pkg/repository/v1manifest/types.go +++ b/pkg/repository/v1manifest/types.go @@ -18,6 +18,9 @@ import ( "errors" "fmt" "time" + + "github.com/pingcap/tiup/pkg/utils" + "golang.org/x/mod/semver" ) // Manifest representation for ser/de. @@ -256,6 +259,25 @@ func (manifest *Component) VersionList(platform string) map[string]VersionItem { return versions } +// LatestVersion return the latest version exclude yanked versions +func (manifest *Component) LatestVersion(platform string) string { + versions := manifest.VersionList(platform) + if versions == nil { + return "" + } + + var latest string + for v := range versions { + if utils.Version(v).IsNightly() { + continue + } + if latest == "" || semver.Compare(v, latest) > 0 { + latest = v + } + } + return latest +} + // VersionListWithYanked return all versions include yanked versions func (manifest *Component) VersionListWithYanked(platform string) map[string]VersionItem { if manifest == nil {