Skip to content

Commit

Permalink
Normalise versions for comparison (#1448)
Browse files Browse the repository at this point in the history
* make sure that `0.4` and `0.4.0.0` are the same

This fixes the issue worked around by 5c509d2 for future releases.
  • Loading branch information
xsebek authored Aug 23, 2023
1 parent 5c509d2 commit 8a17433
Showing 1 changed file with 7 additions and 1 deletion.
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

0 comments on commit 8a17433

Please sign in to comment.