Skip to content

Commit

Permalink
pkg/build: Properly handle extra version markers
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen Augustus <[email protected]>
  • Loading branch information
justaugustus committed Nov 10, 2020
1 parent 88baedd commit cb5d4df
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
4 changes: 2 additions & 2 deletions cmd/krel/cmd/ci_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
)

Expand Down
4 changes: 2 additions & 2 deletions cmd/krel/cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
)

Expand Down
4 changes: 3 additions & 1 deletion pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pkg/build/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
34 changes: 20 additions & 14 deletions pkg/release/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
}
Expand Down

0 comments on commit cb5d4df

Please sign in to comment.