1{-# LANGUAGE NoImplicitPrelude #-}
2{-# LANGUAGE OverloadedStrings #-}
3{-# LANGUAGE RecordWildCards #-}
4module Stackage2.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 Stackage2.BuildConstraints
16import Stackage2.BuildPlan
17import Stackage2.CheckBuildPlan
18import Stackage2.PerformBuild
19import Stackage2.Prelude
20import Stackage2.ServerBundle
21import Stackage2.UpdateBuildPlan
22import Stackage2.Upload
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 :: BuildType -> IO Settings
43getSettings Nightly = do
44 day <- tshow . utctDay <$> getCurrentTime
45 let slug' = "nightly-" ++ day
46 plan' <- defaultBuildConstraints >>= 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 (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 >>= 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 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
152 performBuild pb >>= mapM_ putStrLn
154 putStrLn "Uploading bundle to Stackage Server"
155 token <- readFile "/auth-token"
157 let ghcVer = display $ siGhcVersion $ bpSystemInfo plan
158 ident <- flip uploadBundle man $ setArgs ghcVer def
159 { ubContents = serverBundle now (title ghcVer) slug plan
160 , ubAuthToken = decodeUtf8 token
162 putStrLn $ "New ident: " ++ unSnapshotIdent ident
164 putStrLn "Uploading docs to Stackage Server"
165 res1 <- uploadDocs UploadDocs
167 , udAuthToken = decodeUtf8 token
168 , udDocs = pbDocDir pb
171 putStrLn $ "Doc upload response: " ++ tshow res1
173 ecreds <- tryIO $ readFile "/hackage-creds"
174 case map encodeUtf8 $ words $ decodeUtf8 $ either (const "") id ecreds of
175 [username, password] -> do
176 putStrLn "Uploading as Hackage distro"
177 res2 <- uploadHackageDistro plan username password man
178 putStrLn $ "Distro upload response: " ++ tshow res2
179 _ -> putStrLn "No creds found, skipping Hackage distro upload"
181 putStrLn "Uploading doc map"
182 uploadDocMap UploadDocMap
184 , udmAuthToken = decodeUtf8 token
185 , udmSnapshot = ident
186 , 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