@@ -14,7 +14,7 @@ import Network.HTTP.Client.TLS (tlsManagerSettings)
14
14
import Network.HTTP.Download (download )
15
15
import Options.Applicative.Simple hiding (action )
16
16
import qualified Pantry
17
- import Path (toFilePath )
17
+ import Path ((</>) , addExtension , toFilePath , Path , Abs , File )
18
18
import Path.IO (doesFileExist , removeFile , resolveFile' , resolveDir' )
19
19
import Paths_curator (version )
20
20
import qualified RIO.ByteString.Lazy as BL
@@ -119,41 +119,60 @@ update = do
119
119
void $ updateHackageIndex $ Just " Updating hackage index"
120
120
121
121
constraints :: Target -> RIO PantryApp ()
122
- constraints target =
123
- case target of
124
- TargetLts x y | y > 0 -> do
125
- let prev = y - 1
126
- url = concat [ " https://raw.githubusercontent.com/" ++ constraintsRepo ++ " /master/lts/"
127
- , show x
128
- , " /"
129
- , show prev
130
- , " .yaml"
131
- ]
132
- logInfo $ " Will reuse constraints.yaml from lts-" <> display x <> " ." <> display prev
133
- req <- parseUrlThrow url
134
- constraintsPath <- resolveFile' constraintsFilename
135
- exists <- doesFileExist constraintsPath
136
- when exists $ do
137
- logWarn " Local constraints file will be deleted before downloading reused constraints"
138
- removeFile constraintsPath
139
- downloaded <- download req constraintsPath
140
- unless downloaded $
141
- error $ " Could not download constraints.yaml from " <> url
142
- _ -> do
143
- buildConstraintsPath <- resolveFile' " build-constraints.yaml"
144
- exists <- doesFileExist buildConstraintsPath
145
- stackageConstraints <- if exists
146
- then do
147
- logInfo " Reusing already existing file build-constraints.yaml"
148
- loadStackageConstraints $ toFilePath buildConstraintsPath
149
- else do
150
- logInfo $ " Downloading build-constraints from commercialhaskell/stackage"
151
- req <- parseUrlThrow " https://raw.githubusercontent.com/commercialhaskell/stackage/master/build-constraints.yaml"
152
- man <- liftIO $ newManager tlsManagerSettings
153
- liftIO (httpLbs req man) >>=
154
- loadStackageConstraintsBs . BL. toStrict . responseBody
155
- logInfo " Writing constraints.yaml"
156
- liftIO $ encodeFile constraintsFilename stackageConstraints
122
+ constraints target = do
123
+ stackageConstraints <- case target of
124
+ TargetNightly _ -> nightlyConstraints
125
+ TargetLts major minor -> ltsConstraints major minor
126
+ logInfo " Writing constraints.yaml"
127
+ liftIO $ encodeFile constraintsFilename stackageConstraints
128
+
129
+ nightlyConstraints = do
130
+ buildConstraintsPath <- resolveFile' " build-constraints.yaml"
131
+ exists <- doesFileExist buildConstraintsPath
132
+ if exists
133
+ then do
134
+ logInfo $ " Reusing already existing file " <> fromString (toFilePath buildConstraintsPath)
135
+ loadStackageConstraints $ toFilePath buildConstraintsPath
136
+ else do
137
+ logInfo $ " Downloading " <> fromString (toFilePath buildConstraintsPath)
138
+ <> " from commercialhaskell/stackage"
139
+ req <- parseUrlThrow $ " https://raw.githubusercontent.com/commercialhaskell/stackage/master/build-constraints.yaml"
140
+ man <- liftIO $ newManager tlsManagerSettings
141
+ liftIO (httpLbs req man) >>= loadStackageConstraintsBs . BL. toStrict . responseBody
142
+
143
+ ltsConstraints major minor = do
144
+ when (minor > 0 ) $ do
145
+ verifyPreviousLtsMinorExists major minor
146
+ let buildConstraintsName = " lts-" <> show major <> " -build-constraints.yaml"
147
+ buildConstraintsPath <- resolveFile' buildConstraintsName
148
+ exists <- doesFileExist buildConstraintsPath
149
+ logInfo $ " Downloading " <> fromString (buildConstraintsName) <> " from commercialhaskell/lts-haskell"
150
+ req <- parseUrlThrow $ " https://raw.githubusercontent.com/commercialhaskell/lts-haskell/lts-build-constraints/build-constraints/" <> buildConstraintsName
151
+ man <- liftIO $ newManager tlsManagerSettings
152
+ liftIO (httpLbs req man) >>= loadStackageConstraintsBs . BL. toStrict . responseBody
153
+
154
+ -- Performs a download of the previous LTS minor just to verify that it has been published.
155
+ verifyPreviousLtsMinorExists :: Int -> Int -> RIO PantryApp ()
156
+ verifyPreviousLtsMinorExists major minor = do
157
+ let prevMinor = minor - 1
158
+ url = concat
159
+ [ " https://raw.githubusercontent.com/" ++ constraintsRepo ++ " /master/lts/"
160
+ , show major
161
+ , " /"
162
+ , show prevMinor
163
+ , " .yaml"
164
+ ]
165
+ -- Hacky, use a presumably unique file name for this download (the file is not used).
166
+ constraintsPath <- addExtension " .previous" =<< resolveFile' constraintsFilename
167
+ exists <- doesFileExist constraintsPath
168
+ when exists $
169
+ removeFile constraintsPath
170
+ logInfo $ " Verifying existance of constraints.yaml from "
171
+ <> " lts-" <> display major <> " ." <> display prevMinor
172
+ req <- parseUrlThrow url
173
+ downloaded <- download req constraintsPath
174
+ unless downloaded $
175
+ error $ " Could not download constraints.yaml from " <> url
157
176
158
177
snapshotIncomplete :: Target -> RIO PantryApp ()
159
178
snapshotIncomplete target = do
0 commit comments