From 096b72c3d20de61c16ad3c5d78887cfcba05e666 Mon Sep 17 00:00:00 2001 From: xZero707 Date: Sun, 9 Feb 2025 00:38:00 +0100 Subject: [PATCH] Add main wrapper --- build/tests-util/wp-patch-tests.sh | 73 ++++++++++++++++-------------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/build/tests-util/wp-patch-tests.sh b/build/tests-util/wp-patch-tests.sh index ffa3031..4b4d81a 100755 --- a/build/tests-util/wp-patch-tests.sh +++ b/build/tests-util/wp-patch-tests.sh @@ -20,13 +20,9 @@ function scriptExitHandler() { fi echo "> Script finished with an error" - exit "${LAST_EXIT_CODE}" + return "${LAST_EXIT_CODE}" } -set -e - -PHP_TESTS_TEMP_DIR="$(mktemp -d -t XXXXXXXXXXX)" - function getFileCount() { ALL_DIRECTORIES=("${1:?Target dir is required}"/*) echo ${#ALL_DIRECTORIES[@]} # Sometimes, you just need a count @@ -47,38 +43,49 @@ function taskPrepareWpPatch() { rm "${WP_DL_TEMP_DIR?}" -rf } -# For each patch, download appropriate WP version, apply patch and check if file syntax is correct afterwards -for PATCH_DIR in patches/*/; do - echo "> Deploying task ${PATCH_DIR}" +main() { + PHP_TESTS_TEMP_DIR="$(mktemp -d -t XXXXXXXXXXX)" + export PHP_TESTS_TEMP_DIR - # Introduce ~50ms overhead before deploying another task - # Even shorter overhead helps. but better to be on safe side. - # This should prevent concurrency issues - sleep 0.05 + local patchDir - # Run task concurrently - taskPrepareWpPatch "${PATCH_DIR}" & -done + # For each patch, download appropriate WP version, apply patch and check if file syntax is correct afterwards + for patchDir in patches/*/; do + echo "> Deploying task ${patchDir}" -echo "Waiting for all tasks to finish..." -wait + # Introduce ~50ms overhead before deploying another task + # Even shorter overhead helps. but better to be on safe side. + # This should prevent concurrency issues + sleep 0.05 -# Make sure that directory is not empty -if [ ! "$(ls -A "${PHP_TESTS_TEMP_DIR}")" ]; then - echo "Error: Target directory is empty" - exit 1 -fi + # Run task concurrently + taskPrepareWpPatch "${patchDir}" & + done -NUMBER_OF_PATCHES="$(getFileCount patches)" -NUMBER_OF_TEST_FILES="$(getFileCount "${PHP_TESTS_TEMP_DIR}")" + echo "Waiting for all tasks to finish..." + wait -if [ "${NUMBER_OF_PATCHES}" != "${NUMBER_OF_TEST_FILES}" ]; then - echo "> Error - Unexpected number of files" - echo " Expected: ${NUMBER_OF_PATCHES}" - echo " Actual: ${NUMBER_OF_TEST_FILES}" - exit 1 -fi + # Make sure that directory is not empty + if [ ! "$(ls -A "${PHP_TESTS_TEMP_DIR}")" ]; then + echo "Error: Target directory is empty" + return 1 + fi -# Run php-lint on resulting patch files -php-parallel-lint "${PHP_TESTS_TEMP_DIR}" -s --blame --exclude vendor -p php -exit $? \ No newline at end of file + local numberOfPatches + local numberOfTestFiles + numberOfPatches="$(getFileCount patches)" + numberOfTestFiles="$(getFileCount "${PHP_TESTS_TEMP_DIR}")" + + if [ "${numberOfPatches}" != "${numberOfTestFiles}" ]; then + echo "> Error - Unexpected number of files" + echo " Expected: ${numberOfPatches}" + echo " Actual: ${numberOfTestFiles}" + return 1 + fi + + # Run php-lint on resulting patch files + php-parallel-lint "${PHP_TESTS_TEMP_DIR}" -s --blame --exclude vendor -p php + return $? +} + +main "${@}"