Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
70a556a
.gitignore aider files
zyla Apr 22, 2025
da9c601
feat: add --cache-success flag and parsing logic to SnapshotCliArgs
zyla Apr 22, 2025
331ee94
refactor: generalize hasOutputs to hasCache for caching logic
zyla Apr 22, 2025
6955da8
refactor: rename hasCache to hasRemoteCache and update usages
zyla Apr 22, 2025
7244a72
test: add test case for --cache-success flag in caching mechanism
zyla Apr 22, 2025
ac73143
test: Update cache-success test case to remove unnecessary --outputs …
zyla Apr 22, 2025
fc50de1
test: remove dependency on output.txt in cache success test case
zyla Apr 22, 2025
c8e1b60
fix: remove undefined variable reference in error message
zyla Apr 22, 2025
e69339f
fix: replace hasOutputs with hasRemoteCache in App.hs
zyla Apr 22, 2025
88a5812
feat: create empty tar archive when no files are provided for caching
zyla Apr 22, 2025
d977897
test: update cache-success test to include output verification
zyla Apr 22, 2025
03ed0cc
Fix haskell, test
zyla Apr 22, 2025
9fb3d2f
test: add cache-success-unchanged test to verify unchanged input beha…
zyla Apr 22, 2025
8b77466
fix: update expected output for cache-success-unchanged test case
zyla Apr 22, 2025
7ee7924
docs: document snapshot command flags in README including new flag
zyla Apr 22, 2025
1a07247
docs: update README with snapshot command flags section
zyla Apr 22, 2025
b634725
docs: update snapshot command flags section with actual flag descript…
zyla Apr 22, 2025
12c8776
Tweak command docs
zyla Apr 22, 2025
23c1cb6
docs: add documentation for --long-running flag in README
zyla Apr 22, 2025
e395dd0
Another tweak
zyla Apr 22, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
*~
.test-env
ghtest-env
.aider*
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Features


