From dc4b32f847dd8d2493056361036082ec55231735 Mon Sep 17 00:00:00 2001 From: rfay Date: Sun, 27 Sep 2026 12:58:27 +0000 Subject: [PATCH] fix(drupal-core): guard against PHP-incompatible issue branches, fixes #217 An issue-fork branch can target a newer Drupal core than the workspace's drupal_version parameter (e.g. a "main"/12.x branch checked out into a drupal_version=11 workspace, which configures PHP 8.4). Composer then fails in generateMetapackages, poisons composer.local.lock, and all 3 retries fail identically in 1-2s each without surfacing the real cause. Read the checked-out branch's core/composer.json PHP requirement and compare it to the DDEV-configured PHP version before running composer, failing fast with a clear message instead of burning the retry loop. Co-Authored-By: Claude Sonnet 5 --- drupal-core/template.tf | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/drupal-core/template.tf b/drupal-core/template.tf index 7692a7f..ed2bb9c 100644 --- a/drupal-core/template.tf +++ b/drupal-core/template.tf @@ -797,6 +797,30 @@ WELCOME_STATIC chown coder:coder ~/WELCOME.txt 2>/dev/null || true # Step 4: Install ddev-drupal-dev add-on, composer install, and drush (first run only) + if [ "$DRUPAL_SETUP_NEEDED" = "true" ] && [ "$SETUP_FAILED" != "true" ]; then + # Guard: verify the checked-out branch's PHP requirement is satisfiable by the + # DDEV-configured PHP version before touching composer at all. An issue branch + # based on a newer Drupal core than the selected drupal_version (e.g. a "main" + # branch requiring PHP 8.5 checked out into a drupal_version=11 / PHP 8.4 + # workspace) fails composer's package-discovery step in a way that poisons + # composer.local.lock — all 3 retries below then fail identically in 1-2s each, + # hiding the real cause instead of surfacing it. See #217. + _core_php_min="" + if [ -f "core/composer.json" ]; then + _core_php_min=$(jq -r '.require.php // ""' core/composer.json 2>/dev/null | grep -oE '[0-9]+\.[0-9]+' | head -1) + fi + _configured_php=$(grep -E '^php_version:' .ddev/config.yaml 2>/dev/null | grep -oE '[0-9]+\.[0-9]+' | head -1) + if [ -n "$_core_php_min" ] && [ -n "$_configured_php" ] && \ + awk -v have="$_configured_php" -v need="$_core_php_min" 'BEGIN{exit !(have < need)}'; then + log_setup "✗ PHP version mismatch: checked-out branch ($${ISSUE_BRANCH:-$DRUPAL_BRANCH}) requires PHP >=$_core_php_min, but this workspace is configured for PHP $_configured_php ($DDEV_PROJECT_TYPE, from drupal_version=$DRUPAL_VERSION)" + log_setup " Recreate the workspace with a drupal_version matching this branch's actual Drupal core version, then retry." + update_status "✗ PHP compatibility check: Failed" + update_status " Branch requires PHP >=$_core_php_min, workspace has PHP $_configured_php (drupal_version=$DRUPAL_VERSION)" + update_status " Recreate the workspace with the drupal_version matching this branch." + SETUP_FAILED=true + fi + fi + if [ "$DRUPAL_SETUP_NEEDED" = "true" ] && [ "$SETUP_FAILED" != "true" ]; then log_setup "Installing amateescu/ddev-drupal-dev add-on..." update_status "⏳ DDEV add-on install: In progress..."