Restore composer.json after failed drush installation
>>> [!note] Migrated issue <!-- Drupal.org comment --> <!-- Migrated from issue #3481194. --> Reported by: [jurgenhaas](https://www.drupal.org/user/168924) Related to !274 >>> <h3 id="summary-problem-motivation">Problem/Motivation</h3> <p>In this <a href="https://drupal.slack.com/archives/CGKLP028K/p1729084880254679">Slack thread</a> we've discussed the details:</p> <pre>jurgenhaas<br>I have a follow-up question to https://www.drupal.org/node/3459196 where we added a new variable $_UPGRADE_STATUS_COMPOSER_EXTRA to the composer command for the upgrade status job. Now, I run into a similar issue in the .require-drush include task, where composer require is used but also without the optional composer extra arguments. Should we use $COMPOSER_EXTRA there just like in the major composer update command? Without adding those extras, drush can't be installed if we e.g. have to ignore a system extension dependency. But without drush being installed, the composer-lint task is failing for some strange resaon.<br><br>Here is a sample pipeline for that: https://git.drupalcode.org/project/sqrl/-/pipelines/311538<br><br>fjgarlin<br><br>I thought we were taking care of the composer.lock file here https://git.drupalcode.org/project/gitlab_templates/-/blob/main/includes/include.drupalci.main.yml?ref_type=heads#L489-498<br><br>are you on the latest _GITLAB_TEMPLATES_REF ?<br><br>ignore the above. I was on the wrong composer validate<br><br>yeah, I see installing drush failed in the composer step.<br><br>I wonder if that kept the changes in composer.json but not composer.lock<br><br>jurgenhaas<br><br>That's what it looks like, yes.<br><br>fjgarlin<br><br>we are capturing the error in here<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # Install drush (if not present) but allow failures as it might not be compatible with all Drupal versions.<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; composer require --dev --update-with-all-dependencies drush/drush || EXIT_CODE_DRUSH_REQUIRE=$?<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if [ "$EXIT_CODE_DRUSH_REQUIRE" != "" ]; then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf "$DIVIDER\nWARNING: Drush could NOT be installed. This is not a hard dependency for the default jobs, so this is just a warning.$DIVIDER\n"<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fi<br><br>so we could potentially revert the issue inside the if [ "$EXIT_CODE_DRUSH_REQUIRE" != "" ]; then<br><br>fjgarlin<br><br>do you mind creating an issue with the above info?<br><br>drush shouldn&rsquo;t be a hard dependency, so if it fails we should just leave the files as before trying</pre><h3 id="summary-proposed-resolution">Proposed resolution</h3> <p>Revert composer.json after failed drush installation so that it matches the composer.lock file.</p>
issue