Skip to content

Commit

Permalink
tiup: mirror clone support specify latest version of a component (#1835)
Browse files Browse the repository at this point in the history
  • Loading branch information
srstack authored Apr 13, 2022
1 parent 28fcf9a commit 58f86e8
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 10 deletions.
33 changes: 23 additions & 10 deletions pkg/repository/clone_mirror.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
22 changes: 22 additions & 0 deletions pkg/repository/v1manifest/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import (
"errors"
"fmt"
"time"

"github.com/pingcap/tiup/pkg/utils"
"golang.org/x/mod/semver"
)

// Manifest representation for ser/de.
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 58f86e8

Please sign in to comment.