From 8e9a65c8d1ad553cb07c1dd83e9470a483791bd2 Mon Sep 17 00:00:00 2001 From: Austin Passy <367897+thefrosty@users.noreply.github.com> Date: Thu, 14 Mar 2024 10:25:09 -0700 Subject: [PATCH] Add new bin CI Shell scrpts for PHPStan & Psalm (#131) * Add PHPStan and Psalm shell scripts. * Update composer phpstan and add composer pslam to scripts. --- bin/phpstan.sh | 38 ++++++++++++++++++++++++++++++++++++++ bin/psalm.sh | 38 ++++++++++++++++++++++++++++++++++++++ composer.json | 7 +++++-- 3 files changed, 81 insertions(+), 2 deletions(-) create mode 100755 bin/phpstan.sh create mode 100755 bin/psalm.sh diff --git a/bin/phpstan.sh b/bin/phpstan.sh new file mode 100755 index 0000000..4324623 --- /dev/null +++ b/bin/phpstan.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +set -e + +source "$(dirname "$0")/functions.sh" +echo 'Running PHPStan' + +against="${GITHUB_HEAD_REF:=$(get_commit_against)}" +commit="${GITHUB_BASE_REF:=develop}" +echo "git merge-base commit: ${commit} against: ${against}" +if [[ -z ${CHANGED_FILES+x} ]]; then + commitFiles=$(git diff --name-only "$(git merge-base "${commit}" "${against}")") +else + commitFiles="${CHANGED_FILES}" +fi + +args="${ARGS:=analyze --memory-limit 1G}" +phpFiles="" +phpFilesCount=0 +for f in ${commitFiles}; do + if [[ ! -e ${f} ]]; then + continue + fi + if [[ ${f} =~ \.(php|ctp)$ && ! ${f} =~ ^tests/ ]]; then + phpFilesCount=$((phpFilesCount + 1)) + phpFiles="$phpFiles $f" + fi +done +if [[ ${phpFilesCount} == 0 ]]; then + echo "No PHP files updated, nothing to check." + exit 0 +fi + +phpFiles=$(echo "${phpFiles}" | xargs) +echo "Checking files: $phpFiles" + +# shellcheck disable=SC2086 +source_bin_file phpstan ${args} ${phpFiles} diff --git a/bin/psalm.sh b/bin/psalm.sh new file mode 100755 index 0000000..61abda6 --- /dev/null +++ b/bin/psalm.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +set -e + +source "$(dirname "$0")/functions.sh" +echo 'Running Psalm' + +against="${GITHUB_HEAD_REF:=$(get_commit_against)}" +commit="${GITHUB_BASE_REF:=develop}" +echo "git merge-base commit: ${commit} against: ${against}" +if [[ -z ${CHANGED_FILES+x} ]]; then + commitFiles=$(git diff --name-only "$(git merge-base "${commit}" "${against}")") +else + commitFiles="${CHANGED_FILES}" +fi + +args="${ARGS:=--config=psalm.xml --show-info=true}" +phpFiles="" +phpFilesCount=0 +for f in ${commitFiles}; do + if [[ ! -e ${f} ]]; then + continue + fi + if [[ ${f} =~ \.(php|ctp)$ && ! ${f} =~ ^tests/ ]]; then + phpFilesCount=$((phpFilesCount + 1)) + phpFiles="$phpFiles $f" + fi +done +if [[ ${phpFilesCount} == 0 ]]; then + echo "No PHP files updated, nothing to check." + exit 0 +fi + +phpFiles=$(echo "${phpFiles}" | xargs) +echo "Checking files: $phpFiles" + +# shellcheck disable=SC2086 +source_bin_file psalm ${args} ${phpFiles} diff --git a/composer.json b/composer.json index 29b7eef..667e477 100644 --- a/composer.json +++ b/composer.json @@ -74,11 +74,14 @@ "phpmd": [ "bash ./bin/phpmd.sh" ], + "phpstan": [ + ".bash ./bin/phpstan.sh" + ], "phpunit": [ "./vendor/bin/phpunit --colors --coverage-html ./tests/results && php ./tests/clover-results.php ./tests/clover.xml 2" ], - "phpstan": [ - "./vendor/bin/phpstan analyze src --memory-limit 1G" + "psalm": [ + ".bash ./bin/psalm.sh" ], "tests": [ "@phpcs",