Skip to content

Instantly share code, notes, and snippets.

@sophiewigmore
Created September 14, 2020 18:54
Show Gist options
  • Save sophiewigmore/b865d33cfb208b6d2ffc9dddab42cc9e to your computer and use it in GitHub Desktop.
Save sophiewigmore/b865d33cfb208b6d2ffc9dddab42cc9e to your computer and use it in GitHub Desktop.
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