Use separate scripts to ci tests (#907)

* Run ci static analysis checks using scripts

* Clean up

* Move phpunit run to dedicated script

* Use run.sh and remove ci.sh

* Rename test scripts to be prefixed with "run_"

* Move static analysis runs to test script

* Clean up
This commit is contained in:
Zach Borboa
2025-01-10 21:44:05 -05:00
committed by GitHub
parent 55e95572fc
commit 87fc9b3796
13 changed files with 112 additions and 205 deletions
+1 -11
View File
@@ -41,17 +41,7 @@ jobs:
persist-credentials: false
- name: Test
run: bash tests/ci.sh
run: bash tests/run.sh
env:
CI_PHP_VERSION: ${{ matrix.php-version }}
CI_PHP_FUTURE_RELEASE: ${{ matrix.future-release }}
- name: Static analysis - Psalm
run: 'vendor/bin/psalm --config="tests/psalm.xml"'
# TODO: Remove exclusion that skips running psalm on PHP 8.4 when psalm
# supports PHP 8.4 (https://github.com/vimeo/psalm/issues/11107).
if: ${{ matrix.php-version < 8.4 }}
- name: Static analysis - PHPStan
run: 'vendor/bin/phpstan analyse --configuration="phpstan.neon" .'
if: ${{ matrix.php-version >= 7.4 }}
+1 -1
View File
@@ -30,4 +30,4 @@ cd php-curl-class/
### Continuous Integration Tests
Continuous integration runs [tests/ci.sh](https://github.com/php-curl-class/php-curl-class/blob/master/tests/ci.sh) on supported PHP versions and is configured with [.github/workflows/ci.yml](https://github.com/php-curl-class/php-curl-class/blob/master/.github/workflows/ci.yml).
Continuous integration runs [tests/run.sh](https://github.com/php-curl-class/php-curl-class/blob/master/tests/run.sh) on supported PHP versions and is configured with [.github/workflows/ci.yml](https://github.com/php-curl-class/php-curl-class/blob/master/.github/workflows/ci.yml).
-11
View File
@@ -1,11 +0,0 @@
#!/usr/bin/env bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${SCRIPT_DIR}"
# Run commands from the project root directory.
cd ..
set -x
vendor/bin/psalm --config="tests/psalm.xml"
+11
View File
@@ -0,0 +1,11 @@
error_count="${#errors[@]}"
if [[ "${error_count}" -ge 1 ]]; then
echo -e "\nErrors found: ${error_count}"
iter=0
for value in "${errors[@]}"; do
((iter++))
echo -e "\nError ${iter} of ${error_count}:"
echo "${value}" | perl -pe 's/^(.*)$/\t\1/'
done
fi
+27 -127
View File
@@ -1,152 +1,52 @@
#!/usr/bin/env bash
remove_expectWarning() {
# Fix "Call to undefined method CurlTest\CurlTest::expectWarning()".
if sed v < /dev/null 2> /dev/null; then
sed -i"" -e "/->expectWarning(/d" "./PHPCurlClass/PHP"*
else
sed -i "" -e "/->expectWarning(/d" "./PHPCurlClass/PHP"*
fi
}
replace_assertStringContainsString() {
# -->assertStringContainsString(
# +->assertContains(
find='->assertStringContainsString('
replace='->assertContains('
if sed v < /dev/null 2> /dev/null; then
sed -i"" -e "s/${find}/${replace}/" "./PHPCurlClass/PHP"*
else
sed -i "" -e "s/${find}/${replace}/" "./PHPCurlClass/PHP"*
fi
}
replace_assertMatchesRegularExpression() {
# -->assertMatchesRegularExpression(
# +->assertRegExp(
find='->assertMatchesRegularExpression('
replace='->assertRegExp('
if sed v < /dev/null 2> /dev/null; then
sed -i"" -e "s/${find}/${replace}/" "./PHPCurlClass/PHP"*
else
sed -i "" -e "s/${find}/${replace}/" "./PHPCurlClass/PHP"*
fi
}
phpunit_v6_5_shim() {
remove_expectWarning
replace_assertMatchesRegularExpression
replace_assertStringContainsString
}
phpunit_v7_5_shim() {
remove_expectWarning
replace_assertMatchesRegularExpression
}
phpunit_v8_5_shim() {
remove_expectWarning
replace_assertMatchesRegularExpression
}
phpunit_v9_shim() {
replace_assertMatchesRegularExpression
}
phpunit_v10_shim() {
remove_expectWarning
}
set -x
if [[ "${CI}" == "true" ]]; then
composer self-update
# TODO: Add "vimeo/psalm" back into composer.json under "require-dev" when
# vimeo/psalm supports PHP 8.4 (https://github.com/vimeo/psalm/issues/11107):
# "require-dev": {
# "vimeo/psalm": ">=5.26.1"
# },
#
# TODO: Remove this workaround that only installs vimeo/psalm on PHP < 8.4 when
# vimeo/psalm supports PHP 8.4 (https://github.com/vimeo/psalm/issues/11107):
if [[ $(echo "${CI_PHP_VERSION} < 8.4" | bc -l) -eq 1 ]]; then
composer require --dev "vimeo/psalm:>=5.26.1"
fi
composer install --prefer-source --no-interaction
fi
# Use composer's phpunit and phpcs by adding composer bin directory to the path environment variable.
export PATH="${PWD}/vendor/bin:${PATH}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${SCRIPT_DIR}"
source "set_vars.inc.sh"
echo "CI_PHP_VERSION: ${CI_PHP_VERSION}"
echo "CI_PHP_FUTURE_RELEASE: ${CI_PHP_FUTURE_RELEASE}"
php -r "var_dump(phpversion());"
php -r "var_dump(curl_version());"
# Let test server know we should allow testing.
export PHP_CURL_CLASS_TEST_MODE_ENABLED="yes"
# Start test servers. Run servers on different ports to allow simultaneous
# requests without blocking.
server_count=7
declare -A pids
for i in $(seq 0 $(("${server_count}" - 1))); do
port=8000
(( port += $i ))
php -S "127.0.0.1:${port}" server.php &> /dev/null &
pids["${i}"]="${!}"
done
errors=()
source "check_syntax.sh"
source "run_syntax_check.sh"
# Determine which phpunit to use.
if [[ -f "../vendor/bin/phpunit" ]]; then
phpunit_to_use="../vendor/bin/phpunit"
else
phpunit_to_use="phpunit"
fi
source "run_coding_standards_check.sh"
phpunit_version="$("${phpunit_to_use}" --version | grep -Eo "[0-9]+\.[0-9]+\.[0-9]+")"
echo "phpunit_version: ${phpunit_version}"
source "run_phpunit.sh"
extra_args="${@}"
if [[ "${phpunit_version}" == "6.5."* ]]; then
phpunit_v6_5_shim
phpunit_args=" --debug --verbose --fail-on-risky ${extra_args}"
elif [[ "${phpunit_version}" == "7.5."* ]]; then
phpunit_v7_5_shim
phpunit_args=" --debug --verbose --fail-on-risky ${extra_args}"
elif [[ "${phpunit_version}" == "8.5."* ]]; then
phpunit_v8_5_shim
phpunit_args=" --debug --verbose --fail-on-risky ${extra_args}"
elif [[ "${phpunit_version}" == "9."* ]]; then
phpunit_v9_shim
phpunit_args=" --debug --verbose --fail-on-risky ${extra_args}"
elif [[ "${phpunit_version}" == "10."* ]]; then
phpunit_v10_shim
phpunit_args=" --display-incomplete --display-skipped --display-deprecations --display-errors --display-notices --display-warnings --fail-on-risky ${extra_args}"
fi
source "run_static_analysis_check_phpstan.sh"
# Run tests.
"${phpunit_to_use}" --version
"${phpunit_to_use}" \
--configuration "phpunit.xml" \
${phpunit_args}
if [[ "${?}" -ne 0 ]]; then
echo "Error: phpunit command failed"
errors+=("phpunit command failed")
fi
source "run_static_analysis_check_psalm.sh"
source "check_coding_standards.sh"
set +x
error_count="${#errors[@]}"
if [[ "${error_count}" -ge 1 ]]; then
echo -e "\nErrors found: ${error_count}"
iter=0
for value in "${errors[@]}"; do
((iter++))
echo -e "\nError ${iter} of ${error_count}:"
echo "${value}" | perl -pe 's/^(.*)$/\t\1/'
done
fi
# Stop test servers.
for pid in "${pids[@]}"; do
kill "${pid}" &> /dev/null &
done
source "display_errors.inc.sh"
if [[ "${CI_PHP_FUTURE_RELEASE}" != "true" ]]; then
exit "${#errors[@]}"
@@ -1,8 +1,12 @@
#!/usr/bin/env bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${SCRIPT_DIR}"
source "set_vars.inc.sh"
# Run commands from the project root directory.
cd ..
pushd ..
# Enforce line ending consistency in php files.
crlf_file=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --files-with-matches $'\r' {} \;)
@@ -128,3 +132,5 @@ if [[ "${?}" -ne 0 ]]; then
fi
fi
popd
+1 -53
View File
@@ -57,35 +57,9 @@ phpunit_v10_shim() {
remove_expectWarning
}
set -x
composer self-update
# TODO: Add "vimeo/psalm" back into composer.json under "require-dev" when
# vimeo/psalm supports PHP 8.4 (https://github.com/vimeo/psalm/issues/11107):
# "require-dev": {
# "vimeo/psalm": ">=5.26.1"
# },
#
# TODO: Remove this workaround that only installs vimeo/psalm on PHP < 8.4 when
# vimeo/psalm supports PHP 8.4 (https://github.com/vimeo/psalm/issues/11107):
if [[ $(echo "${CI_PHP_VERSION} < 8.4" | bc -l) -eq 1 ]]; then
composer require --dev "vimeo/psalm:>=5.26.1"
fi
composer install --prefer-source --no-interaction
# Use composer's phpunit and phpcs by adding composer bin directory to the path environment variable.
export PATH="${PWD}/vendor/bin:${PATH}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${SCRIPT_DIR}"
echo "CI_PHP_VERSION: ${CI_PHP_VERSION}"
echo "CI_PHP_FUTURE_RELEASE: ${CI_PHP_FUTURE_RELEASE}"
php -r "var_dump(phpversion());"
php -r "var_dump(curl_version());"
# Let test server know we should allow testing.
export PHP_CURL_CLASS_TEST_MODE_ENABLED="yes"
@@ -101,10 +75,6 @@ for i in $(seq 0 $(("${server_count}" - 1))); do
pids["${i}"]="${!}"
done
errors=()
source "check_syntax.sh"
# Determine which phpunit to use.
if [[ -f "../vendor/bin/phpunit" ]]; then
phpunit_to_use="../vendor/bin/phpunit"
@@ -143,29 +113,7 @@ if [[ "${?}" -ne 0 ]]; then
errors+=("phpunit command failed")
fi
source "check_coding_standards.sh"
set +x
error_count="${#errors[@]}"
if [[ "${error_count}" -ge 1 ]]; then
echo -e "\nErrors found: ${error_count}"
iter=0
for value in "${errors[@]}"; do
((iter++))
echo -e "\nError ${iter} of ${error_count}:"
echo "${value}" | perl -pe 's/^(.*)$/\t\1/'
done
fi
# Stop test servers.
for pid in "${pids[@]}"; do
kill "${pid}" &> /dev/null &
kill "${pid}" &> /dev/null &
done
if [[ "${CI_PHP_FUTURE_RELEASE}" != "true" ]]; then
exit "${#errors[@]}"
elif [[ "${#errors[@]}" -ne 0 ]]; then
echo "One or more tests failed, but allowed as the CI_PHP_FUTURE_RELEASE flag is on for PHP version ${CI_PHP_VERSION}."
fi
+23
View File
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${SCRIPT_DIR}"
source "set_vars.inc.sh"
# Run commands from the project root directory.
pushd ..
set -x
if [[ $(echo "${CI_PHP_VERSION} >= 7.4" | bc -l) -eq 1 ]]; then
vendor/bin/phpstan analyse --configuration="phpstan.neon" .
if [[ "${?}" -ne 0 ]]; then
echo "Error: phpstan static analysis check failed"
errors+=("phpstan static analysis check failed")
fi
else
echo "Skipped running phpstan check"
fi
popd
+25
View File
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${SCRIPT_DIR}"
source "set_vars.inc.sh"
# Run commands from the project root directory.
pushd ..
set -x
# TODO: Remove exclusion that skips running psalm on PHP 8.4 when psalm
# supports PHP 8.4 (https://github.com/vimeo/psalm/issues/11107).
if [[ $(echo "${CI_PHP_VERSION} < 8.4" | bc -l) -eq 1 ]]; then
vendor/bin/psalm --config="tests/psalm.xml"
if [[ "${?}" -ne 0 ]]; then
echo "Error: psalm static analysis check failed"
errors+=("psalm static analysis check failed")
fi
else
echo "Skipped running psalm check"
fi
popd
@@ -1,9 +1,16 @@
#!/usr/bin/env bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${SCRIPT_DIR}"
# Run commands from the project root directory.
pushd ..
# Check syntax in php files. Use `xargs' over `find -exec' as xargs exits with a value of 1 when any command errors.
find .. -type "f" -iname "*.php" ! -path "*/vendor/*" | xargs -L "1" php -l
find . -type "f" -iname "*.php" ! -path "*/vendor/*" | xargs -L "1" php -l
if [[ "${?}" -ne 0 ]]; then
echo "Error: php syntax checks failed"
errors+=("php syntax checks failed")
fi
popd
+4
View File
@@ -0,0 +1,4 @@
# Use installed version when variable not set.
if [[ -z "${CI_PHP_VERSION}" ]]; then
CI_PHP_VERSION="$(php -r "echo preg_replace('/^([0-9]+\.[0-9]+)\.[0-9]+/', '\$1', phpversion());")"
fi
+2
View File
@@ -1,3 +1,5 @@
#!/usr/bin/env bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${SCRIPT_DIR}"
+2
View File
@@ -1,3 +1,5 @@
#!/usr/bin/env bash
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "${SCRIPT_DIR}"