Skip to content

Commit ec60a69

Browse files
committed
pkg/build: Properly handle extra version markers
Signed-off-by: Stephen Augustus <[email protected]>
1 parent 1b31370 commit ec60a69

File tree

5 files changed

+29
-21
lines changed

5 files changed

+29
-21
lines changed

cmd/krel/cmd/ci_build.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ func init() {
117117
"If set, push docker images to specified registry/project",
118118
)
119119

120-
ciBuildCmd.PersistentFlags().StringVar(
120+
ciBuildCmd.PersistentFlags().StringSliceVar(
121121
&ciBuildOpts.ExtraVersionMarkers,
122122
"extra-version-markers",
123-
"",
123+
build.DefaultExtraVersionMarkers,
124124
"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)",
125125
)
126126

cmd/krel/cmd/push.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ func init() {
112112
"If set, push docker images to specified registry/project",
113113
)
114114

115-
pushBuildCmd.PersistentFlags().StringVar(
115+
pushBuildCmd.PersistentFlags().StringSliceVar(
116116
&pushBuildOpts.ExtraVersionMarkers,
117117
"extra-version-markers",
118-
"",
118+
build.DefaultExtraVersionMarkers,
119119
"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)",
120120
)
121121

pkg/build/build.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"github.com/sirupsen/logrus"
2323
)
2424

25+
var DefaultExtraVersionMarkers = []string{}
26+
2527
// Instance is the main structure for creating and pushing builds.
2628
type Instance struct {
2729
opts *Options
@@ -54,7 +56,7 @@ type Options struct {
5456
// Comma separated list which can be used to upload additional version
5557
// files to GCS. The path is relative and is append to a GCS path. (--ci
5658
// only).
57-
ExtraVersionMarkers string
59+
ExtraVersionMarkers []string
5860

5961
// Specify a suffix to append to the upload destination on GCS.
6062
GCSSuffix string

pkg/build/push.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,9 @@ func (bi *Instance) Push() error {
139139
}
140140

141141
// Publish release to GCS
142-
versionMarkers := strings.Split(bi.opts.ExtraVersionMarkers, ",")
142+
extraVersionMarkers := bi.opts.ExtraVersionMarkers
143143
if err := release.NewPublisher().PublishVersion(
144-
bi.opts.BuildType, version, bi.opts.BuildDir, bi.opts.Bucket, versionMarkers,
144+
bi.opts.BuildType, version, bi.opts.BuildDir, bi.opts.Bucket, extraVersionMarkers,
145145
bi.opts.PrivateBucket, bi.opts.Fast,
146146
); err != nil {
147147
return errors.Wrap(err, "publish release")

pkg/release/publish.go

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (*defaultPublisher) GetURLResponse(url string) (string, error) {
7979
// was releaselib.sh: release::gcs::publish_version
8080
func (p *Publisher) PublishVersion(
8181
buildType, version, buildDir, bucket string,
82-
versionMarkers []string,
82+
extraVersionMarkers []string,
8383
privateBucket, fast bool,
8484
) error {
8585
logrus.Info("Publishing version")
@@ -109,42 +109,48 @@ func (p *Publisher) PublishVersion(
109109
return errors.Errorf("invalid version %s", version)
110110
}
111111

112-
var publishFiles []string
112+
var versionMarkers []string
113113
if fast {
114-
publishFiles = append([]string{
115-
releaseType + "-fast",
116-
}, versionMarkers...)
114+
versionMarkers = append(
115+
versionMarkers,
116+
releaseType+"-fast",
117+
)
117118
} else {
118-
publishFiles = append([]string{
119+
versionMarkers = append(
120+
versionMarkers,
119121
releaseType,
120122
fmt.Sprintf("%s-%d", releaseType, sv.Major),
121123
fmt.Sprintf("%s-%d.%d", releaseType, sv.Major, sv.Minor),
122-
}, versionMarkers...)
124+
)
125+
}
126+
127+
if len(extraVersionMarkers) > 0 {
128+
versionMarkers = append(versionMarkers, extraVersionMarkers...)
123129
}
124130

125-
logrus.Infof("Publish version markers: %v", publishFiles)
131+
logrus.Infof("Publish version markers: %v", versionMarkers)
126132
logrus.Infof("Publish official pointer text files to bucket %s", bucket)
127133

128-
for _, file := range publishFiles {
129-
publishFile := filepath.Join(buildType, file+".txt")
134+
for _, file := range versionMarkers {
135+
versionMarker := filepath.Join(buildType, file+".txt")
130136
needsUpdate, err := p.VerifyLatestUpdate(
131-
publishFile, bucket, version,
137+
versionMarker, bucket, version,
132138
)
133139
if err != nil {
134-
return errors.Wrapf(err, "verify latest update for %s", publishFile)
140+
return errors.Wrapf(err, "verify latest update for %s", versionMarker)
135141
}
136142
// If there's a version that's above the one we're trying to release,
137143
// don't do anything, and just try the next one.
138144
if !needsUpdate {
139145
logrus.Infof(
140146
"Skipping %s for %s because it does not need to be updated",
141-
publishFile, version,
147+
versionMarker, version,
142148
)
143149
continue
144150
}
145151

146152
if err := p.PublishToGcs(
147-
publishFile, buildDir, bucket, version, privateBucket,
153+
versionMarker, buildDir, bucket, version, privateBucket,
148154
); err != nil {
149155
return errors.Wrap(err, "publish release to GCS")
150156
}

0 commit comments

Comments
 (0)