jdx / mise

dev tools, env vars, task runner
https://mise.jdx.dev
MIT License
10.32k stars 295 forks source link

Task source diff based on git log sha #2656

Open Ernest0-Production opened 2 months ago

Ernest0-Production commented 2 months ago

Hi 👋 @jdx !

Motivation

I would like to be able to run the task only if the source file was changed.

Proposed Solution

Since calculating the hash sum of a file can take a long time, depending on the size and number of files, it would make sense to find the SHA of the commit on which the file was modified:

git log -1 --pretty=format:"%H - %an, %ar : %s" -- src/main.cpp

If the sha of the file differs from the cached one, then the task is started.

API Stability

To maintain backward compatibility, we can add a new parameter to the task that defines the methods for comparing source files:

[task.foo]
diff_strategy = ["timestamp", "git"]

In the future, it will be possible to add a diff strategy based on the checksum of the file.

Alternative Solution

A more flexible option is to add a parameter for embedding scripts whose stdout would be cached, based on which comparisons between runs would occur:

# Example 1: install a tool that cannot be deployed locally
[task.install_brew]
checksum = [
   "brew --version", 
   "echo $REQUIRED_BREW_VERSION"
]
run = "<command to install brew>"

# Example 2: compile binary only if sources changed
[task.compile_binary]
checksum = "md5 script.cpp"
run = "<command to compile script binary>"

# Example 3: codegen if sources changed (on git checkout)
checksum = "git log -1 ..."
run = "swiftgen run ..."
jdx commented 2 months ago

mise compares timestamps, not hashes

Ernest0-Production commented 2 months ago

I know, that's why I suggested a more optimal solution.