how to force run unit tests when running git push 3f

Solutions on MaxInterview for how to force run unit tests when running git push 3f by the best coders in the world

showing results for - "how to force run unit tests when running git push 3f"
Emil
12 Nov 2018
1#!/bin/bash
2while read oldrev newrev refname
3do
4    # Only run this script for the master branch. You can remove this 
5    # if block if you wish to run it for others as well.
6    if [[ $refname = "refs/heads/master" ]] ; then
7        # Anything echo'd will show up in the console for the person 
8        # who's doing a push
9        echo "Preparing to run phpunit for $newrev ... "
10 
11        # Since the repo is bare, we need to put the actual files someplace, 
12        # so we use the temp dir we chose earlier
13        git archive $newrev | tar -x -C /home/jani/tmp/example
14 
15        echo "Running phpunit for $newrev ... "
16 
17        # This part is the actual code which is used to run our tests
18        # In my case, the phpunit testsuite resides in the tests directory, so go there
19        cd /home/jani/tmp/example/tests       
20 
21        # And execute the testsuite, while ignoring any output
22        phpunit > /dev/null
23 
24        # $? is a shell variable which stores the return code from what we just ran
25        rc=$?
26        if [[ $rc != 0 ]] ; then
27            # A non-zero return code means an error occurred, so tell the user and exit
28            echo "phpunit failed on rev $newrev - push deniend. Run tests locally and confirm they pass before pushing"
29            exit $rc
30        fi
31    fi
32done
33 
34# Everything went OK so we can exit with a zero
35exit 0