Add main wrapper

This commit is contained in:
2025-02-09 00:38:00 +01:00
parent 933e25a75a
commit 096b72c3d2

View File

@@ -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 $?
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 "${@}"