Skip to content

Commit

Permalink
ES-3193 : fixing semver 2 (#471)
Browse files Browse the repository at this point in the history
* This is even worse spaghetti

* filter out prerelease

* prerelease doesn't make sense for orbs imo
  • Loading branch information
Andrei-Predoiu authored Jul 23, 2024
1 parent b76dc91 commit 5a2e281
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 6 deletions.
14 changes: 11 additions & 3 deletions circleci/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func findNewestDockerVersion(currentVersion string, parameters *map[string]*yaml
}

}

currentv, _ := version.NewVersion(versionParts["version"])
errorList := []string{}
versions := []*version.Version{}
for _, raw := range newTagsList {
Expand All @@ -97,6 +97,15 @@ func findNewestDockerVersion(currentVersion string, parameters *map[string]*yaml
continue
}

if len(v.Prerelease()) > 0 {
log.Debug().Msgf("version %s skipped, prerelease", v.Original())
continue
}
if trimmed := TrimSemver(currentv.Original(), v.Original()); len(trimmed) != len(v.Original()) {
log.Debug().Msgf("version %s skipped, must have the same ammount of segments as old version %s", v.Original(), currentv.Original())
continue
}

versions = append(versions, v)
}

Expand All @@ -108,12 +117,11 @@ func findNewestDockerVersion(currentVersion string, parameters *map[string]*yaml

newest := versions[len(versions)-1]

currentv, _ := version.NewVersion(versionParts["version"])
if currentv.GreaterThan(newest) {
cache[currentVersion] = currentTag
return imageName, currentTag, currentTag
}
newVersion := TrimSemver(currentTag, newest.Original())
newVersion := newest.Original()
cache[currentVersion] = newVersion
return imageName, currentTag, newVersion
}
Expand Down
17 changes: 14 additions & 3 deletions circleci/orb.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package circleci

import (
"fmt"
"github.com/hashicorp/go-version"
"net/http"
"strings"

Expand Down Expand Up @@ -52,6 +53,12 @@ func findNewestOrbVersion(currentVersion string, parameters *map[string]*yaml.No
currentTag = paramDefault.Value
}

currentTagParsed, err := version.NewVersion(currentTag)
if err != nil {
log.Error().Err(err).Msgf("error parsing current version for orb: %s", orbSplitString[0])
return orbName, currentTag, currentTag
}

CCIApiToken := ""
if config.AppConfig.BestsellerSpecific.Running {
log.Debug().Msg("Using Bestseller specific token to handle private orbs")
Expand All @@ -66,13 +73,17 @@ func findNewestOrbVersion(currentVersion string, parameters *map[string]*yaml.No
log.Error().Err(err).Msgf("error finding latests orb version failed for orb: %s", orbSplitString[0])
return orbName, currentTag, currentTag
}

if len(orbInfo.Orb.HighestVersion) == 0 || strings.HasPrefix(orbInfo.Orb.HighestVersion, currentTag) {
highestVersion, err := version.NewVersion(orbInfo.Orb.HighestVersion)
if err != nil {
log.Error().Err(err).Msgf("error parsing highest version for orb: %s", orbSplitString[0])
return orbName, currentTag, currentTag
}
if currentTagParsed.GreaterThan(highestVersion) {
cache[currentVersion] = currentTag
return orbName, currentTag, currentTag
}

newVersion := TrimSemver(currentTag, orbInfo.Orb.HighestVersion)
newVersion := TrimSemver(currentTag, highestVersion.Original())
cache[currentVersion] = newVersion
return orbName, currentTag, newVersion
}

0 comments on commit 5a2e281

Please sign in to comment.