11module Spago.PackageSet
22 ( updatePackageSetVersion
3+ , getLatestSetForCompilerVersion
34 , checkPursIsUpToDate
45 , makePackageSetFile
56 , freeze
@@ -13,6 +14,8 @@ import Spago.Env
1314
1415import qualified Control.Exception as Exception
1516import Data.Dynamic (fromDynamic )
17+ import qualified Data.List as List
18+ import qualified Data.Map.Strict as Map
1619import qualified Data.Text as Text
1720import qualified Data.Versions as Version
1821import qualified Dhall.Freeze
@@ -45,6 +48,26 @@ makePackageSetFile force comments = do
4548 else logWarn $ display $ Messages. foundExistingProject packagesPath
4649 Dhall. format packagesPath
4750
51+ getLatestSetForCompilerVersion
52+ :: HasLogFunc env
53+ => Version. SemVer
54+ -> Text
55+ -> Text
56+ -> RIO env (Either SomeException Text )
57+ getLatestSetForCompilerVersion compilerVersion org repo = do
58+ logDebug $ " Got a compiler version: " <> displayShow compilerVersion
59+ -- we first try getting the file with the index of the latest sets
60+ eitherLatestReleases <- try $ GitHub. getLatestReleasesFile org repo
61+ logDebug $ " Latest releases: " <> displayShow eitherLatestReleases
62+ for eitherLatestReleases $ \ latestReleases -> do
63+ -- if we get that, we just try to pick a set for the current compiler
64+ case Map. lookup compilerVersion latestReleases of
65+ -- but if the current compiler is not there we complain about compatibility
66+ Nothing -> die [ display $ Messages. incompatiblePurs (Version. prettySemVer <$> List. reverse (Map. keys latestReleases))]
67+ Just newTag -> do
68+ logDebug $ " Found a new tag in the releases file: " <> display newTag
69+ pure $ newTag
70+
4871-- | Use the specified version of the package set (if specified).
4972-- Otherwise, get the latest version of the package set if possible
5073updatePackageSetVersion
@@ -65,30 +88,37 @@ updatePackageSetVersion maybeTag = do
6588
6689 maybe
6790 (useLatestRelease org repo currentTag)
68- (useSpecificRelease org repo currentTag)
91+ (updateTag org repo currentTag)
6992 maybeTag
7093 where
71- -- | Tries to upgrade the Package-Sets release of the local package set.
72- -- It will:
73- -- - try to read the latest tag from GitHub
74- -- - try to read the current package-set file
75- -- - try to replace the git tag to which the package-set imports point to
76- -- (if they point to the Package-Sets repo. This can be eventually made GitHub generic)
77- -- - if all of this succeeds, it will regenerate the hashes and write to file
94+ -- | Try to fetch the latest compatible tag in various ways, and updates
95+ -- the packages.dhall with it
7896 useLatestRelease
7997 :: Text -> Text -> Text -> RIO env ()
8098 useLatestRelease org repo currentTag = do
81- GitHub. getLatestPackageSetsTag org repo >>= \ case
82- Right tag -> updateTag org repo currentTag tag
83- Left (err :: SomeException ) -> do
84- logWarn " Was not possible to upgrade the package-sets release"
85- logDebug $ " Error: " <> display err
86-
87- useSpecificRelease
88- :: Text -> Text -> Text -> Text -> RIO env ()
89- useSpecificRelease org repo currentTag tag =
90- updateTag org repo currentTag tag
99+ let getLatestFromGitHub = GitHub. getLatestPackageSetsTag org repo >>= \ case
100+ Right tag -> updateTag org repo currentTag tag
101+ Left (err :: SomeException ) -> do
102+ logWarn " Was not possible to upgrade the package-sets release"
103+ logDebug $ " Error: " <> display err
104+ -- first let's get the current compiler version
105+ Purs. pursVersion >>= \ case
106+ Left err -> do
107+ -- if we cannot we just get the latest release from GitHub
108+ logDebug $ display err
109+ getLatestFromGitHub
110+ Right compilerVersion ->
111+ getLatestSetForCompilerVersion compilerVersion org repo >>= \ case
112+ Right newTag -> updateTag org repo currentTag newTag
113+ -- if that fails then we fetch the latest set from GitHub
114+ -- TODO: check that it's compatible with the current compiler
115+ Left _err -> getLatestFromGitHub
91116
117+ -- | Tries to upgrade the package-sets release of the local package set.
118+ -- It will:
119+ -- - try to read the current package-set file
120+ -- - try to replace the git tag to which the package-set imports point to
121+ -- - if all of this succeeds, it will regenerate the hashes and write to file
92122 updateTag :: Text -> Text -> Text -> Text -> RIO env ()
93123 updateTag org repo currentTag specificTag = do
94124 let quotedTag = surroundQuote specificTag
@@ -136,7 +166,7 @@ updatePackageSetVersion maybeTag = do
136166 } = [(org, repo, currentTag)]
137167 getCurrentTag _ = []
138168
139- -- | Given an import and a new purescript/ package-sets tag,
169+ -- | Given an import and a new package-sets tag,
140170 -- upgrades the import to the tag and resets the hash
141171 upgradeImports :: Text -> Text -> Text -> Dhall. Import -> Dhall. Import
142172 upgradeImports org repo newTag (Dhall. Import
0 commit comments