Making deploy more robust

This commit is contained in:
Adrian Stephens 2026-05-16 16:33:08 +01:00
parent 39d96bfa18
commit ce50edc04a
6 changed files with 80 additions and 3 deletions

BIN
dist/feca_mailshots_plugin-1.0.30.zip vendored Normal file

Binary file not shown.

View File

@ -3,7 +3,7 @@
* Plugin Name: FECA Mailshots
* Plugin URI: https://fenedge.co.uk/
* Description: FECA mailshots plugin.
* Version: 1.0.29
* Version: 1.0.31
* Requires at least: 6.0
* Requires PHP: 7.4
* Author: FECA

View File

@ -8,12 +8,41 @@ $autoloadCandidates = [
dirname(__DIR__, 2) . '/vendor/autoload.php', // Backward-compatible: workspace/shared vendor
];
foreach ($autoloadCandidates as $composerAutoload) {
if (is_file($composerAutoload)) {
if (is_file($composerAutoload) && feca_mailshots_composer_autoload_is_usable($composerAutoload)) {
try {
require_once $composerAutoload;
} catch (\Throwable $e) {
error_log('FECA Mailshots skipped unusable Composer autoload: ' . $e->getMessage());
continue;
}
break;
}
}
function feca_mailshots_composer_autoload_is_usable(string $composerAutoload): bool
{
$vendorDir = dirname($composerAutoload);
$autoloadFiles = $vendorDir . '/composer/autoload_files.php';
if (!is_file($autoloadFiles)) {
return true;
}
$files = require $autoloadFiles;
if (!is_array($files)) {
error_log('FECA Mailshots Composer autoload_files.php did not return an array.');
return false;
}
foreach ($files as $file) {
if (!is_string($file) || !is_file($file)) {
error_log('FECA Mailshots Composer dependency file is missing: ' . (is_scalar($file) ? (string) $file : 'unknown'));
return false;
}
}
return true;
}
spl_autoload_register(static function (string $class): void {
$prefix = 'FecaMailshots\\';
if (strncmp($class, $prefix, strlen($prefix)) !== 0) {

View File

@ -174,6 +174,7 @@ else
echo "Error: ${LOCAL_VENDOR_DIR}/autoload.php is missing. Install dependencies first (scripts/install_dependencies.sh)." >&2
exit 1
fi
php "${REPO_ROOT}/scripts/validate_composer_vendor.php" "${LOCAL_VENDOR_DIR}"
fi
ssh -p "${SSH_PORT}" \
@ -217,5 +218,11 @@ rsync "${VENDOR_RSYNC_ARGS[@]}" \
if [[ "${DRY_RUN}" -eq 1 ]]; then
echo "Dry-run complete. No remote files were changed."
else
ssh -p "${SSH_PORT}" \
-i "${SSH_KEY_PATH}" \
-o BatchMode=yes \
-o StrictHostKeyChecking=accept-new \
"${SSH_TARGET}" \
"test -f '${REMOTE_DIR}/vendor/autoload.php' && test -f '${REMOTE_DIR}/vendor/thecodingmachine/safe/lib/special_cases.php'"
echo "Deploy complete."
fi

View File

@ -94,6 +94,7 @@ if [[ ! -f "${REPO_ROOT}/vendor/autoload.php" ]]; then
echo "Error: vendor/autoload.php is missing after dependency install." >&2
exit 1
fi
php "${REPO_ROOT}/scripts/validate_composer_vendor.php" "${REPO_ROOT}/vendor"
rsync -a \
--delete \
@ -108,6 +109,7 @@ rsync -a \
mkdir -p "${STAGE_DIR}/vendor"
rsync -a --delete "${REPO_ROOT}/vendor/" "${STAGE_DIR}/vendor/"
php "${REPO_ROOT}/scripts/validate_composer_vendor.php" "${STAGE_DIR}/vendor"
ARCHIVE_PATH="${OUTPUT_DIR}/${PLUGIN_BASENAME}-${VERSION}.zip"
rm -f "${ARCHIVE_PATH}"

View File

@ -0,0 +1,39 @@
<?php
declare(strict_types=1);
$vendorDir = isset($argv[1]) ? rtrim((string) $argv[1], '/') : dirname(__DIR__) . '/vendor';
$autoload = $vendorDir . '/autoload.php';
$autoloadFiles = $vendorDir . '/composer/autoload_files.php';
if (!is_file($autoload)) {
fwrite(STDERR, "Missing Composer autoload: {$autoload}\n");
exit(1);
}
if (!is_file($autoloadFiles)) {
exit(0);
}
$files = require $autoloadFiles;
if (!is_array($files)) {
fwrite(STDERR, "Composer autoload files map did not return an array: {$autoloadFiles}\n");
exit(1);
}
$missing = [];
foreach ($files as $file) {
if (!is_string($file) || !is_file($file)) {
$missing[] = is_scalar($file) ? (string) $file : 'unknown';
}
}
if ($missing !== []) {
fwrite(STDERR, "Composer vendor is incomplete; missing files:\n");
foreach ($missing as $file) {
fwrite(STDERR, " - {$file}\n");
}
exit(1);
}
exit(0);