From d15a3df04da7f7c9a5c65a3ece87a304d2441e30 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Mon, 3 Feb 2020 15:20:56 +0100 Subject: [PATCH] Version can be in the process of being released Fixes #3617 Signed-off-by: David Gageot --- hack/versions/cmd/latest/version.go | 4 +- hack/versions/cmd/latest_released/version.go | 4 +- hack/versions/cmd/new/version.go | 3 +- hack/versions/cmd/update_comments/main.go | 7 +- hack/versions/pkg/schema/check.go | 3 +- .../pkg/{version => schema}/version.go | 17 ++++- hack/versions/pkg/version.go | 64 ------------------- 7 files changed, 23 insertions(+), 79 deletions(-) rename hack/versions/pkg/{version => schema}/version.go (83%) delete mode 100644 hack/versions/pkg/version.go diff --git a/hack/versions/cmd/latest/version.go b/hack/versions/cmd/latest/version.go index 7f2f87cc0e6..1b2f3cd5dcd 100644 --- a/hack/versions/cmd/latest/version.go +++ b/hack/versions/cmd/latest/version.go @@ -21,13 +21,13 @@ import ( "github.com/sirupsen/logrus" - "github.com/GoogleContainerTools/skaffold/hack/versions/pkg/version" + "github.com/GoogleContainerTools/skaffold/hack/versions/pkg/schema" ) // Print the latest version released. func main() { logrus.SetLevel(logrus.ErrorLevel) - current, _ := version.GetLatestVersion() + current, _ := schema.GetLatestVersion() fmt.Println(current) } diff --git a/hack/versions/cmd/latest_released/version.go b/hack/versions/cmd/latest_released/version.go index 8f86d9f089e..febc839604b 100644 --- a/hack/versions/cmd/latest_released/version.go +++ b/hack/versions/cmd/latest_released/version.go @@ -22,7 +22,7 @@ import ( "github.com/sirupsen/logrus" - "github.com/GoogleContainerTools/skaffold/hack/versions/pkg/version" + hackschema "github.com/GoogleContainerTools/skaffold/hack/versions/pkg/schema" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema" ) @@ -30,7 +30,7 @@ import ( func main() { logrus.SetLevel(logrus.ErrorLevel) - current, latestIsReleased := version.GetLatestVersion() + current, latestIsReleased := hackschema.GetLatestVersion() if latestIsReleased { fmt.Println(current) diff --git a/hack/versions/cmd/new/version.go b/hack/versions/cmd/new/version.go index d27d68cb08a..086540570d9 100644 --- a/hack/versions/cmd/new/version.go +++ b/hack/versions/cmd/new/version.go @@ -27,7 +27,6 @@ import ( "github.com/sirupsen/logrus" hackschema "github.com/GoogleContainerTools/skaffold/hack/versions/pkg/schema" - "github.com/GoogleContainerTools/skaffold/hack/versions/pkg/version" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/color" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema" ) @@ -39,7 +38,7 @@ func main() { prev := strings.TrimPrefix(schema.SchemaVersions[len(schema.SchemaVersions)-2].APIVersion, "skaffold/") logrus.Infof("Previous Skaffold version: %s", prev) - current, latestIsReleased := version.GetLatestVersion() + current, latestIsReleased := hackschema.GetLatestVersion() if !latestIsReleased { logrus.Fatalf("There is no need to create a new version, %s is still not released", current) diff --git a/hack/versions/cmd/update_comments/main.go b/hack/versions/cmd/update_comments/main.go index 977a5f0c791..1658e4d6c5b 100644 --- a/hack/versions/cmd/update_comments/main.go +++ b/hack/versions/cmd/update_comments/main.go @@ -24,17 +24,16 @@ import ( "github.com/sirupsen/logrus" - "github.com/GoogleContainerTools/skaffold/hack/versions/pkg/schema" - "github.com/GoogleContainerTools/skaffold/hack/versions/pkg/version" + hackschema "github.com/GoogleContainerTools/skaffold/hack/versions/pkg/schema" ) func main() { schemaDir := path.Join("pkg", "skaffold", "schema") - _, isReleased := version.GetLatestVersion() + _, isReleased := hackschema.GetLatestVersion() if err := filepath.Walk(schemaDir, func(path string, info os.FileInfo, err error) error { if info.Name() == "config.go" { released := !strings.Contains(path, "latest") || isReleased - return schema.UpdateVersionComment(path, released) + return hackschema.UpdateVersionComment(path, released) } return nil }); err != nil { diff --git a/hack/versions/pkg/schema/check.go b/hack/versions/pkg/schema/check.go index 88406652027..6eeef0b2b8f 100644 --- a/hack/versions/pkg/schema/check.go +++ b/hack/versions/pkg/schema/check.go @@ -27,7 +27,6 @@ import ( "github.com/sirupsen/logrus" "github.com/GoogleContainerTools/skaffold/hack/versions/pkg/diff" - "github.com/GoogleContainerTools/skaffold/hack/versions/pkg/version" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/color" ) @@ -92,7 +91,7 @@ func RunSchemaCheckOnChangedFiles() error { } logrus.Infof("structural changes in latest config, checking on Github if latest is released...") - latestVersion, isReleased := version.GetLatestVersion() + latestVersion, isReleased := GetLatestVersion() if !isReleased { color.Green.Fprintf(os.Stdout, "%s is unreleased, it is safe to change it.\n", latestVersion) continue diff --git a/hack/versions/pkg/version/version.go b/hack/versions/pkg/schema/version.go similarity index 83% rename from hack/versions/pkg/version/version.go rename to hack/versions/pkg/schema/version.go index c0843929b60..bdcce8bd44d 100644 --- a/hack/versions/pkg/version/version.go +++ b/hack/versions/pkg/schema/version.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package version +package schema import ( "fmt" @@ -32,9 +32,20 @@ import ( func GetLatestVersion() (string, bool) { current := strings.TrimPrefix(latest.Version, "skaffold/") logrus.Infof("Current Skaffold version: %s", current) - logrus.Infof("checking for released status of %s...", current) + + config, err := ioutil.ReadFile("pkg/skaffold/schema/latest/config.go") + if err != nil { + logrus.Fatalf("failed to read latest config: %s", err) + } + + if strings.Contains(string(config), "This config version is already released") { + return current, true + } + + logrus.Infof("Checking for released status of %s...", current) lastReleased := getLastReleasedConfigVersion() - logrus.Infof("last released version: %s", lastReleased) + logrus.Infof("Last released version: %s", lastReleased) + latestIsReleased := lastReleased == current return current, latestIsReleased } diff --git a/hack/versions/pkg/version.go b/hack/versions/pkg/version.go deleted file mode 100644 index 5153c9bbf75..00000000000 --- a/hack/versions/pkg/version.go +++ /dev/null @@ -1,64 +0,0 @@ -/* -Copyright 2019 The Skaffold Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package version - -import ( - "context" - "fmt" - "io/ioutil" - "net/http" - "regexp" - "strings" - - "github.com/google/go-github/github" - "github.com/sirupsen/logrus" - - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" -) - -func GetLatestVersion() (string, bool) { - current := strings.TrimPrefix(latest.Version, "skaffold/") - logrus.Infof("Current Skaffold version: %s", current) - logrus.Infof("checking for released status of %s...", current) - lastReleased := getLastReleasedConfigVersion() - logrus.Infof("last released version: %s", lastReleased) - latestIsReleased := lastReleased == current - return current, latestIsReleased -} - -func getLastReleasedConfigVersion() string { - client := github.NewClient(nil) - releases, _, err := client.Repositories.ListReleases(context.Background(), "GoogleContainerTools", "skaffold", &github.ListOptions{}) - if err != nil { - logrus.Fatalf("error listing Github releases: %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) - if err != nil { - logrus.Fatalf("can't determine latest released config version, failed to download %s: %s", configURL, err) - } - defer resp.Body.Close() - config, err := ioutil.ReadAll(resp.Body) - if err != nil { - logrus.Fatalf("failed to read during download %s, err: %s", configURL, err) - } - versionPattern := regexp.MustCompile("const Version string = \"skaffold/(.*)\"") - lastReleased := versionPattern.FindStringSubmatch(string(config))[1] - return lastReleased -}