Decoupled functions from using .hapistrano_deploy_state filename directly

This commit is contained in:
DavidMazarro 2022-02-02 15:16:16 +01:00
parent b55d5bb9fc
commit fd4fdc68d3
No known key found for this signature in database
GPG Key ID: 5B490A04990FAAB7
3 changed files with 11 additions and 6 deletions

View File

@ -157,11 +157,11 @@ spec = do
-- This fails if there are unstaged changes -- This fails if there are unstaged changes
justExec rpath "git diff --exit-code" justExec rpath "git diff --exit-code"
describe "createHapistranoDeployState" $ do describe "createHapistranoDeployState" $ do
it "creates the .hapistrano_deploy_state file correctly" $ \(deployPath, repoPath) -> it ("creates the " <> deployStateFilename <> " file correctly") $ \(deployPath, repoPath) ->
runHap $ do runHap $ do
let task = mkTask deployPath repoPath let task = mkTask deployPath repoPath
release <- Hap.pushRelease task release <- Hap.pushRelease task
parseStatePath <- parseRelFile ".hapistrano_deploy_state" parseStatePath <- parseRelFile deployStateFilename
actualReleasePath <- releasePath deployPath release Nothing actualReleasePath <- releasePath deployPath release Nothing
let stateFilePath = actualReleasePath </> parseStatePath let stateFilePath = actualReleasePath </> parseStatePath
Hap.createHapistranoDeployState deployPath release Success Hap.createHapistranoDeployState deployPath release Success
@ -194,7 +194,7 @@ spec = do
task = mkTask deployPath repoPath task = mkTask deployPath repoPath
Hap.playScriptLocally localCommands Hap.playScriptLocally localCommands
release <- Hap.pushRelease task release <- Hap.pushRelease task
parseStatePath <- parseRelFile ".hapistrano_deploy_state" parseStatePath <- parseRelFile deployStateFilename
actualReleasePath <- releasePath deployPath release Nothing actualReleasePath <- releasePath deployPath release Nothing
let stateFilePath = actualReleasePath </> parseStatePath let stateFilePath = actualReleasePath </> parseStatePath
Hap.createHapistranoDeployState deployPath release Success Hap.createHapistranoDeployState deployPath release Success

View File

@ -45,6 +45,7 @@ import Path
import System.Hapistrano.Commands import System.Hapistrano.Commands
import System.Hapistrano.Core import System.Hapistrano.Core
import System.Hapistrano.Types import System.Hapistrano.Types
import System.Hapistrano.Config (deployStateFilename)
import Text.Read (readMaybe) import Text.Read (readMaybe)
---------------------------------------------------------------------------- ----------------------------------------------------------------------------
@ -127,7 +128,7 @@ createHapistranoDeployState
-> DeployState -- ^ Indicates how the deployment went -> DeployState -- ^ Indicates how the deployment went
-> Hapistrano () -> Hapistrano ()
createHapistranoDeployState deployPath release state = do createHapistranoDeployState deployPath release state = do
parseStatePath <- parseRelFile ".hapistrano_deploy_state" parseStatePath <- parseRelFile deployStateFilename
actualReleasePath <- releasePath deployPath release Nothing actualReleasePath <- releasePath deployPath release Nothing
let stateFilePath = actualReleasePath </> parseStatePath let stateFilePath = actualReleasePath </> parseStatePath
exec (Touch stateFilePath) (Just release) -- creates '.hapistrano_deploy_state' exec (Touch stateFilePath) (Just release) -- creates '.hapistrano_deploy_state'
@ -361,7 +362,7 @@ deployState
-> Release -- ^ 'Release' identifier -> Release -- ^ 'Release' identifier
-> Hapistrano (Maybe DeployState) -- ^ Whether the release was deployed successfully or not -> Hapistrano (Maybe DeployState) -- ^ Whether the release was deployed successfully or not
deployState deployPath mWorkingDir release = do deployState deployPath mWorkingDir release = do
parseStatePath <- parseRelFile ".hapistrano_deploy_state" parseStatePath <- parseRelFile deployStateFilename
actualReleasePath <- releasePath deployPath release mWorkingDir actualReleasePath <- releasePath deployPath release mWorkingDir
let stateFilePath = actualReleasePath </> parseStatePath let stateFilePath = actualReleasePath </> parseStatePath
doesExist <- exec (CheckExists stateFilePath) (Just release) doesExist <- exec (CheckExists stateFilePath) (Just release)

View File

@ -7,7 +7,8 @@
module System.Hapistrano.Config module System.Hapistrano.Config
( Config (..) ( Config (..)
, CopyThing (..) , CopyThing (..)
, Target (..)) , Target (..)
, deployStateFilename)
where where
import Control.Applicative ((<|>)) import Control.Applicative ((<|>))
@ -141,3 +142,6 @@ mkCmd raw =
case mkGenericCommand raw of case mkGenericCommand raw of
Nothing -> fail "invalid restart command" Nothing -> fail "invalid restart command"
Just cmd -> return cmd Just cmd -> return cmd
deployStateFilename :: String
deployStateFilename = ".hapistrano_deploy_state"