- Runs tasks (which are defined as shell scripts)
- Ensures only one instance of a task runs at a time (globally in the whole system) - using file-based locks
- Tasks can run in parallel
Expand Down Expand Up @@ -128,3 +129,16 @@ To use it, first build using another system, and the run `taskrunner` with `TASK

- Previous impl no-op tests/scripts/UPDATE: ~1.6s
- Current impl no-op tests/scripts/UPDATE: ~2.3s

## Snapshot Command Flags

The `snapshot` command supports the following flags:

- `--outputs`: Specifies the output files of the task. These files are used to determine if the task needs to be rerun.
- `--cache-success`: Use remote cache even when no outputs are specified. The task is not rerun if it succeeded previously with the same inputs. Useful e.g. for test suites.
- `--raw`: Specifies raw input strings that are used to compute the task's hash.
- `--fuzzy-cache`: Enables the use of a fuzzy cache, which attempts to restore from a cache of a similar task if the exact cache is not available.
- `--cache-root`: Specifies the root directory for caching. Use when caching things outside of the repository, e.g. `~/.stack`.
- `--cache-version`: Specifies a version string for the cache. `--fuzzy-cache` will not download cache from another version, allowing clean breaks when making big changes, e.g. upgrading a compiler.
- `--commit-status`: Enables reporting of the task's status to a commit status system, such as GitHub checks.
- `--long-running`: Indicates that the task is expected to run for a long time (e.g. a server). Currently doens't have any effect though, TODO: can we remove it?
10 changes: 5 additions & 5 deletions src/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ main = do
forM_ snapshotArgs.postUnpackCommands \cmd -> do
runPostUnpackCmd appState cmd

when (hasOutputs snapshotArgs && settings.saveRemoteCache && (not skipped || appState.settings.primeCacheMode)) do
when (hasRemoteCache snapshotArgs && settings.saveRemoteCache && (not skipped || appState.settings.primeCacheMode)) do
logDebug appState "Saving remote cache"
s <- RemoteCache.getRemoteCacheSettingsFromEnv
RemoteCache.saveCache appState s (fromMaybe settings.rootDirectory snapshotArgs.cacheRoot) snapshotArgs.outputs (archiveName appState snapshotArgs h.hash)
Expand Down Expand Up @@ -397,8 +397,8 @@ commandHandler appState requestPipe responsePipe =
hasInputs :: SnapshotCliArgs -> Bool
hasInputs args = not (null args.fileInputs) || not (null args.rawInputs)

hasOutputs :: SnapshotCliArgs -> Bool
hasOutputs args = not (null args.outputs)
hasRemoteCache :: SnapshotCliArgs -> Bool
hasRemoteCache args = args.cacheSuccess || not (null args.outputs)

snapshot :: AppState -> SnapshotCliArgs -> IO String
snapshot appState args = do
Expand Down Expand Up @@ -447,7 +447,7 @@ snapshot appState args = do
earlyReturn (False, Nothing)


when (hasOutputs args && not force) do
when (hasRemoteCache 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 @@ -456,7 +456,7 @@ snapshot appState args = do

logInfo appState "Inputs changed, running task"

when (not force && hasOutputs args && args.fuzzyCache && mainBranchCommitChanged savedHashInfo hashInfo) do
when (not force && hasRemoteCache args && args.fuzzyCache && mainBranchCommitChanged savedHashInfo hashInfo) do
success <- tryRestoreFuzzyCache appState args
when success do
-- Save change in mainBranchCommit, even if the task didn't succeed yet.
Expand Down
2 changes: 1 addition & 1 deletion src/RemoteCache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import Amazonka.S3.PutObject (newPutObject, PutObject(..))
packTar :: MonadResource m => AppState -> FilePath -> [FilePath] -> ConduitT () BS.ByteString m ()
packTar appState workdir files = do
let cmd = "tar"
let args = ["-c"] <> files
let args = if null files then ["-c", "--files-from=/dev/null"] else ["-c"] <> files
liftIO $ logDebug appState $ "Running subprocess: " <> show (cmd:args) <> " in cwd " <> show workdir
bracketP ( createProcess_ "createProcess_"
(proc cmd args)
Expand Down
6 changes: 6 additions & 0 deletions src/SnapshotCliArgs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data SnapshotCliArgs = SnapshotCliArgs
, cacheRoot :: Maybe FilePath
, cacheVersion :: Maybe Text
, commitStatus :: Bool
, cacheSuccess :: Bool
} deriving (Show)

instance Default SnapshotCliArgs where
Expand All @@ -28,6 +29,7 @@ instance Default SnapshotCliArgs where
, cacheRoot = Nothing
, cacheVersion = Nothing
, commitStatus = False
, cacheSuccess = False
}

type ParseError = String
Expand Down Expand Up @@ -79,6 +81,10 @@ parse input = map fst $ flip execStateT (def :: SnapshotCliArgs, BeforeOutputs)
modifyArgs (\s -> s { commitStatus = True })
go xs

go ("--cache-success":xs) = do
modifyArgs (\s -> s { cacheSuccess = True })
go xs

go (opt:_) | '-':_ <- opt =
lift $ Left $ "Invalid option or missing argument: " <> opt

Expand Down
9 changes: 9 additions & 0 deletions test/t/cache-success-changed.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- output:
[mytask] info | Inputs changed, running task
[mytask] stdout | Expensive computation
[mytask] stdout | oof
[mytask] info | success
[mytask] info | Inputs changed, running task
[mytask] stdout | Expensive computation
[mytask] stdout | rab
[mytask] info | success
35 changes: 35 additions & 0 deletions test/t/cache-success-changed.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# no toplevel
# s3

export TASKRUNNER_SAVE_REMOTE_CACHE=1

mkdir a

(
cd a
echo foo > input.txt
git init -q
git add input.txt
)

cp -r a b

go() {
# Note: we want separate workdir for separate repos
TASKRUNNER_STATE_DIRECTORY="$(pwd)" taskrunner -n mytask bash -e -c '
snapshot input.txt --cache-success
echo "Expensive computation"
rev input.txt
'
}

(
cd a
go
)

(
cd b
echo bar > input.txt
go # note: should run "expensive computation" again
)
7 changes: 7 additions & 0 deletions test/t/cache-success-unchanged.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- output:
[mytask] info | Inputs changed, running task
[mytask] stdout | Expensive computation
[mytask] stdout | oof
[mytask] info | success
[mytask] info | Found remote cache mytask-6b36308659163b577fd1c832107dc46ca3aa659b.tar.zst, restoring
[mytask] info | Restored from remote cache
34 changes: 34 additions & 0 deletions test/t/cache-success-unchanged.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# no toplevel
# s3

export TASKRUNNER_SAVE_REMOTE_CACHE=1

mkdir a

(
cd a
echo foo > input.txt
git init -q
git add input.txt
)

cp -r a b

go() {
# Note: we want separate workdir for separate repos
TASKRUNNER_STATE_DIRECTORY="$(pwd)" taskrunner -n mytask bash -e -c '
snapshot input.txt --cache-success
echo "Expensive computation"
rev input.txt
'
}

(
cd a
go
)

(
cd b
go # note: should not run "expensive computation" again
)