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 fi
echo "> Script finished with an error" 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() { function getFileCount() {
ALL_DIRECTORIES=("${1:?Target dir is required}"/*) ALL_DIRECTORIES=("${1:?Target dir is required}"/*)
echo ${#ALL_DIRECTORIES[@]} # Sometimes, you just need a count echo ${#ALL_DIRECTORIES[@]} # Sometimes, you just need a count
@@ -47,9 +43,15 @@ function taskPrepareWpPatch() {
rm "${WP_DL_TEMP_DIR?}" -rf rm "${WP_DL_TEMP_DIR?}" -rf
} }
# For each patch, download appropriate WP version, apply patch and check if file syntax is correct afterwards main() {
for PATCH_DIR in patches/*/; do PHP_TESTS_TEMP_DIR="$(mktemp -d -t XXXXXXXXXXX)"
echo "> Deploying task ${PATCH_DIR}" export PHP_TESTS_TEMP_DIR
local patchDir
# 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}"
# Introduce ~50ms overhead before deploying another task # Introduce ~50ms overhead before deploying another task
# Even shorter overhead helps. but better to be on safe side. # Even shorter overhead helps. but better to be on safe side.
@@ -57,28 +59,33 @@ for PATCH_DIR in patches/*/; do
sleep 0.05 sleep 0.05
# Run task concurrently # Run task concurrently
taskPrepareWpPatch "${PATCH_DIR}" & taskPrepareWpPatch "${patchDir}" &
done done
echo "Waiting for all tasks to finish..." echo "Waiting for all tasks to finish..."
wait wait
# Make sure that directory is not empty # Make sure that directory is not empty
if [ ! "$(ls -A "${PHP_TESTS_TEMP_DIR}")" ]; then if [ ! "$(ls -A "${PHP_TESTS_TEMP_DIR}")" ]; then
echo "Error: Target directory is empty" echo "Error: Target directory is empty"
exit 1 return 1
fi fi
NUMBER_OF_PATCHES="$(getFileCount patches)" local numberOfPatches
NUMBER_OF_TEST_FILES="$(getFileCount "${PHP_TESTS_TEMP_DIR}")" local numberOfTestFiles
numberOfPatches="$(getFileCount patches)"
numberOfTestFiles="$(getFileCount "${PHP_TESTS_TEMP_DIR}")"
if [ "${NUMBER_OF_PATCHES}" != "${NUMBER_OF_TEST_FILES}" ]; then if [ "${numberOfPatches}" != "${numberOfTestFiles}" ]; then
echo "> Error - Unexpected number of files" echo "> Error - Unexpected number of files"
echo " Expected: ${NUMBER_OF_PATCHES}" echo " Expected: ${numberOfPatches}"
echo " Actual: ${NUMBER_OF_TEST_FILES}" echo " Actual: ${numberOfTestFiles}"
exit 1 return 1
fi fi
# Run php-lint on resulting patch files # Run php-lint on resulting patch files
php-parallel-lint "${PHP_TESTS_TEMP_DIR}" -s --blame --exclude vendor -p php php-parallel-lint "${PHP_TESTS_TEMP_DIR}" -s --blame --exclude vendor -p php
exit $? return $?
}
main "${@}"