generated from layer5io/layer5-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #514 from MUzairS15/designs/version
Add utils to increment and assign semver version to designs.
- Loading branch information
Showing
4 changed files
with
64 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package patterns | ||
|
||
import "github.com/layer5io/meshkit/errors" | ||
|
||
const ( | ||
ErrInvalidVersionCode = "" | ||
) | ||
|
||
func ErrInvalidVersion(err error) error { | ||
return errors.New(ErrInvalidVersionCode, errors.Alert, []string{"invalid/incompatible semver version"}, []string{err.Error()}, []string{"version history for the content has been tampered outside meshery"}, []string{"rolllback to one of the previous version"}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package patterns | ||
|
||
import ( | ||
"github.com/Masterminds/semver/v3" | ||
"github.com/layer5io/meshkit/utils" | ||
"github.com/meshery/schemas/models/patterns" | ||
"gopkg.in/yaml.v2" | ||
) | ||
|
||
func GetNextVersion(p *patterns.PatternFile) (string, error) { | ||
// Existing patterns do not have version hence when trying to assign next version for such patterns, it will fail the validation. | ||
// Hence, if version is not present, start versioning for those afresh. | ||
if p.Version == "" { | ||
AssignVersion(p) | ||
return p.Version, nil | ||
} | ||
version, err := semver.NewVersion(p.Version) | ||
if err != nil { | ||
return "", err | ||
// return ErrInvalidVersion(err) // send meshkit error | ||
} | ||
|
||
nextVersion := version.IncPatch().String() | ||
return nextVersion, nil | ||
} | ||
|
||
func AssignVersion(p *patterns.PatternFile) { | ||
p.Version = semver.New(0, 0, 1, "", "").String() | ||
} | ||
|
||
func GetPatternFormat(patternFile string) (*patterns.PatternFile, error) { | ||
pattern := patterns.PatternFile{} | ||
err := yaml.Unmarshal([]byte(patternFile), &pattern) | ||
if err != nil { | ||
err = utils.ErrDecodeYaml(err) | ||
return nil, err | ||
} | ||
return &pattern, nil | ||
} |