ci: use authenticated github when possible (#21189)
* hack update to use github token if available * automate go mod tidy for both * add ghc client for k8s vers listpull/21203/head
parent
4803425479
commit
49d0fa4e1b
|
|
@ -23,13 +23,14 @@ import (
|
|||
"github.com/google/go-github/v73/github"
|
||||
|
||||
"k8s.io/klog/v2"
|
||||
"k8s.io/minikube/hack/update"
|
||||
)
|
||||
|
||||
// recentK8sVersions returns the most recent k8s version, usually around 100.
|
||||
func recentK8sVersions() ([]string, error) {
|
||||
const k8s = "kubernetes"
|
||||
client := github.NewClient(nil)
|
||||
list, _, err := client.Repositories.ListReleases(context.Background(), k8s, k8s, &github.ListOptions{PerPage: 100})
|
||||
ghc := update.GHClient()
|
||||
list, _, err := ghc.Repositories.ListReleases(context.Background(), k8s, k8s, &github.ListOptions{PerPage: 100})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ package update
|
|||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/mod/semver"
|
||||
|
|
@ -43,7 +44,7 @@ type Release struct {
|
|||
// GHReleases returns greatest current stable release and greatest latest rc or beta pre-release from GitHub owner/repo repository, and any error occurred.
|
||||
// If latest pre-release version is lower than the current stable release, then it will return current stable release for both.
|
||||
func GHReleases(ctx context.Context, owner, repo string) (stable, latest, edge Release, err error) {
|
||||
ghc := github.NewClient(nil)
|
||||
ghc := GHClient()
|
||||
|
||||
// walk through the paginated list of up to ghSearchLimit newest releases
|
||||
opts := &github.ListOptions{PerPage: ghListPerPage}
|
||||
|
|
@ -107,3 +108,12 @@ func StableVersion(ctx context.Context, owner, repo string) (string, error) {
|
|||
}
|
||||
return stable.Tag, nil
|
||||
}
|
||||
|
||||
// GHClient returns a GitHub client regardless of whether the GITHUB_TOKEN is set or not.
|
||||
func GHClient() *github.Client {
|
||||
if os.Getenv("GITHUB_TOKEN") == "" {
|
||||
return github.NewClient(nil)
|
||||
}
|
||||
return github.NewClient(nil).WithAuthToken(os.Getenv("GITHUB_TOKEN"))
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,6 +57,14 @@ func main() {
|
|||
if err := exec.Command("go", "mod", "tidy").Run(); err != nil {
|
||||
klog.Fatalf("failed to run go mod tidy: %v", err)
|
||||
}
|
||||
|
||||
// we need to run go mod tidy in the root folder too (since both minikube and hack use go-github)
|
||||
cmd := exec.Command("go", "mod", "tidy")
|
||||
cmd.Dir = ".."
|
||||
if err := cmd.Run(); err != nil {
|
||||
klog.Fatalf("failed to run go mod tidy in parent folder: %v", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func generateSchema() map[string]update.Item {
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ func main() {
|
|||
|
||||
func LatestControllerTag(ctx context.Context) (string, error) {
|
||||
latest := "v0.0.0"
|
||||
ghc := github.NewClient(nil)
|
||||
ghc := update.GHClient()
|
||||
re := regexp.MustCompile(`controller-(.*)`)
|
||||
|
||||
// walk through the paginated list of up to ghSearchLimit newest releases
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ func main() {
|
|||
|
||||
releases := []string{}
|
||||
|
||||
ghc := github.NewClient(nil)
|
||||
ghc := update.GHClient()
|
||||
|
||||
opts := &github.ListOptions{PerPage: 100}
|
||||
for {
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ type Data struct {
|
|||
func main() {
|
||||
releases := []string{}
|
||||
|
||||
ghc := github.NewClient(nil)
|
||||
ghc := update.GHClient()
|
||||
|
||||
opts := &github.ListOptions{PerPage: 100}
|
||||
for {
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ func main() {
|
|||
}
|
||||
|
||||
func latestNodeVersionByMajor(ctx context.Context, major string) (string, error) {
|
||||
ghc := github.NewClient(nil)
|
||||
ghc := update.GHClient()
|
||||
|
||||
// walk through the paginated list of up to ghSearchLimit newest releases
|
||||
opts := &github.ListOptions{PerPage: ghListPerPage}
|
||||
|
|
|
|||
Loading…
Reference in New Issue