Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalise versions for comparison #1448

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Swarm/Version.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ instance Show NewReleaseFailure where
tagToVersion :: String -> Version
tagToVersion = fst . last . readP_to_S parseVersion

-- | Drop trailing zeros from versions so that we can compare them.
normalize :: Version -> Version
normalize (Version ns tags) = Version (dropTrailing0 ns) tags
where
dropTrailing0 = reverse . dropWhile (== 0) . reverse

-- | Get a newer upstream release version.
--
-- This function can fail if the current branch is not main,
Expand All @@ -161,6 +167,6 @@ getNewerReleaseVersion mgi =
getUpVer :: String -> Either NewReleaseFailure String
getUpVer upTag =
let upVer = tagToVersion upTag
in if myVer >= upVer
in if normalize myVer >= normalize upVer
then Left $ OldUpstreamRelease upVer myVer
else Right upTag
Loading