Skip to content

Small python script to search for changes using fnmatch patterns. The principal objective is make build processes faster avoiding unnecessary steps.

License

Notifications You must be signed in to change notification settings

pyanderson/githasdiff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

githasdiff

Build Status

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 with command exit code.

Inspired by dockerfiles test script from Jess Frazelle.

Configuration

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"
    ]
}

Observations:

  • Global patterns will be always used to search for changes.
  • exclude has priority over include patterns, so first exclude, then matches.
  • If include patterns list is omitted, then script will considerate ["*"] as include 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.

Install

curl -L https://github.com/pyanderson/githasdiff/releases/download/1.0.4/githasdiff > ./githasdiff
chmod +x ./githasdiff

Run

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/

Examples

Check .githasdiff.json for configuration and .travis.yml for running.

About

Small python script to search for changes using fnmatch patterns. The principal objective is make build processes faster avoiding unnecessary steps.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published