-
Notifications
You must be signed in to change notification settings - Fork 21
/
upload-package.hs
60 lines (55 loc) · 1.81 KB
/
upload-package.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
{- stack --resolver lts-8.0 script
--package aeson
--package bytestring
--package directory
--package filepath
--package process
--package text
-}
import qualified Control.Monad as Monad
import qualified Data.Aeson as Aeson
import qualified Data.ByteString.Lazy as ByteString
import qualified Data.Maybe as Maybe
import qualified Data.Text as Text
import qualified System.Directory as Directory
import qualified System.Environment as Environment
import qualified System.Exit as Exit
import qualified System.FilePath as FilePath
import qualified System.Process as Process
main :: IO ()
main = do
checkTravisTag
checkTravisOsName
directory <- getStackUploadDirectory
credentials <- getHackageCredentials
let file = FilePath.joinPath [directory, "credentials.json"]
Directory.createDirectoryIfMissing True directory
ByteString.writeFile file (Aeson.encode credentials)
Process.callProcess "stack" ["upload", "."]
checkTravisTag :: IO ()
checkTravisTag = do
maybeTag <- Environment.lookupEnv "TRAVIS_TAG"
Monad.when
(Maybe.isNothing maybeTag)
(do putStrLn "The $TRAVIS_TAG variable is empty."
Exit.exitSuccess)
checkTravisOsName :: IO ()
checkTravisOsName = do
maybeOs <- Environment.lookupEnv "TRAVIS_OS_NAME"
Monad.when
(maybeOs /= Just "linux")
(do putStrLn "The $TRAVIS_OS_NAME variable is not 'linux'."
Exit.exitSuccess)
getStackUploadDirectory :: IO FilePath
getStackUploadDirectory = do
home <- Directory.getHomeDirectory
pure (FilePath.joinPath [home, ".stack", "upload"])
getHackageCredentials :: IO Aeson.Value
getHackageCredentials = do
username <- Environment.getEnv "HACKAGE_USERNAME"
password <- Environment.getEnv "HACKAGE_PASSWORD"
pure
(Aeson.object
[ Text.pack "username" Aeson..= username
, Text.pack "password" Aeson..= password
])