1{-# LANGUAGE OverloadedStrings #-}
2import Control.Monad (filterM, when)
3import qualified Data.ByteString.Char8 as S8
4import qualified Data.ByteString.Lazy as L
5import qualified Data.ByteString.Lazy.Char8 as L8
6import Data.List (isInfixOf, isPrefixOf,
8import Network.HTTP.Client
9import Network.HTTP.Client.MultipartFormData
10import System.Directory (doesDirectoryExist,
12import System.Environment (getArgs, getEnv,
14import System.Exit (exitFailure)
15import System.Exit (ExitCode (ExitSuccess))
16import System.FilePath (takeDirectory, (</>))
17import System.Process (createProcess, cwd,
21main = withManager defaultManagerSettings $ \m -> do
23 token <- readFile "/auth-token"
26 [x, y] -> return (x, y)
32 , " <filepath> <alias name>"
36 let uploadDocs = "exclusive" `isInfixOf` alias
37 uploadHackageDistro = alias == "unstable-ghc78-exclusive"
46 req1 <- parseUrl "http://www.stackage.org/upload"
48 [ partBS "alias" $ S8.pack alias
49 , partFileSource "stackage" filepath
51 req2 <- formDataBody formData req1
55 [ ("Authorization", S8.pack token)
56 , ("Accept", "application/json")
57 ] ++ requestHeaders req2
59 , checkStatus = \_ _ _ -> Nothing
64 case lookup "x-stackage-ident" $ responseHeaders res of
66 putStrLn $ "New ident: " ++ S8.unpack snapid
68 Nothing -> error $ "An error occurred: " ++ show res
71 putStrLn "Generating index file"
72 let root = takeDirectory filepath </> "haddock"
73 contents <- getDirectoryContents root
74 dirs <- filterM (\n -> doesDirectoryExist $ root </> n)
75 $ filter (not . ("." `isPrefixOf`))
77 writeFile (root </> "index.html") $ mkIndex (S8.unpack snapid) dirs
78 writeFile (root </> "style.css") styleCss
80 putStrLn "Creating tarball"
81 (Nothing, Nothing, Nothing, ph) <- createProcess
82 (proc "tar" $ "cJf" : "haddock.tar.xz" : "index.html" : "style.css" : dirs)
85 ec <- waitForProcess ph
87 then putStrLn "Haddock tarball generated"
88 else error "Error generating Haddock tarball"
90 putStrLn "Uploading Haddocks"
92 req1 <- parseUrl $ "http://www.stackage.org/upload-haddock/"
95 [ partFileSource "tarball" $ root </> "haddock.tar.xz"
97 req2 <- formDataBody formData req1
101 [ ("Authorization", S8.pack token)
102 , ("Accept", "application/json")
103 ] ++ requestHeaders req2
105 , checkStatus = \_ _ _ -> Nothing
107 httpLbs req3 m >>= print
109 when uploadHackageDistro $ do
110 lbs <- L.readFile $ takeDirectory filepath </> "build-plan.csv"
111 let req = "http://hackage.haskell.org/distro/Stackage/packages.csv"
112 { requestHeaders = [("Content-Type", "text/csv")]
113 , requestBody = RequestBodyLBS $ L.intercalate "\n" $ L8.lines lbs
114 , checkStatus = \_ _ _ -> Nothing
117 httpLbs req m >>= print
119mkIndex :: String -> [String] -> String
120mkIndex snapid dirs = concat
121 [ "<!DOCTYPE html>\n<html lang='en'><head><title>Haddocks index</title>"
122 , "<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css'>"
123 , "<link rel='stylesheet' href='style.css'>"
124 , "<link rel='shortcut icon' href='http://www.stackage.org/static/img/favicon.ico' />"
126 , "<body><div class='container'>"
127 , "<div class='row'><div class='span12 col-md-12'>"
128 , "<h1>Haddock documentation index</h1>"
129 , "<p class='return'><a href=\"http://www.stackage.org/stackage/"
131 , "\">Return to snapshot</a></p><ul>"
132 , concatMap toLI dirs
133 , "</ul></div></div></div></body></html>"
146 [ "@media (min-width: 530px) {"
147 , "ul { -webkit-column-count: 2; -moz-column-count: 2; column-count: 2 }"
149 , "@media (min-width: 760px) {"
150 , "ul { -webkit-column-count: 3; -moz-column-count: 3; column-count: 3 }"
154 , " padding-left: 0;"
155 , " list-style-type: none;"
158 , " background: #f0f0f0;"
159 , " font-family: 'Lato', sans-serif;"
160 , " text-shadow: 1px 1px 1px #ffffff;"
161 , " font-size: 20px;"
162 , " line-height: 30px;"
163 , " padding-bottom: 5em;"
166 , " font-weight: normal;"
168 , " font-size: 45px;"
172 , " font-style: italic;"
175 , " margin-bottom: 1em;"
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