From c8b859cb163182744694fa4e381f503e2d297624 Mon Sep 17 00:00:00 2001 From: Nathaniel Hoag Date: Tue, 17 Apr 2018 21:41:50 -0400 Subject: [PATCH 1/9] Add phpcs support --- .travis.yml.dist | 8 ++++++ functions/phpcs.sh | 55 ++++++++++++++++++++++++++++++++++++++++ runners/phpcs/install.sh | 10 ++++++++ runners/phpcs/script.sh | 9 +++++++ tests/run-tests.sh | 2 +- 5 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 functions/phpcs.sh create mode 100644 runners/phpcs/install.sh create mode 100644 runners/phpcs/script.sh diff --git a/.travis.yml.dist b/.travis.yml.dist index 393c587..ee3f7e4 100644 --- a/.travis.yml.dist +++ b/.travis.yml.dist @@ -84,6 +84,14 @@ 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 phpcs that should be used. + - DRUPAL_TI_PHPCS_VERSION="squizlabs/php_codesniffer:^2.9" + # 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..9b7c3db --- /dev/null +++ b/functions/phpcs.sh @@ -0,0 +1,55 @@ +#!/usr/bin/env bash +# @file +# Common functionality for installing phpcs. + +# +# 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 phpcs is already available. + PHPCS=$(which phpcs || echo "") + + if [ -z "$PHPCS" ] + then + # Install phpcs globally. + echo "Installing phpcs: $DRUPAL_TI_PHPCS_VERSION" + composer global require --no-interaction "$DRUPAL_TI_PHPCS_VERSION" "$DRUPAL_TI_DRUPAL_CODER_VERSION" + else + echo "phpcs $DRUPAL_TI_PHPCS_VERSION is already installed." + composer global install --no-interaction + fi + + touch "$TRAVIS_BUILD_DIR/../drupal_ti-phpcs-installed" +} + +# +# Ensures that drupal/coder is installed. +# +function drupal_ti_ensure_drupal_coder() { + # This function is re-entrant. + if [ -r "$TRAVIS_BUILD_DIR/../drupal_ti-drupal_coder-installed" ] + then + return + fi + + # Check if drupal/coder is already available. + DRUPAL_CODER=$(composer info 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 + + touch "$TRAVIS_BUILD_DIR/../drupal_ti-drupal_coder-installed" +} diff --git a/runners/phpcs/install.sh b/runners/phpcs/install.sh new file mode 100644 index 0000000..1af5ae8 --- /dev/null +++ b/runners/phpcs/install.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +# Simple script to install dependencies for travis-ci running. + +set -e $DRUPAL_TI_DEBUG + +# Ensure that drupal/coder is installed. +drupal_ti_ensure_drupal_coder + +# Ensure that phpcs is installed. +drupal_ti_ensure_phpcs diff --git a/runners/phpcs/script.sh b/runners/phpcs/script.sh new file mode 100644 index 0000000..4c3e4fa --- /dev/null +++ b/runners/phpcs/script.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +# @file +# phpcs integration - Script step. + +set -e $DRUPAL_TI_DEBUG + +ARGS=( $DRUPAL_TI_PHPCS_ARGS ) + +./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." From 70295862b57585615929023a6f3956f46802f342 Mon Sep 17 00:00:00 2001 From: Nathaniel Hoag Date: Tue, 17 Apr 2018 23:15:41 -0400 Subject: [PATCH 2/9] Make phpcs runners executable --- runners/phpcs/install.sh | 0 runners/phpcs/script.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 runners/phpcs/install.sh mode change 100644 => 100755 runners/phpcs/script.sh diff --git a/runners/phpcs/install.sh b/runners/phpcs/install.sh old mode 100644 new mode 100755 diff --git a/runners/phpcs/script.sh b/runners/phpcs/script.sh old mode 100644 new mode 100755 From dab1d27d6960547006150d4cce06b64857e76457 Mon Sep 17 00:00:00 2001 From: Nathaniel Hoag Date: Tue, 17 Apr 2018 23:21:19 -0400 Subject: [PATCH 3/9] Add --no-interaction to composer info --- functions/phpcs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/functions/phpcs.sh b/functions/phpcs.sh index 9b7c3db..0fb6580 100644 --- a/functions/phpcs.sh +++ b/functions/phpcs.sh @@ -39,7 +39,7 @@ function drupal_ti_ensure_drupal_coder() { fi # Check if drupal/coder is already available. - DRUPAL_CODER=$(composer info drupal/coder || echo "") + DRUPAL_CODER=$(composer info --no-interaction drupal/coder || echo "") if [ -z "$DRUPAL_CODER" ] then From acc7fb6b5219a2734c63a27e81423498ea59226b Mon Sep 17 00:00:00 2001 From: Nathaniel Hoag Date: Tue, 17 Apr 2018 23:24:34 -0400 Subject: [PATCH 4/9] Use correct path to phpcs --- runners/phpcs/script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runners/phpcs/script.sh b/runners/phpcs/script.sh index 4c3e4fa..91f7377 100755 --- a/runners/phpcs/script.sh +++ b/runners/phpcs/script.sh @@ -6,4 +6,4 @@ set -e $DRUPAL_TI_DEBUG ARGS=( $DRUPAL_TI_PHPCS_ARGS ) -./vendor/bin/phpcs "${ARGS[@]}" +$HOME/.composer/vendor/bin/phpcs "${ARGS[@]}" From d92acbe5dc99cfc65171bdaa9e2a279bcec9e6da Mon Sep 17 00:00:00 2001 From: Nathaniel Hoag Date: Wed, 18 Apr 2018 09:46:35 -0400 Subject: [PATCH 5/9] Simplify installation logic --- functions/phpcs.sh | 30 ++---------------------------- runners/phpcs/install.sh | 3 --- 2 files changed, 2 insertions(+), 31 deletions(-) diff --git a/functions/phpcs.sh b/functions/phpcs.sh index 0fb6580..87843bd 100644 --- a/functions/phpcs.sh +++ b/functions/phpcs.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # @file -# Common functionality for installing phpcs. +# Common functionality for installing phpcs and friends. # # Ensures that phpcs is installed. @@ -12,32 +12,6 @@ function drupal_ti_ensure_phpcs() { return fi - # Check if phpcs is already available. - PHPCS=$(which phpcs || echo "") - - if [ -z "$PHPCS" ] - then - # Install phpcs globally. - echo "Installing phpcs: $DRUPAL_TI_PHPCS_VERSION" - composer global require --no-interaction "$DRUPAL_TI_PHPCS_VERSION" "$DRUPAL_TI_DRUPAL_CODER_VERSION" - else - echo "phpcs $DRUPAL_TI_PHPCS_VERSION is already installed." - composer global install --no-interaction - fi - - touch "$TRAVIS_BUILD_DIR/../drupal_ti-phpcs-installed" -} - -# -# Ensures that drupal/coder is installed. -# -function drupal_ti_ensure_drupal_coder() { - # This function is re-entrant. - if [ -r "$TRAVIS_BUILD_DIR/../drupal_ti-drupal_coder-installed" ] - then - return - fi - # Check if drupal/coder is already available. DRUPAL_CODER=$(composer info --no-interaction drupal/coder || echo "") @@ -51,5 +25,5 @@ function drupal_ti_ensure_drupal_coder() { composer global install --no-interaction fi - touch "$TRAVIS_BUILD_DIR/../drupal_ti-drupal_coder-installed" + touch "$TRAVIS_BUILD_DIR/../drupal_ti-phpcs-installed" } diff --git a/runners/phpcs/install.sh b/runners/phpcs/install.sh index 1af5ae8..461e6f5 100755 --- a/runners/phpcs/install.sh +++ b/runners/phpcs/install.sh @@ -3,8 +3,5 @@ set -e $DRUPAL_TI_DEBUG -# Ensure that drupal/coder is installed. -drupal_ti_ensure_drupal_coder - # Ensure that phpcs is installed. drupal_ti_ensure_phpcs From b43cb2e5502c1eefa76db55098a4b5801f44d714 Mon Sep 17 00:00:00 2001 From: Nathaniel Hoag Date: Wed, 18 Apr 2018 17:28:47 -0400 Subject: [PATCH 6/9] Fixup: Formatting update --- functions/phpcs.sh | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/functions/phpcs.sh b/functions/phpcs.sh index 87843bd..d5178ae 100644 --- a/functions/phpcs.sh +++ b/functions/phpcs.sh @@ -6,24 +6,24 @@ # 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 + # 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 "") + # 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 + 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 - touch "$TRAVIS_BUILD_DIR/../drupal_ti-phpcs-installed" + touch "$TRAVIS_BUILD_DIR/../drupal_ti-phpcs-installed" } From 6e0f8e94383ecd0cabe7dbd196dbe0d98bdb0527 Mon Sep 17 00:00:00 2001 From: Nathaniel Hoag Date: Wed, 18 Apr 2018 17:32:09 -0400 Subject: [PATCH 7/9] Remove phpcs version variable --- .travis.yml.dist | 2 -- 1 file changed, 2 deletions(-) diff --git a/.travis.yml.dist b/.travis.yml.dist index ee3f7e4..f351793 100644 --- a/.travis.yml.dist +++ b/.travis.yml.dist @@ -87,8 +87,6 @@ env: # === PHPCS specific variables. # These arguments are passed to the phpcs command. - DRUPAL_TI_PHPCS_ARGS="" - # The version of phpcs that should be used. - - DRUPAL_TI_PHPCS_VERSION="squizlabs/php_codesniffer:^2.9" # The version of drupal/coder that should be used. - DRUPAL_TI_DRUPAL_CODER_VERSION="drupal/coder:^8.2" From be7daa27d62b18b8b7335b5b6d5854a7ca55012a Mon Sep 17 00:00:00 2001 From: Nathaniel Hoag Date: Tue, 29 May 2018 15:07:46 -0400 Subject: [PATCH 8/9] Add drupal/coder standards to phpcs config --- functions/phpcs.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/functions/phpcs.sh b/functions/phpcs.sh index d5178ae..57f4197 100644 --- a/functions/phpcs.sh +++ b/functions/phpcs.sh @@ -25,5 +25,8 @@ function drupal_ti_ensure_phpcs() { 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" } From 49c92556c1a32426c635f3461289430dee31fe9a Mon Sep 17 00:00:00 2001 From: Nathaniel Hoag Date: Tue, 29 May 2018 15:08:51 -0400 Subject: [PATCH 9/9] Add default phpcs arguments --- runners/phpcs/script.sh | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/runners/phpcs/script.sh b/runners/phpcs/script.sh index 91f7377..3a29398 100755 --- a/runners/phpcs/script.sh +++ b/runners/phpcs/script.sh @@ -4,6 +4,16 @@ set -e $DRUPAL_TI_DEBUG -ARGS=( $DRUPAL_TI_PHPCS_ARGS ) +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[@]}"