Skip to content

Commit

Permalink
Add force
Browse files Browse the repository at this point in the history
  • Loading branch information
kozak committed Sep 12, 2024
1 parent a140741 commit 5bc81d4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/App.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DuplicateRecordFields #-}

module App where

Expand Down Expand Up @@ -71,12 +72,15 @@ getSettings = do
, fuzzyCacheFallbackBranches
, primeCacheMode
, mainBranch
, force = False
}

main :: IO ()
main = do
args <- getCliArgs
settings <- getSettings
(args :: CliArgs) <- getCliArgs
settings' <- getSettings
let f = args.force
let settings = (settings' :: Settings) { force = f }

Check warning on line 83 in src/App.hs

View workflow job for this annotation

GitHub Actions / build

The record update (settings' :: Settings)

let jobName = fromMaybe (FilePath.takeFileName args.cmd) args.name

Expand Down Expand Up @@ -394,6 +398,7 @@ snapshot appState args = do
let currentHash = hexSha1 currentHashInput

mainBranchCommit <- liftIO $ getMainBranchCommit appState
let force = appState.settings.force

Check warning on line 401 in src/App.hs

View workflow job for this annotation

GitHub Actions / build

This binding for ‘force’ shadows the existing binding

let hashInfo = HashInfo
{ hash = currentHash
Expand All @@ -404,7 +409,7 @@ snapshot appState args = do
savedHashInfo <- liftIO $ readHashInfo appState
let savedHash = savedHashInfo.hash

when (currentHash == savedHash) do
when (currentHash == savedHash && not force) do
logDebug appState $ "Hash matches, hash=" <> savedHash <> ", skipping"
earlyReturn (False, Just "local cache hit (?)")

Expand All @@ -416,7 +421,8 @@ snapshot appState args = do
logDebug appState "Prime cache mode, assuming task is done and skippping!"
earlyReturn (False, Nothing)

when (hasOutputs args) do

when (hasOutputs args && not force) do
s <- RemoteCache.getRemoteCacheSettingsFromEnv
success <- liftIO $ RemoteCache.restoreCache appState s (fromMaybe appState.settings.rootDirectory args.cacheRoot) (archiveName appState args currentHash) RemoteCache.Log
when success do
Expand All @@ -425,7 +431,7 @@ snapshot appState args = do

logInfo appState "Inputs changed, running task"

when (hasOutputs args && args.fuzzyCache && mainBranchCommitChanged savedHashInfo hashInfo) do
when (not force && hasOutputs args && args.fuzzyCache && mainBranchCommitChanged savedHashInfo hashInfo) do
tryRestoreFuzzyCache appState args

pure (True, Nothing)
Expand Down Expand Up @@ -463,7 +469,7 @@ readHashInfo appState = do
pure h
else
pure emptyHashInfo


tryRestoreFuzzyCache :: MonadIO m => AppState -> SnapshotCliArgs -> m ()
tryRestoreFuzzyCache appState args = do
Expand Down
5 changes: 5 additions & 0 deletions src/CliArgs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Options.Applicative

data CliArgs = CliArgs
{ name :: Maybe String -- Optional name argument
, force :: Bool -- Skip cache
, cmd :: String -- The command to run
, args :: [String] -- List of arguments for the command
} deriving (Show)
Expand All @@ -16,6 +17,10 @@ commandParser = CliArgs
<> short 'n'
<> metavar "NAME"
<> help "Optional name for the task" ))
<*> switch
( long "force"
<> short 'f'
<> help "Skip cache and fuzzy cache" )
<*> argument str
( metavar "CMD"
<> help "The command to run" )
Expand Down
1 change: 1 addition & 0 deletions src/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ data Settings = Settings
, fuzzyCacheFallbackBranches :: [Text]
, primeCacheMode :: Bool
, mainBranch :: Maybe Text
, force :: Bool
} deriving (Show)

type JobName = String
Expand Down

0 comments on commit 5bc81d4

Please sign in to comment.