Skip to content

Commit

Permalink
Add new bin CI Shell scrpts for PHPStan & Psalm (#131)
Browse files Browse the repository at this point in the history
* Add PHPStan and Psalm shell scripts.

* Update composer phpstan and add composer pslam to scripts.
  • Loading branch information
thefrosty authored Mar 14, 2024
1 parent 5b7898e commit 8e9a65c
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 2 deletions.
38 changes: 38 additions & 0 deletions bin/phpstan.sh
Original file line number Diff line number Diff line change
@@ -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}
38 changes: 38 additions & 0 deletions bin/psalm.sh
Original file line number Diff line number Diff line change
@@ -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}
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 8e9a65c

Please sign in to comment.