Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/krel/cmd/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"strings"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

Expand Down Expand Up @@ -132,7 +133,13 @@ func init() {
func runRelease(options *anago.ReleaseOptions) error {
options.NoMock = rootOpts.nomock
rel := anago.NewRelease(options)

if submitJob {
// Perform a local check of the specified options
// before launching a Cloud Build job:
if err := options.Validate(&anago.State{}); err != nil {
return errors.Wrap(err, "prechecking release options")
}
return rel.Submit(stream)
}
return rel.Run()
Expand Down
9 changes: 9 additions & 0 deletions pkg/anago/anago.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ func (o *Options) Validate(state *State) error {
return errors.Errorf("invalid release branch: %s", o.ReleaseBranch)
}

// Verify the build version is correct:
correct, err := release.IsValidReleaseBuild(o.BuildVersion)
if err != nil {
return errors.Wrap(err, "checking for a valid build version")
}
if !correct {
return errors.New("invalid BuildVersion specified")
}

semverBuildVersion, err := util.TagStringToSemver(o.BuildVersion)
if err != nil {
return errors.Wrapf(err, "invalid build version: %s", o.BuildVersion)
Expand Down
4 changes: 4 additions & 0 deletions pkg/release/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,10 @@ func ReadDockerizedVersion(workDir string) (string, error) {

// IsValidReleaseBuild checks if build version is valid for release.
func IsValidReleaseBuild(build string) (bool, error) {
// If the tag has a plus sign, then we force the versionBuildRe to match
if strings.Contains(build, "+") {
return regexp.MatchString("("+versionReleaseRE+`(\.`+versionBuildRE+")"+versionDirtyRE+"?)", build)
}
return regexp.MatchString("("+versionReleaseRE+`(\.`+versionBuildRE+")?"+versionDirtyRE+"?)", build)
}

Expand Down
17 changes: 17 additions & 0 deletions pkg/release/release_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,23 @@ func TestIsValidReleaseBuild(t *testing.T) {
rErr: false,
},
},
"InvalidCopiedBuild": {
// This trimmed tag often gets copied when double clicking
// on the CloudBuild console:
build: "v1.22.0-alpha.0.787+e6",
want: want{
r: false,
rErr: false,
},
},
"ValidCopiedBuild": {
// Full tag from previous test case:
build: "v1.22.0-alpha.0.787+e6b4fa381152d6",
want: want{
r: true,
rErr: false,
},
},
}

for name, tc := range cases {
Expand Down