Added new Unknown value to DeployState enum

This commit is contained in:
DavidMazarro 2022-02-03 11:51:08 +01:00
parent 4676c3217c
commit eb5d1071b8
No known key found for this signature in database
GPG Key ID: 5B490A04990FAAB7
2 changed files with 11 additions and 6 deletions

View File

@ -37,7 +37,7 @@ import Control.Monad
import Control.Monad.Except import Control.Monad.Except
import Control.Monad.Reader (local, runReaderT) import Control.Monad.Reader (local, runReaderT)
import Data.List (dropWhileEnd, genericDrop, sortOn) import Data.List (dropWhileEnd, genericDrop, sortOn)
import Data.Maybe (mapMaybe) import Data.Maybe (mapMaybe, fromMaybe)
import Data.Ord (Down (..)) import Data.Ord (Down (..))
import Data.Time import Data.Time
import Numeric.Natural import Numeric.Natural
@ -273,8 +273,8 @@ releasesWithState selectedState deployPath = do
. deployState deployPath Nothing . deployState deployPath Nothing
) releases ) releases
where where
stateToBool :: Maybe DeployState -> Bool stateToBool :: DeployState -> Bool
stateToBool (Just Fail) = False stateToBool Fail = False
stateToBool _ = True stateToBool _ = True
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
@ -358,7 +358,7 @@ deployState
:: Path Abs Dir -- ^ Deploy path :: Path Abs Dir -- ^ Deploy path
-> Maybe (Path Rel Dir) -- ^ Working directory -> Maybe (Path Rel Dir) -- ^ Working directory
-> Release -- ^ 'Release' identifier -> Release -- ^ 'Release' identifier
-> Hapistrano (Maybe DeployState) -- ^ Whether the release was deployed successfully or not -> Hapistrano DeployState -- ^ Whether the release was deployed successfully or not
deployState deployPath mWorkingDir release = do deployState deployPath mWorkingDir release = do
parseStatePath <- parseRelFile deployStateFilename parseStatePath <- parseRelFile deployStateFilename
actualReleasePath <- releasePath deployPath release mWorkingDir actualReleasePath <- releasePath deployPath release mWorkingDir
@ -366,8 +366,8 @@ deployState deployPath mWorkingDir release = do
doesExist <- exec (CheckExists stateFilePath) (Just release) doesExist <- exec (CheckExists stateFilePath) (Just release)
if doesExist then do if doesExist then do
deployStateContents <- exec (Cat stateFilePath) (Just release) deployStateContents <- exec (Cat stateFilePath) (Just release)
return $ readMaybe deployStateContents return $ (fromMaybe Unknown . readMaybe) deployStateContents
else return Nothing else return Unknown
stripDirs :: Path Abs Dir -> [Path Abs t] -> Hapistrano [Path Rel t] stripDirs :: Path Abs Dir -> [Path Abs t] -> Hapistrano [Path Rel t]
stripDirs path = stripDirs path =

View File

@ -143,9 +143,14 @@ data TargetSystem
deriving (Eq, Show, Read, Ord, Bounded, Enum) deriving (Eq, Show, Read, Ord, Bounded, Enum)
-- | State of the deployment after running @hap deploy@. -- | State of the deployment after running @hap deploy@.
-- __note:__ the 'Unknown' value is not intended to be
-- written to the @.hapistrano_deploy_state@ file; instead,
-- it's intended to represent whenever Hapistrano couldn't
-- get the information on the deployment state (e.g. the file is not present).
data DeployState data DeployState
= Fail = Fail
| Success | Success
| Unknown
deriving (Eq, Show, Read, Ord, Bounded, Enum) deriving (Eq, Show, Read, Ord, Bounded, Enum)
-- Command line options -- Command line options