diff --git a/.travis.yml.dist b/.travis.yml.dist index 393c587..f351793 100644 --- a/.travis.yml.dist +++ b/.travis.yml.dist @@ -84,6 +84,12 @@ env: # This needs to match your .coveralls.yml file. - DRUPAL_TI_COVERAGE_FILE="build/logs/clover.xml" + # === PHPCS specific variables. + # These arguments are passed to the phpcs command. + - DRUPAL_TI_PHPCS_ARGS="" + # The version of drupal/coder that should be used. + - DRUPAL_TI_DRUPAL_CODER_VERSION="drupal/coder:^8.2" + # Debug options #- DRUPAL_TI_DEBUG="-x -v" # Set to "all" to output all files, set to e.g. "xvfb selenium" or "selenium", diff --git a/functions/phpcs.sh b/functions/phpcs.sh new file mode 100644 index 0000000..57f4197 --- /dev/null +++ b/functions/phpcs.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env bash +# @file +# Common functionality for installing phpcs and friends. + +# +# Ensures that phpcs is installed. +# +function drupal_ti_ensure_phpcs() { + # This function is re-entrant. + if [ -r "$TRAVIS_BUILD_DIR/../drupal_ti-phpcs-installed" ] + then + return + fi + + # Check if drupal/coder is already available. + DRUPAL_CODER=$(composer info --no-interaction drupal/coder || echo "") + + if [ -z "$DRUPAL_CODER" ] + then + # Install drupal/coder globally. + echo "Installing drupal/coder: $DRUPAL_TI_DRUPAL_CODER_VERSION" + composer global require --no-interaction "$DRUPAL_TI_DRUPAL_CODER_VERSION" + else + echo "phpcs $DRUPAL_TI_DRUPAL_CODER_VERSION is already installed." + composer global install --no-interaction + fi + + # Install Drupal and DrupalPractice coding standards. + phpcs --config-set installed_paths $HOME/.composer/vendor/drupal/coder/coder_sniffer + + touch "$TRAVIS_BUILD_DIR/../drupal_ti-phpcs-installed" +} diff --git a/runners/phpcs/install.sh b/runners/phpcs/install.sh new file mode 100755 index 0000000..461e6f5 --- /dev/null +++ b/runners/phpcs/install.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash +# Simple script to install dependencies for travis-ci running. + +set -e $DRUPAL_TI_DEBUG + +# Ensure that phpcs is installed. +drupal_ti_ensure_phpcs diff --git a/runners/phpcs/script.sh b/runners/phpcs/script.sh new file mode 100755 index 0000000..3a29398 --- /dev/null +++ b/runners/phpcs/script.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# @file +# phpcs integration - Script step. + +set -e $DRUPAL_TI_DEBUG + +if [[ -n $DRUPAL_TI_PHPCS_ARGS ]]; then + ARGS=( $DRUPAL_TI_PHPCS_ARGS ) +else + ARGS=( + "--colors" + "--standard=Drupal,DrupalPractice" + "--extensions=php,module,inc,install,test,profile,theme,css,info,txt,md" + "--ignore=node_modules,bower_components,vendor" + "${TRAVIS_BUILD_DIR}" + ) +fi + +$HOME/.composer/vendor/bin/phpcs "${ARGS[@]}" diff --git a/tests/run-tests.sh b/tests/run-tests.sh index 7821742..13727eb 100755 --- a/tests/run-tests.sh +++ b/tests/run-tests.sh @@ -12,7 +12,7 @@ ln -sf "$SCRIPT_DIR/drupal-ti" /tmp/drupal_ti/bin/ # Setup runners. export DRUPAL_TI_RUNNERS="success" -/tmp/drupal_ti/bin/drupal-ti script && echo "- Test succeeed as expected." || exit 1 +/tmp/drupal_ti/bin/drupal-ti script && echo "- Test succeeded as expected." || exit 1 export DRUPAL_TI_RUNNERS="failure" /tmp/drupal_ti/bin/drupal-ti script && exit 1 || echo "- Test failed as expected."