Skip to content

Commit 3b0e46a

Browse files
authored
Fix create-release.hs script (#1355)
This PR fixes the `./scripts/release/create-release.hs` script to: - traverse packages in prescribed order - do not include zeros in version patterns for dependencies When cutting the previous release (#1354), I've noticed that the scripts does not update the dependencies in the `.cabal` files. This was due to traversing the packages in a wrong order because of storing them in `Data.Map` and also because of a quirk in the version patterns. I've verified that the updated scripts has the expected behaviour on on the repo state pre #1354. I do not think it's worth it to add tests for the script. Hopefully, I have only fixed bugs and not introduced new ones!
2 parents e924f61 + d16c49a commit 3b0e46a

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

scripts/release/create-release.hs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
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
2727
import Control.Monad
2828
import Data.Map (Map)
2929
import qualified Data.Map as Map
30+
import Data.Maybe (mapMaybe)
3031
import Data.Monoid (First (..))
3132
import Data.Semigroup (Max (..))
3233
import 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
226227
updateCabalFile 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

235235
replaceIfContains :: Pattern Text -> Text -> Text -> Pattern Text
236236
replaceIfContains t i o = do
@@ -253,6 +253,12 @@ packageNameWithVersion :: FilePath -> Version -> Text
253253
packageNameWithVersion 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

Comments
 (0)