diff --git a/api/types.go b/api/types.go index f20c146d..1bfbf6ac 100644 --- a/api/types.go +++ b/api/types.go @@ -74,6 +74,30 @@ type Release struct { ExternalProjects map[string]ExternalProject `json:"external_projects,omitempty"` } +func (r Release) Validate() error { + if r.Release == "" { + return fmt.Errorf("missing release number") + } + v, err := semver.NewVersion(r.Release) + if err != nil { + return err + } + for _, projects := range r.Projects { + for repoURL, project := range projects { + if project.Tag != nil { + projectVersion, err := semver.NewVersion(*project.Tag) + if err != nil { + return fmt.Errorf("invalid tag for repo %s: %s", repoURL, err) + } + if v.Prerelease() != projectVersion.Prerelease() { + return fmt.Errorf("repo %s uses different prerelease version %s compared to product release number %s", repoURL, *project.Tag, r.Release) + } + } + } + } + return nil +} + /* - Only one pr per published_chart repo - Different chart repos can have different prs diff --git a/cmds/kubedb_create_release.go b/cmds/kubedb_create_release.go index 7ba5cde3..028dcc9c 100644 --- a/cmds/kubedb_create_release.go +++ b/cmds/kubedb_create_release.go @@ -33,6 +33,10 @@ func NewCmdKubeDBCreateRelease() *cobra.Command { DisableAutoGenTag: true, Run: func(cmd *cobra.Command, args []string) { rel := CreateKubeDBReleaseFile() + err := rel.Validate() + if err != nil { + panic(err) + } data, err := lib.MarshalJson(rel) if err != nil { panic(err) diff --git a/cmds/kubevault_create_release.go b/cmds/kubevault_create_release.go index f2288117..d272677d 100644 --- a/cmds/kubevault_create_release.go +++ b/cmds/kubevault_create_release.go @@ -33,6 +33,10 @@ func NewCmdKubeVaultCreateRelease() *cobra.Command { DisableAutoGenTag: true, Run: func(cmd *cobra.Command, args []string) { rel := CreateKubeVaultReleaseFile() + err := rel.Validate() + if err != nil { + panic(err) + } data, err := lib.MarshalJson(rel) if err != nil { panic(err) diff --git a/cmds/kuebform_create_release.go b/cmds/kuebform_create_release.go index f8364b1c..16e5a042 100644 --- a/cmds/kuebform_create_release.go +++ b/cmds/kuebform_create_release.go @@ -33,6 +33,10 @@ func NewCmdKubeformCreateRelease() *cobra.Command { DisableAutoGenTag: true, Run: func(cmd *cobra.Command, args []string) { rel := CreateKubeformReleaseFile() + err := rel.Validate() + if err != nil { + panic(err) + } data, err := lib.MarshalJson(rel) if err != nil { panic(err) diff --git a/cmds/release_run.go b/cmds/release_run.go index e22203f3..42da8691 100644 --- a/cmds/release_run.go +++ b/cmds/release_run.go @@ -97,6 +97,11 @@ func runAutomaton() { panic(err) } + err = release.Validate() + if err != nil { + panic(err) + } + for _, projects := range release.Projects { for repoURL, project := range projects { if project.Tag != nil { diff --git a/cmds/stash_create_release.go b/cmds/stash_create_release.go index 1144e04c..6c0265bc 100644 --- a/cmds/stash_create_release.go +++ b/cmds/stash_create_release.go @@ -33,6 +33,10 @@ func NewCmdStashCreateRelease() *cobra.Command { DisableAutoGenTag: true, Run: func(cmd *cobra.Command, args []string) { rel := CreateStashReleaseFile() + err := rel.Validate() + if err != nil { + panic(err) + } data, err := lib.MarshalJson(rel) if err != nil { panic(err)