Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ 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
## Snapshot Command Flags

The `snapshot` command supports the following flags:

Expand All @@ -142,3 +142,15 @@ The `snapshot` command supports the following flags:
- `--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?


## Tests: Update Golden Files

This project uses [tasty-golden](https://github.com/UnkindPartition/tasty-golden) for snapshot-based testing.

To update the golden files, run the test suite with the `--accept` flag passed to the test executable.
If you're using stack, the full command is:

```sh
stack test --test-arguments --accept
```
5 changes: 3 additions & 2 deletions src/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,8 @@ snapshot appState args = do
mainBranchCommit <- liftIO $ getMainBranchCommit appState
let force = appState.settings.force

inputsAreClean <- liftIO $ not <$> isDirtyAtPaths appState args.fileInputs

let hashInfo = HashInfo
{ hash = currentHash
, hashInput = currentHashInput
Expand All @@ -446,8 +448,7 @@ snapshot appState args = do
logDebug appState "Prime cache mode, assuming task is done and skippping!"
earlyReturn (False, Nothing)


when (hasRemoteCache args && not force) do
when (hasRemoteCache args && not force && inputsAreClean) 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 Down
12 changes: 12 additions & 0 deletions src/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ bytesfmt formatter bs = printf (formatter <> " %s")
bytesSuffixes = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"]
bytesSuffix = bytesSuffixes !! i

isDirtyAtPaths :: AppState -> [FilePath] -> IO Bool
isDirtyAtPaths _ [] = pure False
isDirtyAtPaths appState paths =
bracket (hDuplicate appState.subprocessStderr) hClose \stderr_ -> do
output <-
readCreateProcess
(proc "git" (["status", "--porcelain", "--untracked-files=no", "--"] ++ paths))
{ std_err = UseHandle stderr_
}
""
pure $ not (null output)

getCurrentBranch :: AppState -> IO Text
getCurrentBranch appState =
bracket (hDuplicate appState.subprocessStderr) hClose \stderr_ ->
Expand Down
1 change: 1 addition & 0 deletions test/t/cache-success-unchanged.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mkdir a
echo foo > input.txt
git init -q
git add input.txt
git commit -qm "Add input.txt"
)

cp -r a b
Expand Down
1 change: 1 addition & 0 deletions test/t/prime-cache-mode.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mkdir a
echo foo > input.txt
git init -q
git add input.txt
git commit -qm "Add input.txt"
)

cp -r a b
Expand Down
1 change: 1 addition & 0 deletions test/t/remote-cache-changed.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mkdir a
echo foo > input.txt
git init -q
git add input.txt
git commit -qm "Add input.txt"
)

cp -r a b
Expand Down
1 change: 1 addition & 0 deletions test/t/remote-cache-post-unpack.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mkdir a
echo foo > input.txt
git init -q
git add input.txt
git commit -qm "Add input.txt"
)

cp -r a b
Expand Down
1 change: 1 addition & 0 deletions test/t/remote-cache-unchanged-force.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mkdir a
echo foo > input.txt
git init -q
git add input.txt
git commit -qm "Add input.txt"
)

cp -r a b
Expand Down
1 change: 1 addition & 0 deletions test/t/remote-cache-unchanged-nested-dir.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mkdir -p a
cd nested
echo foo > input.txt
git add input.txt
git commit -qm "Add input.txt"
)

cp -r a b
Expand Down
1 change: 1 addition & 0 deletions test/t/remote-cache-unchanged-out-of-repo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mkdir a
echo foo > input.txt
git init -q
git add input.txt
git commit -qm "Add input.txt"
)

cp -r a b
Expand Down
1 change: 1 addition & 0 deletions test/t/remote-cache-unchanged.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mkdir a
echo foo > input.txt
git init -q
git add input.txt
git commit -qm "Add input.txt"
)

cp -r a b
Expand Down