mirror of
https://github.com/N0rthernL1ghts/wordpress.git
synced 2025-12-08 14:02:41 +01:00
Add main wrapper
This commit is contained in:
@@ -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,38 +43,49 @@ 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
|
||||||
|
|
||||||
# Introduce ~50ms overhead before deploying another task
|
local patchDir
|
||||||
# Even shorter overhead helps. but better to be on safe side.
|
|
||||||
# This should prevent concurrency issues
|
|
||||||
sleep 0.05
|
|
||||||
|
|
||||||
# Run task concurrently
|
# For each patch, download appropriate WP version, apply patch and check if file syntax is correct afterwards
|
||||||
taskPrepareWpPatch "${PATCH_DIR}" &
|
for patchDir in patches/*/; do
|
||||||
done
|
echo "> Deploying task ${patchDir}"
|
||||||
|
|
||||||
echo "Waiting for all tasks to finish..."
|
# Introduce ~50ms overhead before deploying another task
|
||||||
wait
|
# 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
|
# Run task concurrently
|
||||||
if [ ! "$(ls -A "${PHP_TESTS_TEMP_DIR}")" ]; then
|
taskPrepareWpPatch "${patchDir}" &
|
||||||
echo "Error: Target directory is empty"
|
done
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
NUMBER_OF_PATCHES="$(getFileCount patches)"
|
echo "Waiting for all tasks to finish..."
|
||||||
NUMBER_OF_TEST_FILES="$(getFileCount "${PHP_TESTS_TEMP_DIR}")"
|
wait
|
||||||
|
|
||||||
if [ "${NUMBER_OF_PATCHES}" != "${NUMBER_OF_TEST_FILES}" ]; then
|
# Make sure that directory is not empty
|
||||||
echo "> Error - Unexpected number of files"
|
if [ ! "$(ls -A "${PHP_TESTS_TEMP_DIR}")" ]; then
|
||||||
echo " Expected: ${NUMBER_OF_PATCHES}"
|
echo "Error: Target directory is empty"
|
||||||
echo " Actual: ${NUMBER_OF_TEST_FILES}"
|
return 1
|
||||||
exit 1
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
# Run php-lint on resulting patch files
|
local numberOfPatches
|
||||||
php-parallel-lint "${PHP_TESTS_TEMP_DIR}" -s --blame --exclude vendor -p php
|
local numberOfTestFiles
|
||||||
exit $?
|
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 "${@}"
|
||||||
|
|||||||
Reference in New Issue
Block a user