- travis
[openemr.git] / ci / ci.sh
blob1aea60e83a46955f5fd1ad716c5e949eb6094fbf
1 #!/bin/bash
3 if [ -z "$1" ] || [ "$1" == "-h" ] || [ "$1" == "--help" ] ; then
4 printf "OpenEMR Continuous Integration\n\n"
5 printf " Overview:\n"
6 printf " This is the script that is ran by our Continuous Integration server found at\n"
7 printf " https://travis-ci.org/openemr/openemr. Each time you push code to your Pull Request\n"
8 printf " branch, this script will be ran on the server. You'll be able to see the state\n"
9 printf " (green/yellow/red) right on the Github UI.\n\n"
10 printf " In order to proactively test out these checks while you develop, please consult the\n"
11 printf " following wiki page: http://www.open-emr.org/wiki/index.php/Continuous_Integration.\n\n"
12 printf " Arguments:\n"
13 printf " -h, --help | Information on using this script\n"
14 printf " -d, --dir | The codebase directory for OpenEMR\n"
15 exit 0
18 #takes list of files/folders to sniff as its only argument(s)
19 function sniff {
20 BIN_DIR=$HOME/.composer/vendor/bin
21 if [ -d $HOME/$XDG_CONFIG_HOME/composer ]; then
22 BIN_DIR="$HOME/$XDG_CONFIG_HOME/composer/vendor/bin"
24 if [ -d $HOME/.config/composer ]; then
25 BIN_DIR="$HOME/.config/composer/vendor/bin"
27 composer global require "squizlabs/php_codesniffer=3.*"
28 cd $DIR
29 $BIN_DIR/phpcs -p -n --extensions=php,inc --report-width=120 $@
32 if [ "$1" == "-d" ] || [ "$1" == "--dir" ] ; then
34 DIR=$2
36 case "$CI_JOB" in
38 "lint_syntax")
39 echo "Checking for PHP syntax errors"
40 cd $2
41 failSyntax=false;
42 if find . -type f -name "*.php" -exec php -d error_reporting=32767 -l {} \; 2>&1 >&- | grep "^"; then failSyntax=true; fi;
43 if find . -type f -name "*.inc" -exec php -d error_reporting=32767 -l {} \; 2>&1 >&- | grep "^"; then failSyntax=true; fi;
44 if $failSyntax; then
45 exit 1;
48 "lint_style")
49 sniff . --standard=ci/phpcs.xml --report=full
51 "lint_style_new_commit")
52 MODIFIED_FILES=$(git diff-tree --no-commit-id --name-only -r HEAD | tr "\n" " ")
53 sniff "$MODIFIED_FILES" --standard=ci/phpcs_strict.xml --report=full
55 "lint_style_staged")
56 MODIFIED_FILES=$(git diff --cached --name-only | tr "\n" " ")
57 sniff "$MODIFIED_FILES" --standard=ci/phpcs_strict.xml --report=full
60 echo "Error: not a valid CI_JOB"
63 esac