From 7d467db53333f95792aa2e257050c925aa07995d Mon Sep 17 00:00:00 2001 From: Austin Passy <367897+thefrosty@users.noreply.github.com> Date: Wed, 18 Jan 2023 11:56:42 -0800 Subject: [PATCH] Update GitHub Workflow & Cleanup bin shells (#108) * Add reporting to PHPCS. * Updates to local bin shell files. * Wrap exposed features into funtions. * Update to latest install shell. * Update Workflow dependencies to latest version to avoid deprecations in Actions. - Add Changed Files action to get from step. * Add new composite Action. * Update default workflow to use new composite action to be more dynamic. * Update formatting of array for bash. * Remove env. * Update composite to accept a token from the input value. * Misspelled matrix. * Add at least one extension. --- .github/actions/ci-setup/action.yml | 70 ++++++++ .github/workflows/main.yml | 81 +++++---- bin/eslint.sh | 6 +- bin/functions.sh | 103 ++++++++---- bin/install-wp-tests.sh | 248 +++++++++++++--------------- bin/phpcs.sh | 10 +- bin/phpmd.sh | 6 +- composer.json | 2 +- 8 files changed, 323 insertions(+), 203 deletions(-) create mode 100644 .github/actions/ci-setup/action.yml diff --git a/.github/actions/ci-setup/action.yml b/.github/actions/ci-setup/action.yml new file mode 100644 index 0000000..c6acb68 --- /dev/null +++ b/.github/actions/ci-setup/action.yml @@ -0,0 +1,70 @@ +name: CI Setup +description: "Sets up the environment for jobs during CI workflow" +# https://alejandrocelaya.blog/2022/08/19/how-to-reduce-duplication-in-your-github-actions-workflows/ + +inputs: + extensions: + default: 'curl, mysql, zip' + description: 'shivammathur/setup-php extensions' + required: false + extensions-cache-key: + description: 'The key used to cache PHP extensions' + required: true + php-version: + description: 'The PHP version to be setup' + required: true + token: + description: 'A GitHub PAT' + required: true + tools: + default: 'composer' + description: 'shivammathur/setup-php tools' + required: false +outputs: + files: + description: 'All changed files' + value: ${{ steps.files.outputs.all }} + +runs: + using: composite + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup cache extensions + id: extcache + uses: shivammathur/cache-extensions@v1 + with: + php-version: ${{ inputs.php-version }} + extensions: ${{ inputs.extensions }} + key: ${{ inputs.extensions-cache-key }} + + - name: Cache extensions + uses: actions/cache@v3 + with: + path: ${{ steps.extcache.outputs.dir }} + key: ${{ steps.extcache.outputs.key }} + restore-keys: ${{ steps.extcache.outputs.key }} + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ inputs.php-version }} + coverage: xdebug + extensions: ${{ inputs.extensions }} + tools: ${{ inputs.tools }} + + - name: Composer config + run: | + composer config github-oauth.github.com "${{ env.GITHUB_TOKEN }}" + env: + GITHUB_TOKEN: ${{ inputs.token }} + shell: bash + + - name: Composer update + run: composer update --no-interaction --optimize-autoloader + shell: bash + + - name: Get Changed Files + id: files + uses: masesgroup/retrieve-changed-files@v2 diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 36c7895..d362973 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,4 +1,4 @@ -name: Workflow +name: CI Tests on: push: @@ -6,6 +6,9 @@ on: - develop pull_request: +env: + WP_VERSION: 6.1.1 + # Cancels all previous workflow runs for the same branch that have not yet completed. concurrency: # The concurrency group contains the workflow name and the branch name. @@ -13,49 +16,67 @@ concurrency: cancel-in-progress: true jobs: - Build: - runs-on: ubuntu-latest + run-phpcs: + name: Run PHPCS + runs-on: ubuntu-20.04 + if: ${{ github.event_name == 'pull_request' }} strategy: matrix: - php-versions: [ 7.4, 8.0, 8.1 ] + php-versions: [ 8.0, 8.1, 8.2 ] coverage: [ true ] - steps: - name: Checkout - uses: actions/checkout@v2 - with: - fetch-depth: 0 # No shallow clone, we need all history! + uses: actions/checkout@v3 - - name: Setup PHP - uses: shivammathur/setup-php@v2 + - name: Setup + id: ci-setup + uses: ./.github/actions/ci-setup with: + extensions: 'curl' + extensions-cache-key: run-phpcs php-version: ${{ matrix.php-versions }} - coverage: xdebug - tools: composer, cs2pr, phpunit + token: ${{ secrets.GITHUB_TOKEN }} + tools: 'composer, cs2pr, phpcs' - - name: Get composer cache directory - id: composercache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + - name: Run PHPCS + continue-on-error: false + id: phpcs + run: composer phpcs + env: + CHANGED_FILES: ${{ steps.ci-setup.outputs.files }} - - name: Cache dependencies - uses: actions/cache@v2 - with: - path: ${{ steps.composercache.outputs.dir }} - key: php-${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} - restore-keys: ${{ runner.os }}-composer- + - name: Show PHPCS results in PR + if: ${{ always() && steps.phpcs.outcome == 'failure' }} + run: cs2pr ./phpcs-report.xml - - name: Install dependencies - run: composer update --prefer-dist --no-interaction + run-phpunit: + name: Run PHPUnit + runs-on: ubuntu-20.04 + if: ${{ github.event_name == 'pull_request' }} + strategy: + matrix: + php-versions: [ 8.0, 8.1, 8.2 ] + coverage: [ true ] + steps: + - name: Checkout + uses: actions/checkout@v3 - - name: Create all branches - run: source ./bin/create-all-branches.sh + - name: Setup + id: ci-setup + uses: ./.github/actions/ci-setup + with: + extensions: 'curl, mysql, mysqli, tar, zip' + extensions-cache-key: run-phpunit + php-version: ${{ matrix.php-versions }} + token: ${{ secrets.GITHUB_TOKEN }} + tools: 'composer, phpunit' - - name: Run composer tests + - name: Run PHPUnit continue-on-error: false - run: composer tests - - - name: Show PHPCS results in PR - run: cs2pr ./phpcs-report.xml + id: phpunit + run: composer phpunit + env: + CHANGED_FILES: ${{ steps.ci-setup.outputs.files }} - name: Upload coverage to Codecov uses: codecov/codecov-action@v3 diff --git a/bin/eslint.sh b/bin/eslint.sh index a13659a..b83559b 100755 --- a/bin/eslint.sh +++ b/bin/eslint.sh @@ -2,8 +2,8 @@ set -e -echo 'Checking ESLint' source "$(dirname "$0")/functions.sh" +echo 'Checking ESLint' jsFiles="" jsFilesCount=0 @@ -21,6 +21,8 @@ if [[ ${jsFilesCount} == 0 ]]; then exit 0 fi +jsFiles=$(echo "${jsFiles}" | xargs) echo "Checking files: $jsFiles" -npx standard "${jsFiles}" +# shellcheck disable=SC2086 +npx standard ${jsFiles} diff --git a/bin/functions.sh b/bin/functions.sh index 5ae7dae..f372ca4 100644 --- a/bin/functions.sh +++ b/bin/functions.sh @@ -10,35 +10,82 @@ OTHER_ARGUMENTS=() # Loop through arguments and process them # @ref https://pretzelhands.com/posts/command-line-flags/ -for arg in "$@"; do - case $arg in - --default-branch=*) - DEFAULT_BRANCH="${arg#*=}" - shift # Remove --default-branch= from processing - ;; - --test-version=*) - TEST_VERSION="${arg#*=}" - shift # Remove --test-version= from processing - ;; - *) - OTHER_ARGUMENTS+=("$1") - shift # Remove generic argument from processing - ;; - esac -done +function get_arguments() { + for arg in "$@"; do + case $arg in + --default-branch=*) + DEFAULT_BRANCH="${arg#*=}" + shift # Remove --default-branch= from processing + ;; + --test-version=*) + TEST_VERSION="${arg#*=}" + shift # Remove --test-version= from processing + ;; + *) + OTHER_ARGUMENTS+=("$1") + shift # Remove generic argument from processing + ;; + esac + done +} -# Based off: https://gist.github.com/Hounddog/3891872 -if [[ $(git rev-parse --verify HEAD) ]]; then - against='HEAD' -elif [[ $(git rev-parse --verify develop) ]]; then - against='develop' -elif [[ $(git rev-parse --verify main) ]]; then - against='main' -elif [[ $(git rev-parse --verify master) ]]; then - against='master' +# Composer 2.2.x https://getcomposer.org/doc/articles/vendor-binaries.md#finding-the-composer-bin-dir-from-a-binary +if [[ -z "$COMPOSER_BIN_DIR" ]]; then + BIN_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" else - echo "git can't verify HEAD, develop, master, or main." - exit 1 + BIN_DIR="$COMPOSER_BIN_DIR" fi -commitFiles=$(git diff --name-only "$(git merge-base ${DEFAULT_BRANCH:-develop} ${against})") +export BIN_DIR + +function get_branch() { + echo "${GITHUB_BASE_REF:=develop}" +} + +# Based off: https://gist.github.com/Hounddog/3891872 +# Branch to check current commit against +function get_commit_against() { + if [[ $(git rev-parse --verify HEAD) ]]; then + echo 'HEAD' + elif [[ $(git rev-parse --verify develop) ]]; then + echo 'develop' + elif [[ $(git rev-parse --verify main) ]]; then + echo 'main' + elif [[ $(git rev-parse --verify master) ]]; then + echo 'master' + elif [[ $(git rev-parse --verify "$1") ]]; then + echo "$1" + else + echo "git can't verify HEAD, develop, main, or master." + exit 1 + fi +} + +# Helper function to call a bash file with arguments +# $1: The file to call +# $2: The first arguments to pass to the file +# $3: The second arguments to pass to the file +function source_bin_file() { + if [[ ! "${1+x}" ]]; then + echo "Error: missing file" && exit 1 + fi + + FILE=./vendor/bin/"$1" + if [[ -f "$FILE" ]]; then + # shellcheck disable=SC2086 + "$FILE" "${@:2}" + else + # shellcheck disable=SC2086 + "$BIN_DIR"/"$1" "${@:2}" + fi +} + +against=$(get_commit_against) +commit=$(get_branch) +echo "git merge-base commit: ${commit} against: ${against}" +if [[ -z ${CHANGED_FILES+x} ]]; then + #commitFiles=$(git diff --name-only "$(git merge-base "${commit}" "${against}")") + commitFiles=$(git diff --name-only "$(git merge-base ${DEFAULT_BRANCH:-develop} ${against})") + else + commitFiles="${CHANGED_FILES}" +fi diff --git a/bin/install-wp-tests.sh b/bin/install-wp-tests.sh index 67db54f..878881f 100644 --- a/bin/install-wp-tests.sh +++ b/bin/install-wp-tests.sh @@ -1,8 +1,8 @@ #!/usr/bin/env bash if [ $# -lt 3 ]; then - echo "usage: $0 [db-host] [wp-version] [skip-database-creation]" - exit 1 + echo "usage: $0 [db-host] [wp-version] [skip-database-creation]" + exit 1 fi DB_NAME=$1 @@ -18,159 +18,133 @@ WP_TESTS_DIR=${WP_TESTS_DIR-$TMPDIR/wordpress-tests-lib} WP_CORE_DIR=${WP_CORE_DIR-$TMPDIR/wordpress/} download() { - if [ $(which curl) ]; then - curl -s "$1" >"$2" - elif [ $(which wget) ]; then - wget -nv -O "$2" "$1" - fi + if [ `which curl` ]; then + curl -s "$1" > "$2"; + elif [ `which wget` ]; then + wget -nv -O "$2" "$1" + fi } -if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+\-(beta|RC)[0-9]+$ ]]; then - WP_BRANCH=${WP_VERSION%\-*} - WP_TESTS_TAG="branches/$WP_BRANCH" - -elif [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then - WP_TESTS_TAG="branches/$WP_VERSION" +if [[ $WP_VERSION =~ ^[0-9]+\.[0-9]+$ ]]; then + WP_TESTS_TAG="branches/$WP_VERSION" elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0-9]+ ]]; then - if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then - # version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x - WP_TESTS_TAG="tags/${WP_VERSION%??}" - else - WP_TESTS_TAG="tags/$WP_VERSION" - fi + if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then + # version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x + WP_TESTS_TAG="tags/${WP_VERSION%??}" + else + WP_TESTS_TAG="tags/$WP_VERSION" + fi elif [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then - WP_TESTS_TAG="trunk" + WP_TESTS_TAG="trunk" else - # http serves a single offer, whereas https serves multiple. we only want one - download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json - grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json - LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//') - if [[ -z "$LATEST_VERSION" ]]; then - echo "Latest WordPress version could not be found" - exit 1 - fi - WP_TESTS_TAG="tags/$LATEST_VERSION" + # http serves a single offer, whereas https serves multiple. we only want one + download http://api.wordpress.org/core/version-check/1.7/ /tmp/wp-latest.json + grep '[0-9]+\.[0-9]+(\.[0-9]+)?' /tmp/wp-latest.json + LATEST_VERSION=$(grep -o '"version":"[^"]*' /tmp/wp-latest.json | sed 's/"version":"//') + if [[ -z "$LATEST_VERSION" ]]; then + echo "Latest WordPress version could not be found" + exit 1 + fi + WP_TESTS_TAG="tags/$LATEST_VERSION" fi + set -ex install_wp() { - if [ -d $WP_CORE_DIR ]; then - return - fi - - mkdir -p $WP_CORE_DIR - - if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then - mkdir -p $TMPDIR/wordpress-nightly - download https://wordpress.org/nightly-builds/wordpress-latest.zip $TMPDIR/wordpress-nightly/wordpress-nightly.zip - unzip -q $TMPDIR/wordpress-nightly/wordpress-nightly.zip -d $TMPDIR/wordpress-nightly/ - mv $TMPDIR/wordpress-nightly/wordpress/* $WP_CORE_DIR - else - if [ $WP_VERSION == 'latest' ]; then - local ARCHIVE_NAME='latest' - elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+ ]]; then - # https serves multiple offers, whereas http serves single. - download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR/wp-latest.json - if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then - # version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x - LATEST_VERSION=${WP_VERSION%??} - else - # otherwise, scan the releases and get the most up to date minor version of the major release - local VERSION_ESCAPED=$(echo $WP_VERSION | sed 's/\./\\\\./g') - LATEST_VERSION=$(grep -o '"version":"'$VERSION_ESCAPED'[^"]*' $TMPDIR/wp-latest.json | sed 's/"version":"//' | head -1) - fi - if [[ -z "$LATEST_VERSION" ]]; then - local ARCHIVE_NAME="wordpress-$WP_VERSION" - else - local ARCHIVE_NAME="wordpress-$LATEST_VERSION" - fi - else - local ARCHIVE_NAME="wordpress-$WP_VERSION" - fi - download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz - tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR - fi - - download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php + if [ -d $WP_CORE_DIR ]; then + return; + fi + + mkdir -p $WP_CORE_DIR + + if [[ $WP_VERSION == 'nightly' || $WP_VERSION == 'trunk' ]]; then + mkdir -p $TMPDIR/wordpress-nightly + download https://wordpress.org/nightly-builds/wordpress-latest.zip $TMPDIR/wordpress-nightly/wordpress-nightly.zip + unzip -q $TMPDIR/wordpress-nightly/wordpress-nightly.zip -d $TMPDIR/wordpress-nightly/ + mv $TMPDIR/wordpress-nightly/wordpress/* $WP_CORE_DIR + else + if [ $WP_VERSION == 'latest' ]; then + local ARCHIVE_NAME='latest' + elif [[ $WP_VERSION =~ [0-9]+\.[0-9]+ ]]; then + # https serves multiple offers, whereas http serves single. + download https://api.wordpress.org/core/version-check/1.7/ $TMPDIR/wp-latest.json + if [[ $WP_VERSION =~ [0-9]+\.[0-9]+\.[0] ]]; then + # version x.x.0 means the first release of the major version, so strip off the .0 and download version x.x + LATEST_VERSION=${WP_VERSION%??} + else + # otherwise, scan the releases and get the most up to date minor version of the major release + local VERSION_ESCAPED=`echo $WP_VERSION | sed 's/\./\\\\./g'` + LATEST_VERSION=$(grep -o '"version":"'$VERSION_ESCAPED'[^"]*' $TMPDIR/wp-latest.json | sed 's/"version":"//' | head -1) + fi + if [[ -z "$LATEST_VERSION" ]]; then + local ARCHIVE_NAME="wordpress-$WP_VERSION" + else + local ARCHIVE_NAME="wordpress-$LATEST_VERSION" + fi + else + local ARCHIVE_NAME="wordpress-$WP_VERSION" + fi + download https://wordpress.org/${ARCHIVE_NAME}.tar.gz $TMPDIR/wordpress.tar.gz + tar --strip-components=1 -zxmf $TMPDIR/wordpress.tar.gz -C $WP_CORE_DIR + fi + + download https://raw.github.com/markoheijnen/wp-mysqli/master/db.php $WP_CORE_DIR/wp-content/db.php } install_test_suite() { - # portable in-place argument for both GNU sed and Mac OSX sed - if [[ $(uname -s) == 'Darwin' ]]; then - local ioption='-i.bak' - else - local ioption='-i' - fi - - # set up testing suite if it doesn't yet exist - if [ ! -d $WP_TESTS_DIR ]; then - # set up testing suite - mkdir -p $WP_TESTS_DIR - svn co --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes - svn co --quiet --ignore-externals https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data - fi - - if [ ! -f wp-tests-config.php ]; then - download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php - # remove all forward slashes in the end - WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::") - sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php - sed $ioption "s:__DIR__ . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php - sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php - sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php - sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php - sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php - fi + # portable in-place argument for both GNU sed and Mac OSX sed + if [[ $(uname -s) == 'Darwin' ]]; then + local ioption='-i .bak' + else + local ioption='-i' + fi + + # set up testing suite if it doesn't yet exist + if [ ! -d $WP_TESTS_DIR ]; then + # set up testing suite + mkdir -p $WP_TESTS_DIR + svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/includes/ $WP_TESTS_DIR/includes + svn co --quiet https://develop.svn.wordpress.org/${WP_TESTS_TAG}/tests/phpunit/data/ $WP_TESTS_DIR/data + fi + + if [ ! -f wp-tests-config.php ]; then + download https://develop.svn.wordpress.org/${WP_TESTS_TAG}/wp-tests-config-sample.php "$WP_TESTS_DIR"/wp-tests-config.php + # remove all forward slashes in the end + WP_CORE_DIR=$(echo $WP_CORE_DIR | sed "s:/\+$::") + sed $ioption "s:dirname( __FILE__ ) . '/src/':'$WP_CORE_DIR/':" "$WP_TESTS_DIR"/wp-tests-config.php + sed $ioption "s/youremptytestdbnamehere/$DB_NAME/" "$WP_TESTS_DIR"/wp-tests-config.php + sed $ioption "s/yourusernamehere/$DB_USER/" "$WP_TESTS_DIR"/wp-tests-config.php + sed $ioption "s/yourpasswordhere/$DB_PASS/" "$WP_TESTS_DIR"/wp-tests-config.php + sed $ioption "s|localhost|${DB_HOST}|" "$WP_TESTS_DIR"/wp-tests-config.php + fi } -recreate_db() { - shopt -s nocasematch - if [[ $1 =~ ^(y|yes)$ ]]; then - mysqladmin drop $DB_NAME -f --user="$DB_USER" --password="$DB_PASS"$EXTRA - create_db - echo "Recreated the database ($DB_NAME)." - else - echo "Leaving the existing database ($DB_NAME) in place." - fi - shopt -u nocasematch -} - -create_db() { - mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA -} - install_db() { - if [ ${SKIP_DB_CREATE} = "true" ]; then - return 0 - fi - - # parse DB_HOST for port or socket references - local PARTS=(${DB_HOST//\:/ }) - local DB_HOSTNAME=${PARTS[0]} - local DB_SOCK_OR_PORT=${PARTS[1]} - local EXTRA="" - - if ! [ -z $DB_HOSTNAME ]; then - if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then - EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp" - elif ! [ -z $DB_SOCK_OR_PORT ]; then - EXTRA=" --socket=$DB_SOCK_OR_PORT" - elif ! [ -z $DB_HOSTNAME ]; then - EXTRA=" --host=$DB_HOSTNAME --protocol=tcp" - fi - fi - - # create database - if [ $(mysql --user="$DB_USER" --password="$DB_PASS" --execute='show databases;' | grep ^$DB_NAME$) ]; then -# echo "Reinstalling will delete the existing test database ($DB_NAME)" -# read -p 'Are you sure you want to proceed? [y/N]: ' DELETE_EXISTING_DB - recreate_db "yes" - else - create_db - fi + if [ ${SKIP_DB_CREATE} = "true" ]; then + return 0 + fi + + # parse DB_HOST for port or socket references + local PARTS=(${DB_HOST//\:/ }) + local DB_HOSTNAME=${PARTS[0]}; + local DB_SOCK_OR_PORT=${PARTS[1]}; + local EXTRA="" + + if ! [ -z $DB_HOSTNAME ] ; then + if [ $(echo $DB_SOCK_OR_PORT | grep -e '^[0-9]\{1,\}$') ]; then + EXTRA=" --host=$DB_HOSTNAME --port=$DB_SOCK_OR_PORT --protocol=tcp" + elif ! [ -z $DB_SOCK_OR_PORT ] ; then + EXTRA=" --socket=$DB_SOCK_OR_PORT" + elif ! [ -z $DB_HOSTNAME ] ; then + EXTRA=" --host=$DB_HOSTNAME --protocol=tcp" + fi + fi + + # create database + mysqladmin create $DB_NAME --user="$DB_USER" --password="$DB_PASS"$EXTRA } install_wp diff --git a/bin/phpcs.sh b/bin/phpcs.sh index c0abc97..37757c7 100644 --- a/bin/phpcs.sh +++ b/bin/phpcs.sh @@ -2,10 +2,10 @@ set -e -echo 'Checking PHPCS' source "$(dirname "$0")/functions.sh" +echo 'Checking PHPCS' -args="-s --colors --extensions=php --tab-width=4 --standard=phpcs-ruleset.xml --runtime-set testVersion ${TEST_VERSION}-" +args="--standard=phpcs-ruleset.xml --runtime-set testVersion ${TEST_VERSION}-" phpFiles="" phpFilesCount=0 for f in ${commitFiles}; do @@ -28,4 +28,8 @@ if [[ ${phpFilesCount} -gt 2 ]] && { [[ ${GITHUB_ACTIONS+x} ]] || [[ ${CIRCLECI+ args="$args --report=summary" fi -./vendor/bin/phpcs ${args} ${phpFiles} +phpFiles=$(echo "${phpFiles}" | xargs) +echo "Checking files: $phpFiles" + +# shellcheck disable=SC2086 +source_bin_file phpcs "${args}" ${phpFiles} diff --git a/bin/phpmd.sh b/bin/phpmd.sh index 32a9ecd..c38e357 100644 --- a/bin/phpmd.sh +++ b/bin/phpmd.sh @@ -2,8 +2,8 @@ set -e -echo 'Checking PHPMD' source "$(dirname "$0")/functions.sh" +echo 'Checking PHPMD' args="text phpmd-ruleset.xml --exclude tests,vendor --suffixes php" phpFiles="" @@ -22,8 +22,10 @@ if [[ ${phpFilesCount} == 0 ]]; then exit 0 fi +phpFiles=$(echo "${phpFiles:1}" | xargs) echo "Checking files: $phpFiles" +# shellcheck disable=SC2086 for file in ${phpFiles}; do - ./vendor/bin/phpmd ${file} ${args} + source_bin_file phpmd ${file} "${args}" done diff --git a/composer.json b/composer.json index ebb1d16..66efd6e 100644 --- a/composer.json +++ b/composer.json @@ -63,7 +63,7 @@ "Dealerdirect\\Composer\\Plugin\\Installers\\PHPCodeSniffer\\Plugin::run" ], "phpcs": [ - "bash ./bin/phpcs.sh" + "bash ./bin/phpcs.sh --report-full --report-checkstyle=./phpcs-report.xml" ], "phpmd": [ "bash ./bin/phpmd.sh"