Skip to content

Commit

Permalink
Merge pull request #3033 from balopat/fix_version_flake
Browse files Browse the repository at this point in the history
Fix check flake by not using Github API
  • Loading branch information
balopat authored Oct 10, 2019
2 parents 9211864 + 89a10e1 commit 565da32
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
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
}

0 comments on commit 565da32

Please sign in to comment.