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 list
pull/21203/head
Medya Ghazizadeh 2025-07-30 11:40:08 -07:00 committed by GitHub
parent 4803425479
commit 49d0fa4e1b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 26 additions and 7 deletions

View File

@ -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
}

View File

@ -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"))
}

View File

@ -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 {

View File

@ -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

View File

@ -62,7 +62,7 @@ func main() {
releases := []string{}
ghc := github.NewClient(nil)
ghc := update.GHClient()
opts := &github.ListOptions{PerPage: 100}
for {

View File

@ -52,7 +52,7 @@ type Data struct {
func main() {
releases := []string{}
ghc := github.NewClient(nil)
ghc := update.GHClient()
opts := &github.ListOptions{PerPage: 100}
for {

View File

@ -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}