git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Add --dry-run option to psc-publish
20209ffHarry Garrood
psc-publish/Main.hs+19−9
@@ -1,19 +1,24 @@
1
1
2module Main where
2module Main where
3
3
4−import Data.Version (showVersion)
4+import Data.Version (Version(..), showVersion)
5import qualified Data.Aeson as A
5import qualified Data.Aeson as A
6import qualified Data.ByteString.Lazy.Char8 as BL
6import qualified Data.ByteString.Lazy.Char8 as BL
7
7
8import Options.Applicative hiding (str)
8import Options.Applicative hiding (str)
9
9
10import qualified Paths_purescript as Paths
10import qualified Paths_purescript as Paths
11−import Language.PureScript.Publish (preparePackage)
11+import Language.PureScript.Publish
12+
13+dryRun :: Parser Bool
14+dryRun = switch $
15+ long "dry-run"
16+ <> help "Produce no output, and don't require a tagged version to be checked out."
12
17
13main :: IO ()
18main :: IO ()
14−main = execParser opts >> publish
19+main = execParser opts >>= publish
15 where
20 where
16− opts = info (version <*> helper) infoModList
21+ opts = info (version <*> helper <*> dryRun) infoModList
17 infoModList = fullDesc <> headerInfo <> footerInfo
22 infoModList = fullDesc <> headerInfo <> footerInfo
18 headerInfo = header "psc-publish - Generates documentation packages for upload to http://pursuit.purescript.org"
23 headerInfo = header "psc-publish - Generates documentation packages for upload to http://pursuit.purescript.org"
19 footerInfo = footer $ "psc-publish " ++ showVersion Paths.version
24 footerInfo = footer $ "psc-publish " ++ showVersion Paths.version
@@ -21,8 +26,13 @@ main = execParser opts >> publish
21 version :: Parser (a -> a)
26 version :: Parser (a -> a)
22 version = abortOption (InfoMsg (showVersion Paths.version)) $ long "version" <> help "Show the version number" <> hidden
27 version = abortOption (InfoMsg (showVersion Paths.version)) $ long "version" <> help "Show the version number" <> hidden
23
28
24−publish :: IO ()
29+publish :: Bool -> IO ()
25−publish = do
30+publish isDryRun =
31+ if isDryRun
32+ then do
33+ let dummyVersion = ("0.0.0", Version [0,0,0] [])
34+ _ <- preparePackage $ defaultPublishOptions { publishGetVersion = return dummyVersion }
35+ putStrLn "Dry run completed, no errors."
36+ else do
26− pkg <- preparePackage
37+ pkg <- preparePackage defaultPublishOptions
27− BL.putStrLn (A.encode pkg)
38+ BL.putStrLn (A.encode pkg)
28−
src/Language/PureScript/Publish.hs+20−6
@@ -5,8 +5,11 @@
5
5
6module Language.PureScript.Publish
6module Language.PureScript.Publish
7 ( preparePackage
7 ( preparePackage
8+ , preparePackage'
8 , PrepareM()
9 , PrepareM()
9 , runPrepareM
10 , runPrepareM
11+ , PublishOptions(..)
12+ , defaultPublishOptions
10 , getVersionFromGitTag
13 , getVersionFromGitTag
11 , getBowerInfo
14 , getBowerInfo
12 , getModulesAndBookmarks
15 , getModulesAndBookmarks
@@ -49,11 +52,22 @@ import qualified Language.PureScript.Docs as D
49import Language.PureScript.Publish.Utils
52import Language.PureScript.Publish.Utils
50import Language.PureScript.Publish.ErrorsWarnings
53import Language.PureScript.Publish.ErrorsWarnings
51
54
55+data PublishOptions = PublishOptions
56+ { -- | How to obtain the version tag and version that the data being
57+ -- generated will refer to.
58+ publishGetVersion :: PrepareM (String, Version)
59+ }
60+
61+defaultPublishOptions :: PublishOptions
62+defaultPublishOptions = PublishOptions
63+ { publishGetVersion = getVersionFromGitTag
64+ }
65+
52-- | Attempt to retrieve package metadata from the current directory.
66-- | Attempt to retrieve package metadata from the current directory.
53-- Calls exitFailure if no package metadata could be retrieved.
67-- Calls exitFailure if no package metadata could be retrieved.
54−preparePackage :: IO D.UploadedPackage
68+preparePackage :: PublishOptions -> IO D.UploadedPackage
55−preparePackage =
69+preparePackage opts =
56− runPrepareM preparePackage'
70+ runPrepareM (preparePackage' opts)
57 >>= either (\e -> printError e >> exitFailure)
71 >>= either (\e -> printError e >> exitFailure)
58 handleWarnings
72 handleWarnings
59 where
73 where
@@ -93,14 +107,14 @@ otherError = throwError . OtherError
93catchLeft :: Applicative f => Either a b -> (a -> f b) -> f b
107catchLeft :: Applicative f => Either a b -> (a -> f b) -> f b
94catchLeft a f = either f pure a
108catchLeft a f = either f pure a
95
109
96−preparePackage' :: PrepareM D.UploadedPackage
110+preparePackage' :: PublishOptions -> PrepareM D.UploadedPackage
97−preparePackage' = do
111+preparePackage' opts = do
98 exists <- liftIO (doesFileExist "bower.json")
112 exists <- liftIO (doesFileExist "bower.json")
99 unless exists (userError BowerJSONNotFound)
113 unless exists (userError BowerJSONNotFound)
100
114
101 pkgMeta <- liftIO (Bower.decodeFile "bower.json")
115 pkgMeta <- liftIO (Bower.decodeFile "bower.json")
102 >>= flip catchLeft (userError . CouldntParseBowerJSON)
116 >>= flip catchLeft (userError . CouldntParseBowerJSON)
103− (pkgVersionTag, pkgVersion) <- getVersionFromGitTag
117+ (pkgVersionTag, pkgVersion) <- publishGetVersion opts
104 pkgGithub <- getBowerInfo pkgMeta
118 pkgGithub <- getBowerInfo pkgMeta
105 (pkgBookmarks, pkgModules) <- getModulesAndBookmarks
119 (pkgBookmarks, pkgModules) <- getModulesAndBookmarks
106
120