Created
March 23, 2017 04:27
-
-
Save cnelson/fe66ed1c682e52e185a28edb0d716c59 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 ( | |
"bufio" | |
"bytes" | |
"fmt" | |
"io/ioutil" | |
"log" | |
"net/http" | |
"os/exec" | |
"regexp" | |
"sort" | |
"strings" | |
"sync" | |
"gopkg.in/yaml.v2" | |
) | |
type DependencyDeprecationDate struct { | |
Date string | |
Name string | |
Version string `yaml:"version_line"` | |
} | |
type DependencyDeprecationDates []DependencyDeprecationDate | |
func (slice DependencyDeprecationDates) Len() int { | |
return len(slice) | |
} | |
func (slice DependencyDeprecationDates) Less(i, j int) bool { | |
return slice[i].Date < slice[j].Date; | |
} | |
func (slice DependencyDeprecationDates) Swap(i, j int) { | |
slice[i], slice[j] = slice[j], slice[i] | |
} | |
type BuildpackManifest struct { | |
DependencyDeprecationDates DependencyDeprecationDates `yaml:"dependency_deprecation_dates"` | |
} | |
func main() { | |
var wg sync.WaitGroup | |
out, err := exec.Command("cf", "buildpacks").Output() | |
if err != nil { | |
log.Fatal(err) | |
} | |
r, _ := regexp.Compile(`(.+?) .+ (v\d+.*)\.zip$`) | |
scanner := bufio.NewScanner(bytes.NewBuffer(out)) | |
for scanner.Scan() { | |
buildpack := r.FindSubmatch(scanner.Bytes()) | |
wg.Add(1) | |
go func() { | |
defer wg.Done() | |
if len(buildpack) == 0 { | |
return | |
} | |
repo := strings.Replace(string(buildpack[1]), "_", "-", -1) | |
version := string(buildpack[2]) | |
resp, err := http.Get("https://raw.githubusercontent.com/cloudfoundry/" + repo + "/" + version + "/manifest.yml") | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer resp.Body.Close() | |
yamldata, err := ioutil.ReadAll(resp.Body) | |
if err != nil { | |
log.Fatal(err) | |
} | |
manifest := BuildpackManifest{} | |
err = yaml.Unmarshal(yamldata, &manifest) | |
if err != nil { | |
log.Fatal(err) | |
} | |
if len(manifest.DependencyDeprecationDates) == 0 { | |
return | |
} | |
sort.Sort(manifest.DependencyDeprecationDates) | |
fmt.Printf("%s %s\n", repo, version) | |
for _, item := range manifest.DependencyDeprecationDates { | |
fmt.Printf("\t%s - %s %s\n", item.Date, item.Name, item.Version) | |
} | |
}() | |
} | |
wg.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment