@@ -0,0 +1,88 @@
1+{-# LANGUAGE NoImplicitPrelude #-}
2+{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE RecordWildCards #-}
4+module Stackage2.CompleteBuild
8+import Data.Default.Class (def)
10+import Data.Yaml (encodeFile)
11+import Network.HTTP.Client
12+import Stackage2.BuildConstraints
13+import Stackage2.BuildPlan
14+import Stackage2.CheckBuildPlan
15+import Stackage2.PerformBuild
16+import Stackage2.Prelude
17+import Stackage2.ServerBundle
18+import Stackage2.UpdateBuildPlan
19+import Stackage2.Upload
20+import System.IO (BufferMode (LineBuffering), hSetBuffering)
22+data BuildType = Nightly | LTS
24+data Settings = Settings
26+ , planFile :: FilePath
27+ , buildDir :: FilePath
28+ , title :: Text -> Text -- ^ GHC version -> title
30+ , setArgs :: Text -> UploadBundle -> UploadBundle
33+getSettings :: BuildType -> IO Settings
34+getSettings Nightly = do
35+ day <- tshow . utctDay <$> getCurrentTime
36+ let slug' = "nightly-" ++ day
37+ plan' <- defaultBuildConstraints >>= newBuildPlan
39+ { planFile = fpFromText ("nightly-" ++ day) <.> "yaml"
40+ , buildDir = fpFromText $ "/tmp/stackage-nightly-" ++ day
41+ , title = \ghcVer -> concat
42+ [ "Stackage Nightly "
48+ , setArgs = \ghcVer ub -> ub { ubNightly = Just ghcVer }
52+completeBuild :: BuildType -> IO ()
53+completeBuild buildType = withManager defaultManagerSettings $ \man -> do
54+ hSetBuffering stdout LineBuffering
56+ Settings {..} <- getSettings buildType
57+ encodeFile (fpToString planFile) plan
59+ let pb = PerformBuild
61+ , pbInstallDest = buildDir
62+ , pbLogDir = buildDir </> "logs"
63+ , pbLog = hPut stdout
68+ token <- readFile "/auth-token"
70+ let ghcVer = display $ siGhcVersion $ bpSystemInfo plan
71+ ident <- flip uploadBundle man $ setArgs ghcVer def
72+ { ubContents = serverBundle now (title ghcVer) slug plan
73+ , ubAuthToken = decodeUtf8 token
74+ , ubAlias = Just slug
77+ uploadDocs UploadDocs
79+ , udAuthToken = decodeUtf8 token
80+ , udDocs = pbDocDir pb
84+ creds <- readFile "/hackage-creds"
85+ case map encodeUtf8 $ words $ decodeUtf8 creds of
86+ [username, password] ->
87+ uploadHackageDistro plan username password man >>= print