packages feed

hapistrano 0.3.6.1 → 0.3.7.0

raw patch · 7 files changed

+127/−19 lines, 7 filesdep +QuickCheckPVP ok

version bump matches the API change (PVP)

Dependencies added: QuickCheck

API changes (from Hackage documentation)

+ System.Hapistrano.Types: fromMaybeKeepReleases :: Maybe Natural -> Maybe Natural -> Natural
+ System.Hapistrano.Types: fromMaybeReleaseFormat :: Maybe ReleaseFormat -> Maybe ReleaseFormat -> ReleaseFormat
+ System.Hapistrano.Types: instance Data.Aeson.Types.FromJSON.FromJSON System.Hapistrano.Types.ReleaseFormat

Files

CHANGELOG.md view
@@ -1,3 +1,6 @@+## 0.3.7.0+* Read `release-format` and `keep-releases` from the configuration file.+ ## 0.3.6.1 * Loose upper bound for yaml 0.11 
README.md view
@@ -72,6 +72,14 @@   necessary. The platform where Hapistrano is running won't affect the   available options for commands (g.e. A Mac deploying to a Ubuntu machine,   doesn't need this flag)+* `release_format` - The release timestamp format, the+  '--release-format' argument passed via the CLI takes precedence over this+  value. If neither CLI or configuration file value is specified, it defaults+  to 'short'+* `keep_releases` - The number of releases to keep, the+  '--keep-releases' argument passed via the CLI takes precedence over this+  value. If neither CLI or configuration file value is specified, it defaults+  to '5' * `run_locally:`- Instructions to run locally on your machine in the   form of shell commands. Example: @@ -175,7 +183,7 @@  ## Docker -If you would like to use Docker, there is a lightweight image +If you would like to use Docker, there is a lightweight image available on [Docker Hub](https://hub.docker.com/r/stackbuilders/hapistrano/).  ## License
app/Config.hs view
@@ -14,9 +14,11 @@ import           Data.List                  (nubBy) import           Data.Maybe                 (maybeToList) import           Data.Yaml+import           Numeric.Natural import           Path import           System.Hapistrano.Commands-import           System.Hapistrano.Types    (TargetSystem (..))+import           System.Hapistrano.Types    (ReleaseFormat (..),+                                             TargetSystem (..))  -- | Hapistrano configuration typically loaded from @hap.yaml@ file. @@ -46,6 +48,14 @@   , configTargetSystem   :: !TargetSystem   -- ^ Optional parameter to specify the target system. It's GNU/Linux by   -- default+  , configReleaseFormat  :: !(Maybe ReleaseFormat)+  -- ^ The release timestamp format, the '--release-format' argument passed via+  -- the CLI takes precedence over this value. If neither CLI or configuration+  -- file value is specified, it defaults to short+  , configKeepReleases   :: !(Maybe Natural)+  -- ^ The number of releases to keep, the '--keep-releases' argument passed via+  -- the CLI takes precedence over this value. If neither CLI or configuration+  -- file value is specified, it defaults to 5   } deriving (Eq, Ord, Show)  -- | Information about source and destination locations of a file\/directory@@ -78,6 +88,8 @@     configRunLocally  <- o .:? "run_locally" >>=       maybe (return Nothing) (fmap Just . mapM mkCmd)     configTargetSystem <- o .:? "linux" .!= GNULinux+    configReleaseFormat <- o .:? "release_format"+    configKeepReleases <- o .:? "keep_releases"     return Config {..}  instance FromJSON CopyThing where
app/Main.hs view
@@ -38,7 +38,7 @@ -- | Command to execute and command-specific options.  data Command-  = Deploy ReleaseFormat Natural -- ^ Deploy a new release (with timestamp+  = Deploy (Maybe ReleaseFormat) (Maybe Natural) -- ^ Deploy a new release (with timestamp     -- format and how many releases to keep)   | Rollback Natural -- ^ Rollback to Nth previous release @@ -77,17 +77,20 @@  deployParser :: Parser Command deployParser = Deploy-  <$> option pReleaseFormat-  ( long "release-format"-  <> short 'r'-  <> value ReleaseShort-  <> help "Which format release timestamp format to use: ‘long’ or ‘short’, default is ‘short’." )-  <*> option auto-  ( long "keep-releases"-  <> short 'k'-  <> value 5-  <> showDefault-  <> help "How many releases to keep" )+  <$> optional+        ( option pReleaseFormat+            ( long "release-format"+            <> short 'r'+            <> help "Which format release timestamp format to use: ‘long’ or ‘short’, default is ‘short’."+            )+        )+  <*> optional+        ( option auto+            ( long "keep-releases"+            <> short 'k'+            <> help "How many releases to keep, default is '5'"+            )+        )  rollbackParser :: Parser Command rollbackParser = Rollback@@ -130,7 +133,9 @@       hap sshOpts =  do         r <- Hap.runHapistrano sshOpts printFnc $           case optsCommand of-            Deploy releaseFormat n -> do+            Deploy cliReleaseFormat cliKeepReleases -> do+              let releaseFormat = fromMaybeReleaseFormat cliReleaseFormat configReleaseFormat+                  keepReleases = fromMaybeKeepReleases cliKeepReleases configKeepReleases               forM_ configRunLocally Hap.playScriptLocally               release <- case configVcAction of                            True -> Hap.pushRelease (task releaseFormat)@@ -151,7 +156,7 @@               forM_ configBuildScript (Hap.playScript configDeployPath release)               Hap.registerReleaseAsComplete configDeployPath release               Hap.activateRelease configTargetSystem configDeployPath release-              Hap.dropOldReleases configDeployPath n+              Hap.dropOldReleases configDeployPath keepReleases               forM_ configRestartCommand Hap.exec             Rollback n -> do               Hap.rollback configTargetSystem configDeployPath n
hapistrano.cabal view
@@ -1,5 +1,5 @@ name:                hapistrano-version:             0.3.6.1+version:             0.3.7.0 synopsis:            A deployment library for Haskell applications description:   .@@ -50,7 +50,8 @@                      , System.Hapistrano.Commands                      , System.Hapistrano.Core                      , System.Hapistrano.Types-  build-depends:       base               >= 4.8 && < 5.0+  build-depends:       aeson              >= 0.11 && < 1.5+                     , base               >= 4.8 && < 5.0                      , filepath           >= 1.2 && < 1.5                      , formatting         >= 6.2 && < 7.0                      , gitrev             >= 1.2 && < 1.4@@ -104,6 +105,7 @@                      , path               >= 0.5 && < 0.7                      , path-io            >= 1.2 && < 1.5                      , process            >= 1.4 && < 1.7+                     , QuickCheck         >= 2.5.1 && < 3.0                      , temporary          >= 1.1 && < 1.4   if flag(dev)     ghc-options:       -threaded -rtsopts -with-rtsopts=-N -Wall -Werror
spec/System/HapistranoSpec.hs view
@@ -7,6 +7,7 @@ import           Control.Monad import           Control.Monad.Reader import           Data.Maybe                 (catMaybes)+import           Numeric.Natural import           Path import           Path.IO import qualified System.Hapistrano          as Hap@@ -17,6 +18,8 @@ import           System.IO import           Test.Hspec                 hiding (shouldBe, shouldReturn) import qualified Test.Hspec                 as Hspec+import           Test.Hspec.QuickCheck+import           Test.QuickCheck  testBranchName :: String testBranchName = "another_branch"@@ -36,6 +39,48 @@         , "cabal install --only-dependencies -j"         , "cabal build -j" ] +  describe "fromMaybeReleaseFormat" $ do+    context "when the command line value is present" $ do+      context "and the config file value is present" $+        prop "returns the command line value" $+          forAll ((,) <$> arbitraryReleaseFormat <*> arbitraryReleaseFormat) $+            \(rf1, rf2) -> fromMaybeReleaseFormat (Just rf1) (Just rf2) `Hspec.shouldBe` rf1++      context "and the config file value is not present" $+        prop "returns the command line value" $ forAll arbitraryReleaseFormat $ \rf ->+          fromMaybeReleaseFormat (Just rf) Nothing `Hspec.shouldBe` rf++    context "when the command line value is not present" $ do+      context "and the config file value is present" $+        prop "returns the config file value" $ forAll arbitraryReleaseFormat $ \rf ->+          fromMaybeReleaseFormat Nothing (Just rf) `Hspec.shouldBe` rf++      context "and the config file value is not present" $+        it "returns the default value" $+          fromMaybeReleaseFormat Nothing Nothing `Hspec.shouldBe` ReleaseShort+++  describe "fromMaybeKeepReleases" $ do+    context "when the command line value is present" $ do+      context "and the config file value is present" $+        prop "returns the command line value" $+          forAll ((,) <$> arbitraryKeepReleases <*> arbitraryKeepReleases) $+            \(kr1, kr2) -> fromMaybeKeepReleases (Just kr1) (Just kr2) `Hspec.shouldBe` kr1++      context "and the second value is not present" $+        prop "returns the command line value" $ forAll arbitraryKeepReleases $ \kr ->+          fromMaybeKeepReleases (Just kr) Nothing `Hspec.shouldBe` kr++    context "when the command line value is not present" $ do+      context "and the config file value is present" $+        prop "returns the config file value" $ forAll arbitraryKeepReleases $ \kr ->+          fromMaybeKeepReleases Nothing (Just kr) `Hspec.shouldBe` kr++      context "and the config file value is not present" $+        it "returns the default value" $+          fromMaybeKeepReleases Nothing Nothing `Hspec.shouldBe` 5++   around withSandbox $ do     describe "pushRelease" $ do       it "sets up repo all right" $ \(deployPath, repoPath) -> runHap $ do@@ -227,3 +272,9 @@ currentSystem = if os == "linux"                 then GNULinux                 else BSD++arbitraryReleaseFormat :: Gen ReleaseFormat+arbitraryReleaseFormat = elements [ReleaseShort, ReleaseLong]++arbitraryKeepReleases :: Gen Natural+arbitraryKeepReleases = fromInteger . getPositive  <$> arbitrary
src/System/Hapistrano/Types.hs view
@@ -9,6 +9,8 @@ -- -- Type definitions for the Hapistrano tool. +{-# LANGUAGE OverloadedStrings #-}+ module System.Hapistrano.Types   ( Hapistrano   , Failure (..)@@ -22,13 +24,18 @@   , mkRelease   , releaseTime   , renderRelease-  , parseRelease )+  , parseRelease+  , fromMaybeReleaseFormat+  , fromMaybeKeepReleases ) where  import           Control.Applicative import           Control.Monad.Except import           Control.Monad.Reader+import           Data.Aeson+import           Data.Maybe import           Data.Time+import           Numeric.Natural import           Path  -- | Hapistrano monad.@@ -68,6 +75,13 @@   | ReleaseLong  -- ^ Long release path including picoseconds   deriving (Show, Read, Eq, Ord, Enum, Bounded) +instance FromJSON ReleaseFormat where+  parseJSON = withText "release format" $ \t ->+    case t of+      "short" -> return ReleaseShort+      "long"  -> return ReleaseLong+      _       -> fail "expected 'short' or 'long'"+ -- | SSH options.  data SshOptions = SshOptions@@ -124,3 +138,16 @@ releaseFormatShort, releaseFormatLong :: String releaseFormatShort = "%Y%m%d%H%M%S" releaseFormatLong  = "%Y%m%d%H%M%S%q"++-- | Get release format based on the CLI and file configuration values.++fromMaybeReleaseFormat :: Maybe ReleaseFormat -> Maybe ReleaseFormat -> ReleaseFormat+fromMaybeReleaseFormat cliRF configRF = fromMaybe ReleaseShort (cliRF <|> configRF)++-- | Get keep releases based on the CLI and file configuration values.++fromMaybeKeepReleases :: Maybe Natural -> Maybe Natural -> Natural+fromMaybeKeepReleases cliKR configKR = fromMaybe defaultKeepReleases (cliKR <|> configKR)++defaultKeepReleases :: Natural+defaultKeepReleases = 5