packages feed

hapistrano 0.3.2.4 → 0.3.3.0

raw patch · 7 files changed

+61/−6 lines, 7 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ System.Hapistrano: playScriptLocally :: [GenericCommand] -> Hapistrano ()

Files

CHANGELOG.md view
@@ -1,3 +1,8 @@+## 0.3.3.0++* Correct bounds for base. GHC support for versions older than 7.10 was dropped on 0.3.0.0+* Add `run_locally` to run user defined commands locally before deployment. Thanks to Sibi (GitHub: psibi) for this contribution+ ## 0.3.2.4  * Allow time 1.8
README.md view
@@ -66,6 +66,21 @@ * `vc_action` - Controls if version control related activity should   take place. It defaults to true. When you don't want activity like   cloning, fetching etc. to take place, set this to `false`.+* `run_locally:`- Instructions to run locally on your machine in the+  form of shell commands. Example:++```+run_locally:+  - pwd+  - bash deploy.sh+```++Note how we are even able to execute a bash script named `deploy.sh`+above. Be sure to use `set -e` in your bash script to avoid+headaches. Hapistrano will stop the execution on non zero exit+codes. Without the usage of `set -e`, there is a possiblity that your+bash script may return a zero exit code even if your intermediate+command resulted in an error.  After creating a configuration file as above, deploying is as simple as: 
app/Config.hs view
@@ -36,6 +36,7 @@     -- ^ Collection of directories to copy over to target machine before building   , configVcAction :: !Bool   -- ^ Perform version control related actions. By default, it's assumed to be True.+  , configRunLocally :: !(Maybe [GenericCommand])   } deriving (Eq, Ord, Show)  -- | Information about source and destination locations of a file\/directory@@ -65,6 +66,8 @@     configCopyFiles  <- o .:? "copy_files" .!= []     configCopyDirs   <- o .:? "copy_dirs"  .!= []     configVcAction    <- o .:? "vc_action" .!= True+    configRunLocally  <- o .:? "run_locally" >>= +      maybe (return Nothing) (fmap Just . mapM mkCmd)     return Config {..}  instance FromJSON CopyThing where
app/Main.hs view
@@ -132,6 +132,7 @@             r <- Hap.runHapistrano sshOpts printFnc $               case optsCommand of                 Deploy releaseFormat n -> do+                  forM_ configRunLocally Hap.playScriptLocally                   release <- case configVcAction of                                True -> Hap.pushRelease (task releaseFormat)                                False -> Hap.pushReleaseWithoutVc (task releaseFormat)
hapistrano.cabal view
@@ -1,5 +1,5 @@ name:                hapistrano-version:             0.3.2.4+version:             0.3.3.0 synopsis:            A deployment library for Haskell applications description:   .@@ -43,7 +43,7 @@                      , System.Hapistrano.Commands                      , System.Hapistrano.Core                      , System.Hapistrano.Types-  build-depends:       base               >= 4.6 && < 5.0+  build-depends:       base               >= 4.8 && < 5.0                      , filepath           >= 1.2 && < 1.5                      , mtl                >= 2.0 && < 3.0                      , path               >= 0.5 && < 0.7@@ -63,7 +63,7 @@                      , Paths_hapistrano   build-depends:       aeson              >= 0.11 && < 1.3                      , async              >= 2.0.1.6 && < 2.2-                     , base               >= 4.6 && < 5.0+                     , base               >= 4.8 && < 5.0                      , hapistrano                      , optparse-applicative >= 0.11 && < 0.15                      , path               >= 0.5 && < 0.7@@ -81,7 +81,7 @@   hs-source-dirs:      spec   main-is:             Spec.hs   other-modules:       System.HapistranoSpec-  build-depends:       base               >= 4.5 && < 5.0+  build-depends:       base               >= 4.8 && < 5.0                      , directory          >= 1.2.2 && < 1.4                      , filepath           >= 1.2 && < 1.5                      , hapistrano
spec/System/HapistranoSpec.hs view
@@ -8,6 +8,7 @@ import Control.Monad.Reader import Path import Path.IO+import Data.Maybe (catMaybes) import System.Hapistrano.Types import System.IO import Test.Hspec hiding (shouldBe, shouldReturn)@@ -19,7 +20,7 @@ spec :: Spec spec = do   describe "readScript" $-    it "preforms all the necessary normalizations correctly" $ do+    it "performs all the necessary normalizations correctly" $ do       spath <- makeAbsolute $(mkRelFile "script/clean-build.sh")       (fmap Hap.unGenericCommand <$> Hap.readScript spath)         `Hspec.shouldReturn`@@ -58,6 +59,23 @@             rc = Hap.Readlink (Hap.currentSymlinkPath deployPath)         Hap.exec rc `shouldReturn` rpath         doesFileExist (Hap.tempSymlinkPath deployPath) `shouldReturn` False+        +    describe "playScriptLocally (successful run)" $+       it "check that local scripts are run and deployment is successful" $ \(deployPath, repoPath) -> runHap $ do+        let localCommands = catMaybes $ map Hap.mkGenericCommand ["pwd", "ls"]+            task = mkTask deployPath repoPath+        Hap.playScriptLocally localCommands+        release <- Hap.pushRelease task+        Hap.registerReleaseAsComplete deployPath release+        (Hap.ctokenPath deployPath release >>= doesFileExist) `shouldReturn` True++    describe "playScriptLocally (error exit)" $+       it "check that deployment isn't done" $ \(deployPath, repoPath) -> (runHap $ do+        let localCommands = catMaybes $ map Hap.mkGenericCommand ["pwd", "ls", "false"]+            task = mkTask deployPath repoPath+        Hap.playScriptLocally localCommands+        release <- Hap.pushRelease task+        Hap.registerReleaseAsComplete deployPath release) `shouldThrow` anyException      describe "rollback" $ do       context "without completion tokens" $
src/System/Hapistrano.hs view
@@ -22,6 +22,7 @@   , rollback   , dropOldReleases   , playScript+  , playScriptLocally     -- * Path helpers   , releasePath   , currentSymlinkPath@@ -40,6 +41,7 @@ import System.Hapistrano.Commands import System.Hapistrano.Core import System.Hapistrano.Types+import Control.Monad.Reader (local)  ---------------------------------------------------------------------------- -- High-level functionality@@ -123,7 +125,7 @@     cpath <- ctokenPath  deployPath release     exec (Rm cpath) --- | Play the given script switching to diroctory of given release.+-- | Play the given script switching to directory of given release.  playScript   :: Path Abs Dir      -- ^ Deploy path@@ -133,6 +135,17 @@ playScript deployDir release cmds = do   rpath <- releasePath deployDir release   forM_ cmds (exec . Cd rpath)++-- | Plays the given script on your machine locally.++playScriptLocally :: [GenericCommand] -> Hapistrano ()+playScriptLocally cmds =+  local+    (\c ->+        c+        { configSshOptions = Nothing+        }) $+  forM_ cmds exec  ---------------------------------------------------------------------------- -- Helpers