-
Notifications
You must be signed in to change notification settings - Fork 53
/
check-versions.go
executable file
·92 lines (80 loc) · 2.21 KB
/
check-versions.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
///usr/bin/env true; exec /usr/bin/env go run "$0" "$@"
package main
import (
"context"
"flag"
"fmt"
"io"
"log"
"net/http"
"os"
"text/tabwriter"
"github.com/google/go-github/github"
"golang.org/x/oauth2"
)
func init() {
log.SetFlags(0)
}
func writeRelease(w io.Writer, owner, name, tag, url string) (int, error) {
return fmt.Fprintf(w, "%s/%s\t%s\t%s\n", owner, name, tag, url)
}
func main() {
token := flag.String("token", "", "Github token to use")
flag.Parse()
ctx := context.Background()
var tc *http.Client
if *token != "" {
tc = oauth2.NewClient(ctx, oauth2.StaticTokenSource(&oauth2.Token{
AccessToken: *token,
}))
}
cl := github.NewClient(tc)
w := tabwriter.NewWriter(os.Stdout, 0, 8, 0, '\t', 0)
fmt.Fprintln(w, "Repository", "\tVersion", "\tRelease page")
for _, repo := range []struct {
owner, name string
}{
{"golang", "go"},
{"grpc-ecosystem", "grpc-gateway"},
{"stepancheg", "grpc-rust"},
{"grpc", "grpc-swift"},
{"grpc", "grpc-web"},
{"pseudomuto", "protoc-gen-doc"},
{"grpc", "grpc-go"},
{"protocolbuffers", "protobuf-go"},
{"gogo", "protobuf"},
{"mwitkow", "go-proto-validators"},
{"danielvladco", "go-proto-gql"},
{"ckaznocha", "protoc-gen-lint"},
{"envoyproxy", "protoc-gen-validate"},
{"stepancheg", "rust-protobuf"},
{"rust-lang", "rust"},
{"apple", "swift"},
{"improbable-eng", "ts-protoc-gen"},
{"upx", "upx"},
} {
tag := "n/a"
url := "n/a"
rel, _, err := cl.Repositories.GetLatestRelease(ctx, repo.owner, repo.name)
if err != nil {
log.Printf("Failed to query github API for latest release of `%s/%s`: %s, trying tags...", repo.owner, repo.name, err)
tags, _, err := cl.Repositories.ListTags(ctx, repo.owner, repo.name, &github.ListOptions{
PerPage: 1,
})
if err != nil {
log.Printf("Failed to list tags of `%s/%s` on github: %s", repo.owner, repo.name, err)
} else if len(tags) > 0 {
tag = *tags[0].Name
}
} else {
tag = *rel.TagName
url = *rel.HTMLURL
}
if _, err := writeRelease(w, repo.owner, repo.name, tag, url); err != nil {
log.Printf("Failed to write release %s(%s) of `%s/%s`: %s", err, tag, *rel.HTMLURL, repo.owner, repo.name)
}
}
if err := w.Flush(); err != nil {
log.Fatal(err)
}
}