1{-# LANGUAGE NoImplicitPrelude #-}
2{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE RecordWildCards #-}
4module Stackage.CompleteBuild
9import Data.Default.Class (def)
10import Data.Semigroup (Max (..), Option (..))
11import Data.Text.Read (decimal)
13import Data.Yaml (decodeFileEither, encodeFile)
14import Network.HTTP.Client
15import Stackage.BuildConstraints
16import Stackage.BuildPlan
17import Stackage.CheckBuildPlan
18import Stackage.PerformBuild
19import Stackage.Prelude
20import Stackage.ServerBundle
21import Stackage.UpdateBuildPlan
23import System.IO (BufferMode (LineBuffering), hSetBuffering)
25data BuildType = Nightly | LTS BumpType
26 deriving (Show, Read, Eq, Ord)
28data BumpType = Major | Minor
29 deriving (Show, Read, Eq, Ord)
31data Settings = Settings
33 , planFile :: FilePath
34 , buildDir :: FilePath
36 , title :: Text -> Text -- ^ GHC version -> title
38 , setArgs :: Text -> UploadBundle -> UploadBundle
42getSettings :: Manager -> BuildType -> IO Settings
43getSettings man Nightly = do
44 day <- tshow . utctDay <$> getCurrentTime
45 let slug' = "nightly-" ++ day
46 plan' <- defaultBuildConstraints man >>= newBuildPlan
48 { planFile = fpFromText ("nightly-" ++ day) <.> "yaml"
49 , buildDir = fpFromText $ "builds/stackage-nightly-" ++ day
50 , logDir = fpFromText $ "logs/stackage-nightly-" ++ day
51 , title = \ghcVer -> concat
58 , setArgs = \ghcVer ub -> ub { ubNightly = Just ghcVer }
60 , postBuild = return ()
62getSettings man (LTS bumpType) = do
63 Option mlts <- fmap (fmap getMax) $ runResourceT
65 $$ foldMapC (Option . fmap Max . parseLTSVer . filename)
67 (new, plan') <- case bumpType of
72 Just (LTSVer x _) -> LTSVer (x + 1) 0
73 plan' <- defaultBuildConstraints man >>= newBuildPlan
76 old <- maybe (error "No LTS plans found in current directory") return mlts
77 oldplan <- decodeFileEither (fpToString $ renderLTSVer old)
78 >>= either throwM return
79 let new = incrLTSVer old
80 plan' <- updateBuildPlan oldplan
83 let newfile = renderLTSVer new
87 , buildDir = fpFromText $ "builds/stackage-lts-" ++ tshow new
88 , logDir = fpFromText $ "logs/stackage-lts-" ++ tshow new
89 , title = \ghcVer -> concat
95 , slug = "lts-" ++ tshow new
96 , setArgs = \_ ub -> ub { ubLTS = Just $ tshow new }
99 let git args = withCheckedProcess
100 (proc "git" args) $ \ClosedStream Inherited Inherited ->
102 putStrLn "Committing new LTS file to Git"
103 git ["add", fpToString newfile]
104 git ["commit", "-m", "Added new LTS release: " ++ show new]
105 putStrLn "Pushing to Git repository"
109data LTSVer = LTSVer !Int !Int
111instance Show LTSVer where
112 show (LTSVer x y) = concat [show x, ".", show y]
113incrLTSVer :: LTSVer -> LTSVer
114incrLTSVer (LTSVer x y) = LTSVer x (y + 1)
116parseLTSVer :: FilePath -> Maybe LTSVer
118 w <- stripPrefix "lts-" $ fpToText fp
119 x <- stripSuffix ".yaml" w
120 Right (major, y) <- Just $ decimal x
121 z <- stripPrefix "." y
122 Right (minor, "") <- Just $ decimal z
123 return $ LTSVer major minor
124renderLTSVer :: LTSVer -> FilePath
125renderLTSVer lts = fpFromText $ concat
131completeBuild :: BuildType -> IO ()
132completeBuild buildType = withManager defaultManagerSettings $ \man -> do
133 hSetBuffering stdout LineBuffering
135 putStrLn $ "Loading settings for: " ++ tshow buildType
136 Settings {..} <- getSettings man buildType
138 putStrLn $ "Writing build plan to: " ++ fpToText planFile
139 encodeFile (fpToString planFile) plan
141 putStrLn "Checking build plan"
144 putStrLn "Performing build"
145 let pb = PerformBuild
147 , pbInstallDest = buildDir
149 , pbLog = hPut stdout
151 , pbGlobalInstall = False
153 performBuild pb >>= mapM_ putStrLn
155 putStrLn "Uploading bundle to Stackage Server"
156 token <- readFile "/auth-token"
158 let ghcVer = display $ siGhcVersion $ bpSystemInfo plan
159 ident <- flip uploadBundle man $ setArgs ghcVer def
160 { ubContents = serverBundle now (title ghcVer) slug plan
161 , ubAuthToken = decodeUtf8 token
163 putStrLn $ "New ident: " ++ unSnapshotIdent ident
165 putStrLn "Uploading docs to Stackage Server"
166 res1 <- uploadDocs UploadDocs
168 , udAuthToken = decodeUtf8 token
169 , udDocs = pbDocDir pb
172 putStrLn $ "Doc upload response: " ++ tshow res1
174 ecreds <- tryIO $ readFile "/hackage-creds"
175 case map encodeUtf8 $ words $ decodeUtf8 $ either (const "") id ecreds of
176 [username, password] -> do
177 putStrLn "Uploading as Hackage distro"
178 res2 <- uploadHackageDistro plan username password man
179 putStrLn $ "Distro upload response: " ++ tshow res2
180 _ -> putStrLn "No creds found, skipping Hackage distro upload"
182 putStrLn "Uploading doc map"
183 uploadDocMap UploadDocMap
185 , udmAuthToken = decodeUtf8 token
186 , udmSnapshot = ident
187 , udmDocDir = pbDocDir pb
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list