From 1316c0042c6338a5e9c041fe1885200c03550101 Mon Sep 17 00:00:00 2001 From: balopat Date: Thu, 12 Sep 2019 00:27:12 -0700 Subject: [PATCH 1/2] refactored new_config in preparation for schema change checks --- hack/new_version.sh | 4 +- .../version.go => versions/cmd/new/new.go} | 40 ++---------- hack/versions/pkg/version/version.go | 64 +++++++++++++++++++ 3 files changed, 72 insertions(+), 36 deletions(-) rename hack/{new_config_version/version.go => versions/cmd/new/new.go} (76%) create mode 100644 hack/versions/pkg/version/version.go diff --git a/hack/new_version.sh b/hack/new_version.sh index 5130b62bd40..01bbcd29782 100755 --- a/hack/new_version.sh +++ b/hack/new_version.sh @@ -16,7 +16,7 @@ set -e -go run ./hack/new_config_version/version.go $@ +go run ./hack/versions/cmd/new/version.go $@ goimports -w ./pkg/skaffold/schema make generate-schemas @@ -26,7 +26,7 @@ make test echo echo "---------------------------------------" echo -echo "Files generated for $NEW_VERSION." +echo "Files generated for the new version." echo "All tests should have passed. For the docs change, commit the results and rerun 'make test'." echo "Please double check manually the generated files as well: the upgrade functionality, and all the examples:" echo diff --git a/hack/new_config_version/version.go b/hack/versions/cmd/new/new.go similarity index 76% rename from hack/new_config_version/version.go rename to hack/versions/cmd/new/new.go index 546db4ea8da..091a2eef2b4 100644 --- a/hack/new_config_version/version.go +++ b/hack/versions/cmd/new/new.go @@ -18,21 +18,15 @@ package main import ( "bufio" - "context" - "fmt" "io/ioutil" - "net/http" "os" "path/filepath" "regexp" "strings" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" - + "github.com/GoogleContainerTools/skaffold/hack/versions/pkg/version" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/color" - "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema" - "github.com/google/go-github/github" "github.com/sirupsen/logrus" ) @@ -42,14 +36,10 @@ func main() { logrus.SetLevel(logrus.DebugLevel) prev := strings.TrimPrefix(schema.SchemaVersions[len(schema.SchemaVersions)-2].APIVersion, "skaffold/") logrus.Infof("Previous Skaffold version: %s", prev) - current := strings.TrimPrefix(latest.Version, "skaffold/") - logrus.Infof("Current Skaffold version: %s", current) - next := readNextVersion() - logrus.Infof("checking for released status of %s...", prev) - lastReleased := getLastReleasedConfigVersion() - logrus.Infof("last released version: %s", lastReleased) - if lastReleased != current { + current, latestIsReleased := version.GetLatestVersion() + + if !latestIsReleased { logrus.Fatalf("There is no need to create a new version, %s is still not released", current) } @@ -62,6 +52,8 @@ func main() { } }) + next := readNextVersion() + // Create code to upgrade from current to new cp(path(prev, "upgrade.go"), path(current, "upgrade.go")) sed(path(current, "upgrade.go"), current, next) @@ -101,26 +93,6 @@ func main() { sed("docs/config.toml", current, next) } -func getLastReleasedConfigVersion() string { - client := github.NewClient(nil) - releases, _, _ := client.Repositories.ListReleases(context.Background(), "GoogleContainerTools", "skaffold", &github.ListOptions{}) - 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 -} - func makeSchemaDir(new string) { latestDir, _ := os.Stat(path("latest")) newDirPath := path(new) diff --git a/hack/versions/pkg/version/version.go b/hack/versions/pkg/version/version.go new file mode 100644 index 00000000000..cbebe5c4ff9 --- /dev/null +++ b/hack/versions/pkg/version/version.go @@ -0,0 +1,64 @@ +/* +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/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" + + "github.com/google/go-github/github" + "github.com/sirupsen/logrus" +) + +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 +} From 9f08ab900bf4951bab1b043a79c8d0131ada83ae Mon Sep 17 00:00:00 2001 From: balopat Date: Thu, 12 Sep 2019 00:31:17 -0700 Subject: [PATCH 2/2] goimports --- hack/versions/pkg/version/version.go | 1 - 1 file changed, 1 deletion(-) diff --git a/hack/versions/pkg/version/version.go b/hack/versions/pkg/version/version.go index cbebe5c4ff9..f045b9f319c 100644 --- a/hack/versions/pkg/version/version.go +++ b/hack/versions/pkg/version/version.go @@ -25,7 +25,6 @@ import ( "strings" "github.com/GoogleContainerTools/skaffold/pkg/skaffold/schema/latest" - "github.com/google/go-github/github" "github.com/sirupsen/logrus" )