-
Notifications
You must be signed in to change notification settings - Fork 0
/
check.go
41 lines (34 loc) · 959 Bytes
/
check.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package recipeutil
import (
"context"
"fmt"
"github.com/futurice/jalapeno/internal/cli/option"
"github.com/futurice/jalapeno/pkg/oci"
re "github.com/futurice/jalapeno/pkg/recipe"
"golang.org/x/mod/semver"
)
func CheckForUpdates(sauce *re.Sauce, opts option.OCIRepository) ([]string, error) {
if sauce.CheckFrom == "" {
return nil, fmt.Errorf("source of the sauce with ID '%s' is undefined, can not check for new versions", sauce.ID)
}
repo, err := oci.NewRepository(opts.Repository(sauce.CheckFrom))
if err != nil {
return nil, err
}
var versions []string
ctx := context.Background()
err = repo.Tags(ctx, "", func(tags []string) error {
versions = make([]string, 0, len(tags))
for _, tag := range tags {
if semver.IsValid(tag) && semver.Compare(tag, sauce.Recipe.Version) > 0 {
versions = append(versions, tag)
}
}
semver.Sort(versions)
return nil
})
if err != nil {
return nil, err
}
return versions, nil
}