1313 with-utf8,
1414-}
1515
16- {-# LANGUAGE BlockArguments #-}
17- {-# LANGUAGE GHC2021 #-}
18- {-# LANGUAGE OverloadedStrings #-}
16+ {-# LANGUAGE BlockArguments #-}
17+ {-# LANGUAGE GHC2021 #-}
18+ {-# LANGUAGE OverloadedStrings #-}
1919{-# LANGUAGE ScopedTypeVariables #-}
2020
2121{-# OPTIONS_GHC -Wall -Wextra #-}
@@ -27,6 +27,7 @@ import qualified Control.Foldl as Foldl
2727import Control.Monad
2828import Data.Map (Map )
2929import qualified Data.Map as Map
30+ import Data.Maybe (mapMaybe )
3031import Data.Monoid (First (.. ))
3132import Data.Semigroup (Max (.. ))
3233import qualified Data.Text as Text
@@ -55,10 +56,10 @@ main = withStdTerminalHandles $ sh do
5556
5657 pure (packageName, maxMaybe, dependencies)
5758
58- packageVersions <- reduce Foldl. map do
59- (packageName, maybeSeverity ) <- select $ Map. toList packageChangeSeverities
59+ packageVersions <- reduce Foldl. list do
60+ (packageName, _ ) <- select packages
6061
61- case maybeSeverity of
62+ case join $ Map. lookup packageName packageChangeSeverities of
6263 Nothing -> do
6364 liftIO do
6465 putStrLn $ " No changes need to be made for package " <> packageName <> " !"
@@ -69,22 +70,22 @@ main = withStdTerminalHandles $ sh do
6970
7071 pure (packageName, (currentPackageVersion, nextPackageVersion))
7172
72- void $ liftIO $ flip Map. traverseWithKey packageVersions $ \ package (current, next) -> do
73+ liftIO $ forM_ packageVersions $ \ ( package, (current, next) ) -> do
7374 putStrLn $ package <> " : " <> showVersion current <> " -> " <> showVersion next
7475
7576 unless isDryRun do
7677 unless skipGit do
77- createGitBranch packageVersions
78+ createGitBranch ( Map. fromList packageVersions)
7879
79- (packageName, (current, next)) <- select $ Map. toList packageVersions
80+ (packageName, (current, next)) <- select $ Map. toList ( Map. fromList packageVersions)
8081
8182 if isDryRun
8283 then
8384 liftIO do
8485 putStrLn $ " This is a dry run, so no changes will be made for " <> packageName
8586 else do
86- updateCabalFile packageName current next packageVersions
8787 runScrivCollect packageName next
88+ updateCabalFile packageName current next (Map. fromList packageVersions)
8889 unless skipGit do
8990 createGitCommit packageName next
9091
@@ -226,11 +227,10 @@ updateCabalFile :: FilePath
226227updateCabalFile package current next dependenciesVersions = do
227228 inplace (updateVersion <|> updateDependencies) (package </> package <.> " cabal" )
228229 where
229- versionText = Text. pack . showVersion
230230 updateVersion =
231- replaceIfContains " version:" (versionText current) (versionText next)
231+ replaceIfContains " version:" (consensusVersionTextForCabal current) (consensusVersionTextForCabal next)
232232 updateDependencies = do
233- Map. foldlWithKey (\ pat pkg (i, o) -> replaceIfContains (fromString pkg) (versionText i) (versionText o) <|> pat) empty dependenciesVersions
233+ Map. foldlWithKey (\ pat pkg (i, o) -> replaceIfContains (fromString pkg) (consensusVersionTextForCabal i) (consensusVersionTextForCabal o) <|> pat) empty dependenciesVersions
234234
235235replaceIfContains :: Pattern Text -> Text -> Text -> Pattern Text
236236replaceIfContains t i o = do
@@ -253,6 +253,12 @@ packageNameWithVersion :: FilePath -> Version -> Text
253253packageNameWithVersion package v = Text. pack $
254254 package <> " -" <> showVersion v
255255
256+ consensusVersionTextForCabal :: Version -> Text
257+ consensusVersionTextForCabal Version {versionBranch = vb@ [_zero, _major, _minor, _patch]} =
258+ Text. intercalate " ." . mapMaybe emptyIfZero $ vb
259+ where emptyIfZero n = if n == 0 then Nothing else Just $ Text. pack $ show n
260+ consensusVersionTextForCabal v = Text. pack $ showVersion v
261+
256262-- The following newtypes and instances are only used to pick out the headings
257263-- in the parsed Markdown files and can be safely ignored unless you care about
258264-- the internals of `findChangeSeverity`
0 commit comments