Small python script to search for changes using fnmatch patterns to filter git diff HEAD~
. The principal objective is make build processes faster checking whats changes before build projects/services.
- The script exits with 0 when changes are found and 1 otherwise.
- If script receives a
command
, it will be executed and exits withcommand
exit code.
Inspired by dockerfiles test script from Jess Frazelle.
Create a json file named .githasdiff.json
with include
and exclude
patterns for each project/service/build:
{
"project_a": {
"include": [
"project_a/*.py"
],
"exclude": [
"project_a/extra_scripts/*.py"
]
}
}
Global patterns can be defined in same file:
{
"include": [
"*.py"
],
"exclude": [
"*.md"
]
}
- Global patterns will be always used to search for changes.
exclude
has priority overinclude
patterns, so first exclude, then matches.- If
include
patterns list is omitted, then script will considerate["*"]
asinclude
list pattern.
It's also possible use an env var GITHASDIFF_FILE
to set the path to json config file, and an env var GITHASDIFF_COMMAND
to set command to check for diff.
curl -L https://github.com/pyanderson/githasdiff/releases/download/1.0.4/githasdiff > ./githasdiff
chmod +x ./githasdiff
Using if/else:
if ./githasdiff project_a; then docker build -t project_a project_a/; else exit 0; fi
Using the command
as args:
./githasdiff project_a docker build -t project_a project_a/
Check .githasdiff.json for configuration and .travis.yml for running.