The Script#
What the Script does#
- Gets changed files, comparing the current branch to the
origin/develop
branch.
- Checks for changes only in the
web/themes
or web/modules
directories. To change this behavior, change the
argument for grep
below
- Runs
phpcs
with the Drupal
standard.
#!/bin/bash
echo 'Printing phpcs warnings for only Changed Files';
changed_files=$(git diff --name-only --diff-filter=d origin/develop..$CI_COMMIT_SHORT_SHA | grep -E "web/themes|web/modules")
if [[ -z $changed_files ]]
then
echo "There are no files to check."
exit 0
fi
./vendor/bin/phpcs --colors --standard=Drupal --extensions=php,module,inc,install,test,profile,theme $changed_files
Sample Gitlab CI Job to run the script#
...
phpcs-warnings:
stage: Check
script:
- scripts/gitlab-ci/phpcs-check-changed.sh