Skip to content

Commit

Permalink
playground: fix cannot find nightly version (#1715)
Browse files Browse the repository at this point in the history
  • Loading branch information
nexustar authored Jan 10, 2022
1 parent f7a536b commit db793d8
Showing 1 changed file with 35 additions and 27 deletions.
62 changes: 35 additions & 27 deletions pkg/repository/v1_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,30 @@ func (r *V1Repository) LocalComponentVersion(id, ver string, includeYanked bool)
return vi, nil
}

func findVersionFromManifest(id, constraint, platform string, manifest *v1manifest.Component) (string, error) {
cons, err := utils.NewConstraint(constraint)
if err != nil {
return "", err
}
versions := manifest.VersionList(platform)
verList := make([]string, 0, len(versions))
for v := range versions {
if v == manifest.Nightly {
continue
}
verList = append(verList, v)
}
sort.Slice(verList, func(p, q int) bool {
return semver.Compare(verList[p], verList[q]) > 0
})
for _, v := range verList {
if cons.Check(v) {
return v, nil
}
}
return "", errors.Annotatef(ErrUnknownVersion, "version %s on %s for component %s not found", constraint, platform, id)
}

// ResolveComponentVersionWithPlatform resolves the latest version of a component that satisfies the constraint
func (r *V1Repository) ResolveComponentVersionWithPlatform(id, constraint, platform string) (utils.Version, error) {
manifest, err := r.LocalComponentManifest(id, false)
Expand All @@ -814,40 +838,24 @@ func (r *V1Repository) ResolveComponentVersionWithPlatform(id, constraint, platf
}
ver = v.String()
case utils.NightlyVersionAlias:
if !manifest.HasNightly(platform) {
return "", errors.Annotatef(ErrUnknownVersion, "component %s does not have nightly on %s", id, platform)
}
ver = manifest.Nightly
default:
cons, err := utils.NewConstraint(constraint)
v, _, err := r.LatestNightlyVersion(id)
if err != nil {
return "", err
}
versions := manifest.VersionList(platform)
verList := make([]string, 0, len(versions))
for v := range versions {
if v == manifest.Nightly {
continue
ver = v.String()
default:
ver, err = findVersionFromManifest(id, constraint, platform, manifest)
if err != nil {
manifest, err = r.FetchComponentManifest(id, false)
if err != nil {
return "", err
}
verList = append(verList, v)
}
sort.Slice(verList, func(p, q int) bool {
return semver.Compare(verList[p], verList[q]) > 0
})
for _, v := range verList {
if cons.Check(v) {
ver = v
break
ver, err = findVersionFromManifest(id, constraint, platform, manifest)
if err != nil {
return "", errors.Annotatef(ErrUnknownVersion, "version %s on %s for component %s not found", constraint, platform, id)
}
}
}
if ver == "" {
return "", fmt.Errorf(`no version on %s for component %s satisfies constraint "%s"`, platform, id, constraint)
}
vi := manifest.VersionItem(platform, ver, false)
if vi == nil {
return "", errors.Annotatef(ErrUnknownVersion, "version %s on %s for component %s not found", ver, platform, id)
}
return utils.Version(ver), nil
}

Expand Down

0 comments on commit db793d8

Please sign in to comment.