Skip to content

Fix check flake by not using Github API #3033

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions hack/versions/pkg/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ limitations under the License.
package version

import (
"context"
"fmt"
"io/ioutil"
"net/http"
"regexp"
"strings"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/update"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest"
"github.com/google/go-github/github"
"github.com/sirupsen/logrus"
)

Expand All @@ -40,12 +40,10 @@ func GetLatestVersion() (string, bool) {
}

func getLastReleasedConfigVersion() string {
client := github.NewClient(nil)
releases, _, err := client.Repositories.ListReleases(context.Background(), "GoogleContainerTools", "skaffold", &github.ListOptions{})
lastTag, err := update.DownloadLatestVersion()
if err != nil {
logrus.Fatalf("error listing Github releases: %s", err)
logrus.Fatalf("error getting latest version: %s", err)
}
lastTag := *releases[0].TagName
logrus.Infof("last release tag: %s", lastTag)
configURL := fmt.Sprintf("https://raw.githubusercontent.com/GoogleContainerTools/skaffold/%s/pkg/skaffold/schema/latest/config.go", lastTag)
resp, err := http.Get(configURL)
Expand Down
32 changes: 20 additions & 12 deletions pkg/skaffold/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var (
getEnv = os.Getenv
)

const latestVersionURL = "https://storage.googleapis.com/skaffold/releases/latest/VERSION"
const LatestVersionURL = "https://storage.googleapis.com/skaffold/releases/latest/VERSION"

// IsUpdateCheckEnabled returns whether or not the update check is enabled
// It is true by default, but setting it to any other value than true will disable the check
Expand All @@ -60,19 +60,11 @@ func isUpdateCheckEnabledByEnvOrConfig(configfile string) bool {
// and returns it with the current version of Skaffold
func getLatestAndCurrentVersion() (semver.Version, semver.Version, error) {
none := semver.Version{}
resp, err := http.Get(latestVersionURL)
versionString, err := DownloadLatestVersion()
if err != nil {
return none, none, errors.Wrap(err, "getting latest version info from GCS")
return none, none, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return none, none, errors.Wrapf(err, "http %d, error: %s", resp.StatusCode, resp.Status)
}
versionBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return none, none, errors.Wrap(err, "reading version file from GCS")
}
latest, err := version.ParseVersion(string(versionBytes))
latest, err := version.ParseVersion(versionString)
if err != nil {
return none, none, errors.Wrap(err, "parsing latest version from GCS")
}
Expand All @@ -82,3 +74,19 @@ func getLatestAndCurrentVersion() (semver.Version, semver.Version, error) {
}
return latest, current, nil
}

func DownloadLatestVersion() (string, error) {
resp, err := http.Get(LatestVersionURL)
if err != nil {
return "", errors.Wrap(err, "getting latest version info from GCS")
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return "", errors.Wrapf(err, "http %d, error: %s", resp.StatusCode, resp.Status)
}
versionBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", errors.Wrap(err, "reading version file from GCS")
}
return strings.TrimSuffix(string(versionBytes), "\n"), nil
}