Skip to content

Commit

Permalink
Validate release numbers
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Oct 28, 2020
1 parent 254ebb8 commit 02ad15f
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 0 deletions.
24 changes: 24 additions & 0 deletions api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions cmds/kubedb_create_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions cmds/kubevault_create_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions cmds/kuebform_create_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions cmds/release_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions cmds/stash_create_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 02ad15f

Please sign in to comment.