Merge pull request #1024 for XSS remediation in prescription module
[openemr.git] / ci / ci.sh
blob9e52f0c787422db958e73c848bbf0459452f0de6
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 INI=$HOME/.phpenv/versions/$(phpenv version-name 2> /dev/null)/etc/php.ini
21 if [ -f $INI ]; then
22 grep -q "extension = ldap.so" $INI || echo "extension = ldap.so" >> $INI
24 BIN_DIR=$HOME/.composer/vendor/bin
25 if [ -d $HOME/$XDG_CONFIG_HOME/composer ]; then
26 BIN_DIR="$HOME/$XDG_CONFIG_HOME/composer/vendor/bin"
28 if [ -d $HOME/.config/composer ]; then
29 BIN_DIR="$HOME/.config/composer/vendor/bin"
31 composer global require "squizlabs/php_codesniffer=3.0.*"
32 cd $DIR
33 $BIN_DIR/phpcs -p -n --extensions=php,inc --report-width=120 $@
36 if [ "$1" == "-d" ] || [ "$1" == "--dir" ] ; then
38 DIR=$2
40 case "$CI_JOB" in
42 "lint_syntax")
43 cd $2
44 find . -type d \( -path ./vendor \
45 -o -path ./interface/main/calendar/modules \
46 -o -path ./interface/reports \
47 -o -path ./contrib/util \
48 -o -path ./library/html2pdf/vendor/tecnickcom \
49 -o -path ./library/classes/fpdf \
50 -o -path ./library/html2pdf \
51 -o -path ./gacl \
52 -o -path ./library/edihistory \) -prune -o \
53 -name "*.php" -print0 | xargs -0 -n1 -P8 php -l
55 "lint_style")
56 sniff . --standard=ci/phpcs.xml --report=full
58 "lint_style_new_commit")
59 MODIFIED_FILES=$(git diff-tree --no-commit-id --name-only -r HEAD | tr "\n" " ")
60 sniff "$MODIFIED_FILES" --standard=ci/phpcs_strict.xml --report=full
62 "lint_style_staged")
63 MODIFIED_FILES=$(git diff --cached --name-only | tr "\n" " ")
64 sniff "$MODIFIED_FILES" --standard=ci/phpcs_strict.xml --report=full
67 echo "Error: not a valid CI_JOB"
70 esac