Search code examples
gitbashbuildcontinuous-integrationcodeship

How can I make a script that will build w/ Codeship only when changes are made to a specific directory?


Let's say I have two directories, lib and src, and only want Codeship to build commited changes that are from the src directory. How would I go about making a Bash script that does that? I know that applying the --skip-ci flag to a commit will make Codeship not create a build off of that commit. Any help is greatly appreciated!


Solution

  • You could use a command like the following directly in the test steps:

    if [[ $(git log -m -n 1 --name-only --pretty=format:"" | grep -e "lib" -e "src" -c) -gt 0 ]]; then run_your_tests; fi
    

    This will display the changed files for the last commit without any additional metadata and count the occurrences of lib and src in those lines.

    If these strings occur more than once it will run the run_your_tests command. Else it will simply return.

    Note, that this is a very crude version, it isn't looking for the strings at the beginning of file names for example. But it should be a good starting point.

    Please get in touch via support@codeship.com (or our in app messenger) if you have any further questions! (And I will update the answer if we add something via the in app support.

    [Disclaimer] I'm working for Codeship ;)