From ec60a695b1098da1312228762eb593aa891a4b5c Mon Sep 17 00:00:00 2001 From: Stephen Augustus Date: Mon, 9 Nov 2020 21:16:53 -0500 Subject: [PATCH] pkg/build: Properly handle extra version markers Signed-off-by: Stephen Augustus --- cmd/krel/cmd/ci_build.go | 4 ++-- cmd/krel/cmd/push.go | 4 ++-- pkg/build/build.go | 4 +++- pkg/build/push.go | 4 ++-- pkg/release/publish.go | 34 ++++++++++++++++++++-------------- 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/cmd/krel/cmd/ci_build.go b/cmd/krel/cmd/ci_build.go index ff57c9d6bf3..f1a0440bff7 100644 --- a/cmd/krel/cmd/ci_build.go +++ b/cmd/krel/cmd/ci_build.go @@ -117,10 +117,10 @@ func init() { "If set, push docker images to specified registry/project", ) - ciBuildCmd.PersistentFlags().StringVar( + ciBuildCmd.PersistentFlags().StringSliceVar( &ciBuildOpts.ExtraVersionMarkers, "extra-version-markers", - "", + build.DefaultExtraVersionMarkers, "Comma separated list which can be used to upload additional version files to GCS. The path is relative and is append to a GCS path. (--ci only)", ) diff --git a/cmd/krel/cmd/push.go b/cmd/krel/cmd/push.go index 35a62d04226..8a85f805472 100644 --- a/cmd/krel/cmd/push.go +++ b/cmd/krel/cmd/push.go @@ -112,10 +112,10 @@ func init() { "If set, push docker images to specified registry/project", ) - pushBuildCmd.PersistentFlags().StringVar( + pushBuildCmd.PersistentFlags().StringSliceVar( &pushBuildOpts.ExtraVersionMarkers, "extra-version-markers", - "", + build.DefaultExtraVersionMarkers, "Comma separated list which can be used to upload additional version files to GCS. The path is relative and is append to a GCS path. (--ci only)", ) diff --git a/pkg/build/build.go b/pkg/build/build.go index 3105b653067..79bf6ce9cb1 100644 --- a/pkg/build/build.go +++ b/pkg/build/build.go @@ -22,6 +22,8 @@ import ( "github.com/sirupsen/logrus" ) +var DefaultExtraVersionMarkers = []string{} + // Instance is the main structure for creating and pushing builds. type Instance struct { opts *Options @@ -54,7 +56,7 @@ type Options struct { // Comma separated list which can be used to upload additional version // files to GCS. The path is relative and is append to a GCS path. (--ci // only). - ExtraVersionMarkers string + ExtraVersionMarkers []string // Specify a suffix to append to the upload destination on GCS. GCSSuffix string diff --git a/pkg/build/push.go b/pkg/build/push.go index a97af5256b5..f492343f6d7 100644 --- a/pkg/build/push.go +++ b/pkg/build/push.go @@ -139,9 +139,9 @@ func (bi *Instance) Push() error { } // Publish release to GCS - versionMarkers := strings.Split(bi.opts.ExtraVersionMarkers, ",") + extraVersionMarkers := bi.opts.ExtraVersionMarkers if err := release.NewPublisher().PublishVersion( - bi.opts.BuildType, version, bi.opts.BuildDir, bi.opts.Bucket, versionMarkers, + bi.opts.BuildType, version, bi.opts.BuildDir, bi.opts.Bucket, extraVersionMarkers, bi.opts.PrivateBucket, bi.opts.Fast, ); err != nil { return errors.Wrap(err, "publish release") diff --git a/pkg/release/publish.go b/pkg/release/publish.go index 0977d576b5d..e4e46c5443c 100644 --- a/pkg/release/publish.go +++ b/pkg/release/publish.go @@ -79,7 +79,7 @@ func (*defaultPublisher) GetURLResponse(url string) (string, error) { // was releaselib.sh: release::gcs::publish_version func (p *Publisher) PublishVersion( buildType, version, buildDir, bucket string, - versionMarkers []string, + extraVersionMarkers []string, privateBucket, fast bool, ) error { logrus.Info("Publishing version") @@ -109,42 +109,48 @@ func (p *Publisher) PublishVersion( return errors.Errorf("invalid version %s", version) } - var publishFiles []string + var versionMarkers []string if fast { - publishFiles = append([]string{ - releaseType + "-fast", - }, versionMarkers...) + versionMarkers = append( + versionMarkers, + releaseType+"-fast", + ) } else { - publishFiles = append([]string{ + versionMarkers = append( + versionMarkers, releaseType, fmt.Sprintf("%s-%d", releaseType, sv.Major), fmt.Sprintf("%s-%d.%d", releaseType, sv.Major, sv.Minor), - }, versionMarkers...) + ) + } + + if len(extraVersionMarkers) > 0 { + versionMarkers = append(versionMarkers, extraVersionMarkers...) } - logrus.Infof("Publish version markers: %v", publishFiles) + logrus.Infof("Publish version markers: %v", versionMarkers) logrus.Infof("Publish official pointer text files to bucket %s", bucket) - for _, file := range publishFiles { - publishFile := filepath.Join(buildType, file+".txt") + for _, file := range versionMarkers { + versionMarker := filepath.Join(buildType, file+".txt") needsUpdate, err := p.VerifyLatestUpdate( - publishFile, bucket, version, + versionMarker, bucket, version, ) if err != nil { - return errors.Wrapf(err, "verify latest update for %s", publishFile) + return errors.Wrapf(err, "verify latest update for %s", versionMarker) } // If there's a version that's above the one we're trying to release, // don't do anything, and just try the next one. if !needsUpdate { logrus.Infof( "Skipping %s for %s because it does not need to be updated", - publishFile, version, + versionMarker, version, ) continue } if err := p.PublishToGcs( - publishFile, buildDir, bucket, version, privateBucket, + versionMarker, buildDir, bucket, version, privateBucket, ); err != nil { return errors.Wrap(err, "publish release to GCS") }