diff --git a/README.md b/README.md index 5e8bb62..fbec0cf 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 +``` diff --git a/src/App.hs b/src/App.hs index 825e48d..c8d840b 100644 --- a/src/App.hs +++ b/src/App.hs @@ -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 @@ -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 diff --git a/src/Utils.hs b/src/Utils.hs index 7a3b6df..508644d 100644 --- a/src/Utils.hs +++ b/src/Utils.hs @@ -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_ -> diff --git a/test/t/cache-success-unchanged.txt b/test/t/cache-success-unchanged.txt index 2785686..40d6537 100644 --- a/test/t/cache-success-unchanged.txt +++ b/test/t/cache-success-unchanged.txt @@ -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 diff --git a/test/t/prime-cache-mode.txt b/test/t/prime-cache-mode.txt index c877a05..888b284 100644 --- a/test/t/prime-cache-mode.txt +++ b/test/t/prime-cache-mode.txt @@ -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 diff --git a/test/t/remote-cache-changed.txt b/test/t/remote-cache-changed.txt index 0e08469..55a6435 100644 --- a/test/t/remote-cache-changed.txt +++ b/test/t/remote-cache-changed.txt @@ -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 diff --git a/test/t/remote-cache-post-unpack.txt b/test/t/remote-cache-post-unpack.txt index 61a0d0a..c764ecc 100644 --- a/test/t/remote-cache-post-unpack.txt +++ b/test/t/remote-cache-post-unpack.txt @@ -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 diff --git a/test/t/remote-cache-unchanged-force.txt b/test/t/remote-cache-unchanged-force.txt index 53988e4..20a9095 100644 --- a/test/t/remote-cache-unchanged-force.txt +++ b/test/t/remote-cache-unchanged-force.txt @@ -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 diff --git a/test/t/remote-cache-unchanged-nested-dir.txt b/test/t/remote-cache-unchanged-nested-dir.txt index e3ddd3e..4b9c10c 100644 --- a/test/t/remote-cache-unchanged-nested-dir.txt +++ b/test/t/remote-cache-unchanged-nested-dir.txt @@ -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 diff --git a/test/t/remote-cache-unchanged-out-of-repo.txt b/test/t/remote-cache-unchanged-out-of-repo.txt index 31f7dd7..0723ad0 100644 --- a/test/t/remote-cache-unchanged-out-of-repo.txt +++ b/test/t/remote-cache-unchanged-out-of-repo.txt @@ -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 diff --git a/test/t/remote-cache-unchanged.txt b/test/t/remote-cache-unchanged.txt index 7a9a5a9..143483c 100644 --- a/test/t/remote-cache-unchanged.txt +++ b/test/t/remote-cache-unchanged.txt @@ -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