Restore composer.json after failed drush installation

Issue information

From user: jurgenhaas

Related to !274 (merged)

Contribution record

Fork management

Problem/Motivation

In this Slack thread we've discussed the details:

jurgenhaas
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.

Here is a sample pipeline for that: https://git.drupalcode.org/project/sqrl/-/pipelines/311538

fjgarlin

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

are you on the latest _GITLAB_TEMPLATES_REF ?

ignore the above. I was on the wrong composer validate

yeah, I see installing drush failed in the composer step.

I wonder if that kept the changes in composer.json but not composer.lock

jurgenhaas

That's what it looks like, yes.

fjgarlin

we are capturing the error in here

      # Install drush (if not present) but allow failures as it might not be compatible with all Drupal versions.
      composer require --dev --update-with-all-dependencies drush/drush || EXIT_CODE_DRUSH_REQUIRE=$?
      if [ "$EXIT_CODE_DRUSH_REQUIRE" != "" ]; then
        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"
      fi

so we could potentially revert the issue inside the if [ "$EXIT_CODE_DRUSH_REQUIRE" != "" ]; then

fjgarlin

do you mind creating an issue with the above info?

drush shouldn’t be a hard dependency, so if it fails we should just leave the files as before trying

Proposed resolution

Revert composer.json after failed drush installation so that it matches the composer.lock file.

Edited by drupalbot
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information