Skip to content

Commit

Permalink
update(build/registry): make sure new artifacts requirements contain …
Browse files Browse the repository at this point in the history
…the new `engine_version_semver` key.

All the rules are already modified to contain a semver string

Signed-off-by: Lorenzo Susini <[email protected]>
  • Loading branch information
loresuso authored and poiana committed Nov 7, 2023
1 parent e206c1a commit 8e1ae00
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions build/registry/requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"errors"
"fmt"
"os"
"strconv"
"strings"

"github.com/blang/semver"
Expand All @@ -31,7 +30,7 @@ import (

const (
rulesEngineAnchor = "- required_engine_version"
engineVersionKey = "engine_version"
engineVersionKey = "engine_version_semver"
)

// ErrReqNotFound error when the requirements are not found in the rulesfile.
Expand Down Expand Up @@ -65,13 +64,21 @@ func rulesfileRequirement(filePath string) (*oci.ArtifactRequirement, error) {

// Split the requirement and parse the version to semVer.
tokens := strings.Split(fileScanner.Text(), ":")
reqVer, err := semver.ParseTolerant(tokens[1])
reqVer, err := semver.Parse(tokens[1])
if err != nil {
return nil, fmt.Errorf("unable to parse to semVer the version requirement %q", tokens[1])
reqVer, err = semver.ParseTolerant(tokens[1])
if err != nil {
return nil, fmt.Errorf("unable to parse requirement %q: expected a numeric value or a valid semver string", tokens[1])
}
reqVer = semver.Version{
Major: 0,
Minor: reqVer.Major,
Patch: 0,
}
}

return &oci.ArtifactRequirement{
Name: engineVersionKey,
Version: strconv.FormatUint(reqVer.Major, 10),
Version: reqVer.String(),
}, nil
}

0 comments on commit 8e1ae00

Please sign in to comment.