Created
September 14, 2020 18:54
-
-
Save sophiewigmore/b865d33cfb208b6d2ffc9dddab42cc9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main │············································································································ | |
│············································································································ | |
import ( │············································································································ | |
"fmt" │············································································································ | |
"sort" │············································································································ | |
│············································································································ | |
"github.com/Masterminds/semver" │············································································································ | |
"github.com/google/go-containerregistry/pkg/name" │············································································································ | |
"github.com/google/go-containerregistry/pkg/v1/remote" │············································································································ | |
) │············································································································ | |
│············································································································ | |
func main() { │············································································································ | |
│············································································································ | |
registry, err := name.NewRegistry("gcr.io") │············································································································ | |
if err != nil { │············································································································ | |
panic(err) │············································································································ | |
} │············································································································ | |
│············································································································ | |
repo, err := name.NewRepository("paketo-buildpacks/go") │············································································································ | |
if err != nil { │············································································································ | |
panic(err) │············································································································ | |
} │············································································································ | |
│············································································································ | |
repo.Registry = registry │············································································································ | |
│············································································································ | |
tags, err := remote.List(repo) │············································································································ | |
if err != nil { │············································································································ | |
panic(err) │············································································································ | |
} │············································································································ | |
fmt.Println(tags) │············································································································ | |
│············································································································ | |
vs := make([]*semver.Version, len(tags)) │············································································································ | |
for i, r := range tags { │············································································································ | |
if r == "latest" { │············································································································ | |
r = "0.0.0" │············································································································ | |
} │············································································································ | |
v, err := semver.NewVersion(r) │············································································································ | |
if err != nil { │············································································································ | |
panic(err) │············································································································ | |
} │············································································································ | |
│············································································································ | |
vs[i] = v │············································································································ | |
} │············································································································ | |
sort.Sort(semver.Collection(vs)) │············································································································ | |
fmt.Println(vs) │············································································································ | |
│············································································································ | |
fmt.Println(vs[len(vs)-1]) │············································································································ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment