mtimehash

CLI to modify files mtime (modification data time) based on the hash of the file content.
This makes it deterministic regardless of when the file was created or modified.
Installation
go install github.com/slsyy/mtimehash/cmd/mtimehash@latest
Rationale
go test uses mtimes to determine, if files opened during tests has changed and thus: tests need to be re-run.
Unfortunately in a typical CI workflow modifications times are random as git does not preserve them. This makes caching
for those tests ineffective, which slows down the test execution
More information here: https://github.com/golang/go/issues/58571
The trick is to set mtime based on the file content hash.
This way the mtime is deterministic regardless of when the repository
was modified/clone, so a hit ratio should be much higher.
Usage
Processing Files
Pass a list of files to modify via stdin:
find . -type f | mtimehash files
In my project I use:
find . -type f -size -10000k ! -path ./.git/\*\* | mtimehash files
to skip large files and .git directory
Processing Directories
Pass a list of directories to modify via stdin:
find . -type d | mtimehash dirs
The directory modification time is set based on a hash of the directory contents (file and subdirectory names), making it deterministic based on what files are present in the directory.
Note: It's recommended to process files first, then directories:
find . -type f | mtimehash files
find . -type d | mtimehash dirs
This ensures directories get updated mtimes based on the final state of their contents.