From b5a1c01828e8321c5cc69a7169741d7164af40cc Mon Sep 17 00:00:00 2001
From: Jonathan Smith <jonathan1055@sandfordsolutions.com>
Date: Mon, 10 Feb 2025 17:36:10 +0000
Subject: [PATCH 01/11] Create variable PROJECT_FOLDER

---
 includes/include.drupalci.main-d7.yml | 4 ++++
 includes/include.drupalci.main.yml    | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/includes/include.drupalci.main-d7.yml b/includes/include.drupalci.main-d7.yml
index 2f611457..89ddea8b 100644
--- a/includes/include.drupalci.main-d7.yml
+++ b/includes/include.drupalci.main-d7.yml
@@ -69,6 +69,10 @@
     # Use -e so that \n is interpreted as a new line.
     echo -e "PHP_VERSION=$PHP_VERSION\nPHP_IMAGE_VARIANT=$PHP_IMAGE_VARIANT\nPHP_IMAGE_TAG=$PHP_IMAGE_TAG" >> build.env
 
+    # Create a variable to hold the path to the project's own folder.
+    export PROJECT_FOLDER=$CI_PROJECT_DIR/$_WEB_ROOT/sites/all/modules/custom/$CI_PROJECT_NAME
+    echo "PROJECT_FOLDER=$PROJECT_FOLDER" >> build.env
+
 # Display the Gitlab Templates version, the Composer version and some useful CI variables.
 .show-ci-variables: &show-ci-variables
   - echo "Executing curl -OL https://git.drupalcode.org/$_CURL_TEMPLATES_REPO/-/raw/$_CURL_TEMPLATES_REF/scripts/extract-version.php"
diff --git a/includes/include.drupalci.main.yml b/includes/include.drupalci.main.yml
index 1fb4f385..289972c6 100644
--- a/includes/include.drupalci.main.yml
+++ b/includes/include.drupalci.main.yml
@@ -98,6 +98,10 @@
     # Write PHP_IMAGE_VARIANT and PHP_IMAGE_TAG so that all subsequent variant jobs have the correct values automatically.
     echo -e "PHP_IMAGE_VARIANT=$PHP_IMAGE_VARIANT\nPHP_IMAGE_TAG=$PHP_IMAGE_TAG" >> build.env
 
+    # Create a variable to hold the path to the project's own folder.
+    export PROJECT_FOLDER=$CI_PROJECT_DIR/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME
+    echo "PROJECT_FOLDER=$PROJECT_FOLDER" >> build.env
+
 # Display the Gitlab Templates version, the Composer version and some useful CI variables.
 .show-ci-variables: &show-ci-variables
   - echo "Executing curl -OL https://git.drupalcode.org/$_CURL_TEMPLATES_REPO/-/raw/$_CURL_TEMPLATES_REF/scripts/extract-version.php"
-- 
GitLab


From b15951c99fcfbfa7cd2443b4673c21e4114ecf30 Mon Sep 17 00:00:00 2001
From: Jonathan Smith <jonathan1055@sandfordsolutions.com>
Date: Mon, 10 Feb 2025 17:46:34 +0000
Subject: [PATCH 02/11] Replace 11 usages in D10 template

---
 includes/include.drupalci.main.yml | 20 ++++++++++----------
 scripts/test-only.sh               |  2 +-
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/includes/include.drupalci.main.yml b/includes/include.drupalci.main.yml
index 289972c6..c7a7de44 100644
--- a/includes/include.drupalci.main.yml
+++ b/includes/include.drupalci.main.yml
@@ -201,7 +201,7 @@
 .amend-core-requirements-next-major: &amend-core-requirements-next-major
   - SAVED_PWD=$PWD;
   # Change directory to restrict finding info.yml to just those in the project.
-  - cd $CI_PROJECT_DIR/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME && pwd
+  - cd $PROJECT_FOLDER && pwd
   # Need the -L parameter to be able to detect the symlinked files.
   - INFO_FILES=$(find -L . -name "*.info.yml") || true
   # Return to top level to make the file changes.
@@ -598,9 +598,9 @@ composer-lint:
     - composer validate
     # Validate the module's composer.json.
     - |
-      if [ -f $CI_PROJECT_DIR/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME/composer.json ]; then
+      if [ -f $PROJECT_FOLDER/composer.json ]; then
         echo "Validating the composer.json file from the project."
-        cd $CI_PROJECT_DIR/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME && pwd
+        cd $PROJECT_FOLDER && pwd
         # Rename the lock file so it is not used in the validation command.
         test -f composer.lock && mv composer.lock composer.lock.backup
         composer validate
@@ -614,11 +614,11 @@ composer-lint:
     - PHP_FILES=$(find -L $_WEB_ROOT/modules/custom/$CI_PROJECT_NAME -type f | grep -E "\.($DRUPAL_PHP_FILE_TYPES_PIPE)$" | wc -l) || true
     - |
       if [[ "$PHP_FILES" > "0" ]]; then
-        echo "Found $PHP_FILES PHP files in $CI_PROJECT_DIR/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME"
+        echo "Found $PHP_FILES PHP files in $PROJECT_FOLDER"
         # parallel-lint has to be run here in $CI_PROJECT_DIR as it cannot follow symlinks.
         vendor/bin/parallel-lint -e $DRUPAL_PHP_FILE_TYPES --exclude $_WEB_ROOT --exclude vendor --exclude node_modules --no-progress $_PARALLEL_LINT_EXTRA .
       else
-        echo "There are no PHP files to validate in $CI_PROJECT_DIR/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME"
+        echo "There are no PHP files to validate in $PROJECT_FOLDER"
       fi
 
 phpcs:
@@ -672,7 +672,7 @@ phpcs:
     - composer
   script:
     # Run from within project directory so paths are correct.
-    - cd $CI_PROJECT_DIR/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME && pwd
+    - cd $PROJECT_FOLDER && pwd
     - *check-composer-end-code
     # If there is no PHPStan configuration neon file get the default from /assets/phpstan.neon
     - |
@@ -706,7 +706,7 @@ phpcs:
     - mv -v $_PHPSTAN_BASELINE_FILENAME $CI_PROJECT_DIR
     # Fix paths in message text in the reports.
     - cd $CI_PROJECT_DIR && pwd
-    - sed -i "s#$CI_PROJECT_DIR/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME/##g" junit.xml $_PHPSTAN_BASELINE_FILENAME phpstan-quality-report.json
+    - sed -i "s#$PROJECT_FOLDER/##g" junit.xml $_PHPSTAN_BASELINE_FILENAME phpstan-quality-report.json
     - exit $EXIT_CODE
   allow_failure: true
   artifacts:
@@ -823,7 +823,7 @@ stylelint:
   script:
     - cd $CI_PROJECT_DIR/$_WEB_ROOT/core && corepack enable && yarn add @gitlab-formatters/stylelint-formatter-gitlab
     # Change directory to the project root folder.
-    - cd $CI_PROJECT_DIR/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME && pwd
+    - cd $PROJECT_FOLDER && pwd
     - echo "Stylelint version $(${CI_PROJECT_DIR}/${_WEB_ROOT}/core/node_modules/.bin/stylelint --version)"
     # If there is no .stylelintignore file, there is no warning or error. The
     # option is just ignored.
@@ -858,7 +858,7 @@ eslint:
     - composer
   script:
     # Change directory to the project root folder
-    - cd $CI_PROJECT_DIR/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME && pwd
+    - cd $PROJECT_FOLDER && pwd
     # Configure ESLint with core defaults. We use core/.eslintrc.passing.json which includes core/.eslintrc.json and .eslintrc.jquery.json.
     # These links are created in the folder above modules/custom/$CI_PROJECT_NAME and will be used in addition to the project's own .eslintrc.json.
     - ln -s $CI_PROJECT_DIR/$_WEB_ROOT/core/.eslintrc.passing.json $CI_PROJECT_DIR/$_WEB_ROOT/modules/custom/.eslintrc.json
@@ -940,7 +940,7 @@ cspell:
     - echo "Executing curl -OL https://git.drupalcode.org/$_CURL_TEMPLATES_REPO/-/raw/$_CURL_TEMPLATES_REF/scripts/prepare-cspell.php"
     - curl -OL https://git.drupalcode.org/$_CURL_TEMPLATES_REPO/-/raw/$_CURL_TEMPLATES_REF/scripts/prepare-cspell.php
     # Restore composer.json back to an unchanged version.
-    - test -f $CI_PROJECT_DIR/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME/composer.json && cp $CI_PROJECT_DIR/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME/composer.json composer.json
+    - test -f $PROJECT_FOLDER/composer.json && cp $PROJECT_FOLDER/composer.json composer.json
     - |
       if [ ! -f .cspell.json ]; then
         echo "Getting default .cspell.json from https://git.drupalcode.org/$_CURL_TEMPLATES_REPO/-/raw/$_CURL_TEMPLATES_REF/assets/.cspell.json"
diff --git a/scripts/test-only.sh b/scripts/test-only.sh
index c2ca7d69..fd94cfc1 100755
--- a/scripts/test-only.sh
+++ b/scripts/test-only.sh
@@ -44,7 +44,7 @@ TESTS_CHANGED=$(git diff ${BASELINE} --name-only | grep -E 'Test\.php$') || true
 if [ "$TESTS_CHANGED" != "" ]; then
   printf " \n2️⃣ Running tests changed in this merge request\n \nThe following test files have been changed, and only these tests will be run:\n$TESTS_CHANGED\n "
   for file in $TESTS_CHANGED; do
-    test=$CI_PROJECT_DIR/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME/$file
+    test=$PROJECT_FOLDER/$file
     if [ "$_PHPUNIT_CONCURRENT" == "0" ]; then
       printf "$DIVIDER\n_PHPUNIT_CONCURRENT=$_PHPUNIT_CONCURRENT, _PHPUNIT_EXTRA=$_PHPUNIT_EXTRA, PHPUNIT_OPTIONS=$PHPUNIT_OPTIONS\n "
       printf "executing: sudo -u www-data -H -E vendor/bin/phpunit $PHPUNIT_OPTIONS --bootstrap $PWD/$_WEB_ROOT/core/tests/bootstrap.php $test --log-junit $CI_PROJECT_DIR/junit.xml $_PHPUNIT_EXTRA\n "
-- 
GitLab


From 4a99c7665c7488dab3cbb6f2bead437521144e80 Mon Sep 17 00:00:00 2001
From: Jonathan Smith <jonathan1055@sandfordsolutions.com>
Date: Mon, 10 Feb 2025 17:57:11 +0000
Subject: [PATCH 03/11] Replace 6 usages in d7 template

---
 includes/include.drupalci.main-d7.yml | 10 +++++-----
 scripts/test-only-d7.sh               |  2 +-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/includes/include.drupalci.main-d7.yml b/includes/include.drupalci.main-d7.yml
index 89ddea8b..2a689009 100644
--- a/includes/include.drupalci.main-d7.yml
+++ b/includes/include.drupalci.main-d7.yml
@@ -145,9 +145,9 @@
     if [ "$_D7_DRUPAL_TEST_DEPENDENCIES" != "" ]; then
       printf "\n\n*** Installing test_dependencies: $_D7_DRUPAL_TEST_DEPENDENCIES"
       vendor/bin/drush --root=$_WEB_ROOT pm:download -y $_D7_DRUPAL_TEST_DEPENDENCIES
-    elif [ ! -f $_WEB_ROOT/sites/all/modules/custom/$CI_PROJECT_NAME/composer.json ]; then
+    elif [ ! -f $PROJECT_FOLDER/composer.json ]; then
       printf "\n\n*** Trying to install test_dependencies from $PROJECT_NAME.info automatically. If this fails you can populate the variable _D7_DRUPAL_TEST_DEPENDENCIES in your .gitlab-ci.yml file, or create a composer.json and define the test dependencies with require-dev.\n\n"
-      cat $_WEB_ROOT/sites/all/modules/custom/$CI_PROJECT_NAME/$PROJECT_NAME.info | sed -n '/^test_dependencies\[\].*=/p' | sed -r 's/^test_dependencies\[\].?=//' | sed 's/([^)]*)//' | while read -r line; do
+      cat $PROJECT_FOLDER/$PROJECT_NAME.info | sed -n '/^test_dependencies\[\].*=/p' | sed -r 's/^test_dependencies\[\].?=//' | sed 's/([^)]*)//' | while read -r line; do
         IFS=':' read -r -a array <<< "$line"
         echo "- drush dl ${array[0]}"
         vendor/bin/drush --root=$_WEB_ROOT pm:download -y ${array[0]}
@@ -365,9 +365,9 @@ stages:
     # Delete the current composer.json, and then restore from backup if one was made earlier.
     - |
       if [[ -f composer.json.backup ]]; then
-        rm $_WEB_ROOT/sites/all/modules/custom/$CI_PROJECT_NAME/composer.json
-        echo "Restoring composer.json.backup to $_WEB_ROOT/sites/all/modules/custom/$CI_PROJECT_NAME/composer.json"
-        mv composer.json.backup $_WEB_ROOT/sites/all/modules/custom/$CI_PROJECT_NAME/composer.json
+        rm $PROJECT_FOLDER/composer.json
+        echo "Restoring composer.json.backup to $PROJECT_FOLDER/composer.json"
+        mv composer.json.backup $PROJECT_FOLDER/composer.json
       fi
     # Give confirmation of the directories in vendor/drupal and sites/all/modules.
     - ls $CI_PROJECT_DIR/vendor/drupal
diff --git a/scripts/test-only-d7.sh b/scripts/test-only-d7.sh
index 07cf7133..446abbba 100755
--- a/scripts/test-only-d7.sh
+++ b/scripts/test-only-d7.sh
@@ -38,7 +38,7 @@ TESTS_CHANGED=$(git diff ${BASELINE} --name-only | grep -E '\.test$') || true
 if [ "$TESTS_CHANGED" != "" ]; then
   printf " \n2️⃣ Running tests changed in this merge request\n \nThe following test files have been changed, and only these tests will be run:\n$TESTS_CHANGED\n "
   for file in $TESTS_CHANGED; do
-    test=sites/all/modules/custom/$CI_PROJECT_NAME/$file
+    test=$PROJECT_FOLDER/$file
     printf "$DIVIDER\nexecuting: sudo SYMFONY_DEPRECATIONS_HELPER='$SYMFONY_DEPRECATIONS_HELPER' MINK_DRIVER_ARGS_WEBDRIVER='$MINK_DRIVER_ARGS_WEBDRIVER' -u www-data php $_WEB_ROOT/scripts/run-tests.sh --color --concurrency '32' --url $SIMPLETEST_BASE_URL --verbose --fail-only --xml $BROWSERTEST_OUTPUT_DIRECTORY --file $test $_PHPUNIT_EXTRA\n "
     sudo SYMFONY_DEPRECATIONS_HELPER="$SYMFONY_DEPRECATIONS_HELPER" MINK_DRIVER_ARGS_WEBDRIVER="$MINK_DRIVER_ARGS_WEBDRIVER" -u www-data php $_WEB_ROOT/scripts/run-tests.sh --color --concurrency "32" --url $SIMPLETEST_BASE_URL --verbose --fail-only --xml $BROWSERTEST_OUTPUT_DIRECTORY --file $test $_PHPUNIT_EXTRA || EXIT_CODE=$?
   done;
-- 
GitLab


From 4dcb8ce3409528959e3baa1fe9b746dbe6d99c5c Mon Sep 17 00:00:00 2001
From: Jonathan Smith <jonathan1055@sandfordsolutions.com>
Date: Tue, 11 Feb 2025 10:08:50 +0000
Subject: [PATCH 04/11] Rename PROJECT_FOLDER to DRUPAL_PROJECT_FOLDER

---
 includes/include.drupalci.main-d7.yml | 14 +++++++-------
 includes/include.drupalci.main.yml    | 24 ++++++++++++------------
 scripts/test-only-d7.sh               |  2 +-
 scripts/test-only.sh                  |  2 +-
 4 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/includes/include.drupalci.main-d7.yml b/includes/include.drupalci.main-d7.yml
index 2a689009..85de70de 100644
--- a/includes/include.drupalci.main-d7.yml
+++ b/includes/include.drupalci.main-d7.yml
@@ -70,8 +70,8 @@
     echo -e "PHP_VERSION=$PHP_VERSION\nPHP_IMAGE_VARIANT=$PHP_IMAGE_VARIANT\nPHP_IMAGE_TAG=$PHP_IMAGE_TAG" >> build.env
 
     # Create a variable to hold the path to the project's own folder.
-    export PROJECT_FOLDER=$CI_PROJECT_DIR/$_WEB_ROOT/sites/all/modules/custom/$CI_PROJECT_NAME
-    echo "PROJECT_FOLDER=$PROJECT_FOLDER" >> build.env
+    export DRUPAL_PROJECT_FOLDER=$CI_PROJECT_DIR/$_WEB_ROOT/sites/all/modules/custom/$CI_PROJECT_NAME
+    echo "DRUPAL_PROJECT_FOLDER=$DRUPAL_PROJECT_FOLDER" >> build.env
 
 # Display the Gitlab Templates version, the Composer version and some useful CI variables.
 .show-ci-variables: &show-ci-variables
@@ -145,9 +145,9 @@
     if [ "$_D7_DRUPAL_TEST_DEPENDENCIES" != "" ]; then
       printf "\n\n*** Installing test_dependencies: $_D7_DRUPAL_TEST_DEPENDENCIES"
       vendor/bin/drush --root=$_WEB_ROOT pm:download -y $_D7_DRUPAL_TEST_DEPENDENCIES
-    elif [ ! -f $PROJECT_FOLDER/composer.json ]; then
+    elif [ ! -f $DRUPAL_PROJECT_FOLDER/composer.json ]; then
       printf "\n\n*** Trying to install test_dependencies from $PROJECT_NAME.info automatically. If this fails you can populate the variable _D7_DRUPAL_TEST_DEPENDENCIES in your .gitlab-ci.yml file, or create a composer.json and define the test dependencies with require-dev.\n\n"
-      cat $PROJECT_FOLDER/$PROJECT_NAME.info | sed -n '/^test_dependencies\[\].*=/p' | sed -r 's/^test_dependencies\[\].?=//' | sed 's/([^)]*)//' | while read -r line; do
+      cat $DRUPAL_PROJECT_FOLDER/$PROJECT_NAME.info | sed -n '/^test_dependencies\[\].*=/p' | sed -r 's/^test_dependencies\[\].?=//' | sed 's/([^)]*)//' | while read -r line; do
         IFS=':' read -r -a array <<< "$line"
         echo "- drush dl ${array[0]}"
         vendor/bin/drush --root=$_WEB_ROOT pm:download -y ${array[0]}
@@ -365,9 +365,9 @@ stages:
     # Delete the current composer.json, and then restore from backup if one was made earlier.
     - |
       if [[ -f composer.json.backup ]]; then
-        rm $PROJECT_FOLDER/composer.json
-        echo "Restoring composer.json.backup to $PROJECT_FOLDER/composer.json"
-        mv composer.json.backup $PROJECT_FOLDER/composer.json
+        rm $DRUPAL_PROJECT_FOLDER/composer.json
+        echo "Restoring composer.json.backup to $DRUPAL_PROJECT_FOLDER/composer.json"
+        mv composer.json.backup $DRUPAL_PROJECT_FOLDER/composer.json
       fi
     # Give confirmation of the directories in vendor/drupal and sites/all/modules.
     - ls $CI_PROJECT_DIR/vendor/drupal
diff --git a/includes/include.drupalci.main.yml b/includes/include.drupalci.main.yml
index c7a7de44..b9219128 100644
--- a/includes/include.drupalci.main.yml
+++ b/includes/include.drupalci.main.yml
@@ -99,8 +99,8 @@
     echo -e "PHP_IMAGE_VARIANT=$PHP_IMAGE_VARIANT\nPHP_IMAGE_TAG=$PHP_IMAGE_TAG" >> build.env
 
     # Create a variable to hold the path to the project's own folder.
-    export PROJECT_FOLDER=$CI_PROJECT_DIR/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME
-    echo "PROJECT_FOLDER=$PROJECT_FOLDER" >> build.env
+    export DRUPAL_PROJECT_FOLDER=$CI_PROJECT_DIR/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME
+    echo "DRUPAL_PROJECT_FOLDER=$DRUPAL_PROJECT_FOLDER" >> build.env
 
 # Display the Gitlab Templates version, the Composer version and some useful CI variables.
 .show-ci-variables: &show-ci-variables
@@ -201,7 +201,7 @@
 .amend-core-requirements-next-major: &amend-core-requirements-next-major
   - SAVED_PWD=$PWD;
   # Change directory to restrict finding info.yml to just those in the project.
-  - cd $PROJECT_FOLDER && pwd
+  - cd $DRUPAL_PROJECT_FOLDER && pwd
   # Need the -L parameter to be able to detect the symlinked files.
   - INFO_FILES=$(find -L . -name "*.info.yml") || true
   # Return to top level to make the file changes.
@@ -598,9 +598,9 @@ composer-lint:
     - composer validate
     # Validate the module's composer.json.
     - |
-      if [ -f $PROJECT_FOLDER/composer.json ]; then
+      if [ -f $DRUPAL_PROJECT_FOLDER/composer.json ]; then
         echo "Validating the composer.json file from the project."
-        cd $PROJECT_FOLDER && pwd
+        cd $DRUPAL_PROJECT_FOLDER && pwd
         # Rename the lock file so it is not used in the validation command.
         test -f composer.lock && mv composer.lock composer.lock.backup
         composer validate
@@ -614,11 +614,11 @@ composer-lint:
     - PHP_FILES=$(find -L $_WEB_ROOT/modules/custom/$CI_PROJECT_NAME -type f | grep -E "\.($DRUPAL_PHP_FILE_TYPES_PIPE)$" | wc -l) || true
     - |
       if [[ "$PHP_FILES" > "0" ]]; then
-        echo "Found $PHP_FILES PHP files in $PROJECT_FOLDER"
+        echo "Found $PHP_FILES PHP files in $DRUPAL_PROJECT_FOLDER"
         # parallel-lint has to be run here in $CI_PROJECT_DIR as it cannot follow symlinks.
         vendor/bin/parallel-lint -e $DRUPAL_PHP_FILE_TYPES --exclude $_WEB_ROOT --exclude vendor --exclude node_modules --no-progress $_PARALLEL_LINT_EXTRA .
       else
-        echo "There are no PHP files to validate in $PROJECT_FOLDER"
+        echo "There are no PHP files to validate in $DRUPAL_PROJECT_FOLDER"
       fi
 
 phpcs:
@@ -672,7 +672,7 @@ phpcs:
     - composer
   script:
     # Run from within project directory so paths are correct.
-    - cd $PROJECT_FOLDER && pwd
+    - cd $DRUPAL_PROJECT_FOLDER && pwd
     - *check-composer-end-code
     # If there is no PHPStan configuration neon file get the default from /assets/phpstan.neon
     - |
@@ -706,7 +706,7 @@ phpcs:
     - mv -v $_PHPSTAN_BASELINE_FILENAME $CI_PROJECT_DIR
     # Fix paths in message text in the reports.
     - cd $CI_PROJECT_DIR && pwd
-    - sed -i "s#$PROJECT_FOLDER/##g" junit.xml $_PHPSTAN_BASELINE_FILENAME phpstan-quality-report.json
+    - sed -i "s#$DRUPAL_PROJECT_FOLDER/##g" junit.xml $_PHPSTAN_BASELINE_FILENAME phpstan-quality-report.json
     - exit $EXIT_CODE
   allow_failure: true
   artifacts:
@@ -823,7 +823,7 @@ stylelint:
   script:
     - cd $CI_PROJECT_DIR/$_WEB_ROOT/core && corepack enable && yarn add @gitlab-formatters/stylelint-formatter-gitlab
     # Change directory to the project root folder.
-    - cd $PROJECT_FOLDER && pwd
+    - cd $DRUPAL_PROJECT_FOLDER && pwd
     - echo "Stylelint version $(${CI_PROJECT_DIR}/${_WEB_ROOT}/core/node_modules/.bin/stylelint --version)"
     # If there is no .stylelintignore file, there is no warning or error. The
     # option is just ignored.
@@ -858,7 +858,7 @@ eslint:
     - composer
   script:
     # Change directory to the project root folder
-    - cd $PROJECT_FOLDER && pwd
+    - cd $DRUPAL_PROJECT_FOLDER && pwd
     # Configure ESLint with core defaults. We use core/.eslintrc.passing.json which includes core/.eslintrc.json and .eslintrc.jquery.json.
     # These links are created in the folder above modules/custom/$CI_PROJECT_NAME and will be used in addition to the project's own .eslintrc.json.
     - ln -s $CI_PROJECT_DIR/$_WEB_ROOT/core/.eslintrc.passing.json $CI_PROJECT_DIR/$_WEB_ROOT/modules/custom/.eslintrc.json
@@ -940,7 +940,7 @@ cspell:
     - echo "Executing curl -OL https://git.drupalcode.org/$_CURL_TEMPLATES_REPO/-/raw/$_CURL_TEMPLATES_REF/scripts/prepare-cspell.php"
     - curl -OL https://git.drupalcode.org/$_CURL_TEMPLATES_REPO/-/raw/$_CURL_TEMPLATES_REF/scripts/prepare-cspell.php
     # Restore composer.json back to an unchanged version.
-    - test -f $PROJECT_FOLDER/composer.json && cp $PROJECT_FOLDER/composer.json composer.json
+    - test -f $DRUPAL_PROJECT_FOLDER/composer.json && cp $DRUPAL_PROJECT_FOLDER/composer.json composer.json
     - |
       if [ ! -f .cspell.json ]; then
         echo "Getting default .cspell.json from https://git.drupalcode.org/$_CURL_TEMPLATES_REPO/-/raw/$_CURL_TEMPLATES_REF/assets/.cspell.json"
diff --git a/scripts/test-only-d7.sh b/scripts/test-only-d7.sh
index 446abbba..d79d37dd 100755
--- a/scripts/test-only-d7.sh
+++ b/scripts/test-only-d7.sh
@@ -38,7 +38,7 @@ TESTS_CHANGED=$(git diff ${BASELINE} --name-only | grep -E '\.test$') || true
 if [ "$TESTS_CHANGED" != "" ]; then
   printf " \n2️⃣ Running tests changed in this merge request\n \nThe following test files have been changed, and only these tests will be run:\n$TESTS_CHANGED\n "
   for file in $TESTS_CHANGED; do
-    test=$PROJECT_FOLDER/$file
+    test=$DRUPAL_PROJECT_FOLDER/$file
     printf "$DIVIDER\nexecuting: sudo SYMFONY_DEPRECATIONS_HELPER='$SYMFONY_DEPRECATIONS_HELPER' MINK_DRIVER_ARGS_WEBDRIVER='$MINK_DRIVER_ARGS_WEBDRIVER' -u www-data php $_WEB_ROOT/scripts/run-tests.sh --color --concurrency '32' --url $SIMPLETEST_BASE_URL --verbose --fail-only --xml $BROWSERTEST_OUTPUT_DIRECTORY --file $test $_PHPUNIT_EXTRA\n "
     sudo SYMFONY_DEPRECATIONS_HELPER="$SYMFONY_DEPRECATIONS_HELPER" MINK_DRIVER_ARGS_WEBDRIVER="$MINK_DRIVER_ARGS_WEBDRIVER" -u www-data php $_WEB_ROOT/scripts/run-tests.sh --color --concurrency "32" --url $SIMPLETEST_BASE_URL --verbose --fail-only --xml $BROWSERTEST_OUTPUT_DIRECTORY --file $test $_PHPUNIT_EXTRA || EXIT_CODE=$?
   done;
diff --git a/scripts/test-only.sh b/scripts/test-only.sh
index fd94cfc1..eb1606a2 100755
--- a/scripts/test-only.sh
+++ b/scripts/test-only.sh
@@ -44,7 +44,7 @@ TESTS_CHANGED=$(git diff ${BASELINE} --name-only | grep -E 'Test\.php$') || true
 if [ "$TESTS_CHANGED" != "" ]; then
   printf " \n2️⃣ Running tests changed in this merge request\n \nThe following test files have been changed, and only these tests will be run:\n$TESTS_CHANGED\n "
   for file in $TESTS_CHANGED; do
-    test=$PROJECT_FOLDER/$file
+    test=$DRUPAL_PROJECT_FOLDER/$file
     if [ "$_PHPUNIT_CONCURRENT" == "0" ]; then
       printf "$DIVIDER\n_PHPUNIT_CONCURRENT=$_PHPUNIT_CONCURRENT, _PHPUNIT_EXTRA=$_PHPUNIT_EXTRA, PHPUNIT_OPTIONS=$PHPUNIT_OPTIONS\n "
       printf "executing: sudo -u www-data -H -E vendor/bin/phpunit $PHPUNIT_OPTIONS --bootstrap $PWD/$_WEB_ROOT/core/tests/bootstrap.php $test --log-junit $CI_PROJECT_DIR/junit.xml $_PHPUNIT_EXTRA\n "
-- 
GitLab


From 5536dcd47792c3135e37c932b2881084319ce047 Mon Sep 17 00:00:00 2001
From: Jonathan Smith <20701-jonathan1055@users.noreply.drupalcode.org>
Date: Tue, 11 Feb 2025 10:39:44 +0000
Subject: [PATCH 05/11] Document before_script and after_script examples

---
 docs/info/customizations.md | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/docs/info/customizations.md b/docs/info/customizations.md
index 2f61de7e..4640f804 100644
--- a/docs/info/customizations.md
+++ b/docs/info/customizations.md
@@ -45,6 +45,19 @@ phpstan:
   allow_failure: false
 ```
 
+## Custom before_script and after_script
+
+If your project needs to do extra processing in preparation before a job, or to do some custom work with results after a job, you can use the `before_script` and `after_script` job keywords. Every job can accept these customizations and they are specifically not used by Gitlab Templates, making them available for Contrib use. The variable `$DRUPAL_PROJECT_FOLDER` contains the absolute path to the contrib project within the Drupal site installation.
+```
+phpcs:
+  before_script:
+    - rm $DRUPAL_PROJECT_FOLDER/some-file.xml
+
+phpstan:
+  after_script:
+    - php $DRUPAL_PROJECT_FOLDER/scripts/phpstan-baseline-summary.php
+```
+
 ## References
 
 If the part of the template that you are overriding uses in-template references, you don't need to replicate them in your overrides, you can just use the [!reference notation](https://docs.gitlab.com/ee/ci/yaml/yaml_optimization.html#reference-tags).
-- 
GitLab


From e4c36c593b10983f578812d0f4558c1d2413ff04 Mon Sep 17 00:00:00 2001
From: Jonathan Smith <20701-jonathan1055@users.noreply.drupalcode.org>
Date: Tue, 11 Feb 2025 11:12:47 +0000
Subject: [PATCH 06/11] Apply 3 suggestions about examples

---
 docs/info/customizations.md | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/docs/info/customizations.md b/docs/info/customizations.md
index 4640f804..f022a8b2 100644
--- a/docs/info/customizations.md
+++ b/docs/info/customizations.md
@@ -48,11 +48,15 @@ phpstan:
 ## Custom before_script and after_script
 
 If your project needs to do extra processing in preparation before a job, or to do some custom work with results after a job, you can use the `before_script` and `after_script` job keywords. Every job can accept these customizations and they are specifically not used by Gitlab Templates, making them available for Contrib use. The variable `$DRUPAL_PROJECT_FOLDER` contains the absolute path to the contrib project within the Drupal site installation.
+
+Examples:
 ```
+# Remove files that you don't want to be checked.
 phpcs:
   before_script:
     - rm $DRUPAL_PROJECT_FOLDER/some-file.xml
 
+# Run a custom script after the job finishes.
 phpstan:
   after_script:
     - php $DRUPAL_PROJECT_FOLDER/scripts/phpstan-baseline-summary.php
-- 
GitLab


From 76d0e1e9d55911544b4f01647c92af05ec1b3d00 Mon Sep 17 00:00:00 2001
From: Jonathan Smith <20701-jonathan1055@users.noreply.drupalcode.org>
Date: Tue, 11 Feb 2025 11:13:55 +0000
Subject: [PATCH 07/11] .xml would not be checked by phpcs, so use .inc

---
 docs/info/customizations.md | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/docs/info/customizations.md b/docs/info/customizations.md
index f022a8b2..d0c22759 100644
--- a/docs/info/customizations.md
+++ b/docs/info/customizations.md
@@ -54,7 +54,7 @@ Examples:
 # Remove files that you don't want to be checked.
 phpcs:
   before_script:
-    - rm $DRUPAL_PROJECT_FOLDER/some-file.xml
+    - rm $DRUPAL_PROJECT_FOLDER/some-file.inc
 
 # Run a custom script after the job finishes.
 phpstan:
-- 
GitLab


From 31d566116686ab26f26fe9721de629aaf0f013be Mon Sep 17 00:00:00 2001
From: Jonathan Smith <jonathan1055@sandfordsolutions.com>
Date: Tue, 11 Feb 2025 12:00:40 +0000
Subject: [PATCH 08/11] use DRUPAL_PROJECT_FOLDER in composer-base,
 composer-lint find and phpunit binary concurrent=0

---
 includes/include.drupalci.main.yml | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/includes/include.drupalci.main.yml b/includes/include.drupalci.main.yml
index b9219128..eafc806d 100644
--- a/includes/include.drupalci.main.yml
+++ b/includes/include.drupalci.main.yml
@@ -480,9 +480,9 @@ stages:
     # Delete the current composer.json, and then restore from backup if one was made earlier.
     - |
       if [[ -f composer.json.backup ]]; then
-        rm $_WEB_ROOT/modules/custom/$CI_PROJECT_NAME/composer.json
-        echo "Restoring composer.json.backup to $_WEB_ROOT/modules/custom/$CI_PROJECT_NAME/composer.json"
-        mv composer.json.backup $_WEB_ROOT/modules/custom/$CI_PROJECT_NAME/composer.json
+        rm $DRUPAL_PROJECT_FOLDER/composer.json
+        echo "Restoring composer.json.backup to $DRUPAL_PROJECT_FOLDER/composer.json"
+        mv composer.json.backup $DRUPAL_PROJECT_FOLDER/composer.json
       fi
     # For Nightwatch et al.
     - cd $_WEB_ROOT/core && corepack enable && yarn install && cd $CI_PROJECT_DIR
@@ -611,7 +611,7 @@ composer-lint:
     - DRUPAL_PHP_FILE_TYPES_PIPE=`echo "$DRUPAL_PHP_FILE_TYPES" | tr ',' '|'`
     - echo "DRUPAL_PHP_FILE_TYPES_PIPE=$DRUPAL_PHP_FILE_TYPES_PIPE"
     # Find all PHP files in the actual project folder. -L is needed to follow the symlinks. Need || true to cater for when there are no files.
-    - PHP_FILES=$(find -L $_WEB_ROOT/modules/custom/$CI_PROJECT_NAME -type f | grep -E "\.($DRUPAL_PHP_FILE_TYPES_PIPE)$" | wc -l) || true
+    - PHP_FILES=$(find -L $DRUPAL_PROJECT_FOLDER -type f | grep -E "\.($DRUPAL_PHP_FILE_TYPES_PIPE)$" | wc -l) || true
     - |
       if [[ "$PHP_FILES" > "0" ]]; then
         echo "Found $PHP_FILES PHP files in $DRUPAL_PROJECT_FOLDER"
@@ -1171,8 +1171,8 @@ nightwatch (next major):
           printf "$DIVIDER\n"
         fi
         printf "_PHPUNIT_CONCURRENT=$_PHPUNIT_CONCURRENT, _PHPUNIT_TESTGROUPS=$_PHPUNIT_TESTGROUPS, _PHPUNIT_EXTRA=$_PHPUNIT_EXTRA\nPHPUNIT_OPTIONS=$PHPUNIT_OPTIONS, WHAT_TO_RUN=$WHAT_TO_RUN\n"
-        echo "executing: sudo -u www-data -H -E vendor/bin/phpunit $PHPUNIT_OPTIONS --bootstrap $PWD/$_WEB_ROOT/core/tests/bootstrap.php $PWD/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME --log-junit $CI_PROJECT_DIR/junit.xml $WHAT_TO_RUN $_PHPUNIT_EXTRA"
-        sudo -u www-data -H -E vendor/bin/phpunit $PHPUNIT_OPTIONS --bootstrap $PWD/$_WEB_ROOT/core/tests/bootstrap.php $PWD/$_WEB_ROOT/modules/custom/$CI_PROJECT_NAME --log-junit $CI_PROJECT_DIR/junit.xml $WHAT_TO_RUN $_PHPUNIT_EXTRA || EXIT_CODE=$?
+        echo "executing: sudo -u www-data -H -E vendor/bin/phpunit $PHPUNIT_OPTIONS --bootstrap $PWD/$_WEB_ROOT/core/tests/bootstrap.php $DRUPAL_PROJECT_FOLDER --log-junit $CI_PROJECT_DIR/junit.xml $WHAT_TO_RUN $_PHPUNIT_EXTRA"
+        sudo -u www-data -H -E vendor/bin/phpunit $PHPUNIT_OPTIONS --bootstrap $PWD/$_WEB_ROOT/core/tests/bootstrap.php $DRUPAL_PROJECT_FOLDER --log-junit $CI_PROJECT_DIR/junit.xml $WHAT_TO_RUN $_PHPUNIT_EXTRA || EXIT_CODE=$?
       elif [ "$_PHPUNIT_CONCURRENT" == "1" ]; then
         # if _PHPUNIT_TESTGROUPS is blank then do not add anything, because the test group will be handled by the matrix.
         # if _PHPUNIT_TESTGROUPS is --all then add --directory modules/custom/$CI_PROJECT_NAME
-- 
GitLab


From 651208ba86a48850cb7e113d95b199c36848a5eb Mon Sep 17 00:00:00 2001
From: Jonathan Smith <jonathan1055@sandfordsolutions.com>
Date: Tue, 11 Feb 2025 17:34:53 +0000
Subject: [PATCH 09/11] Fix double $$ in test-only changes

---
 includes/include.drupalci.main.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/includes/include.drupalci.main.yml b/includes/include.drupalci.main.yml
index eafc806d..f1a65e75 100644
--- a/includes/include.drupalci.main.yml
+++ b/includes/include.drupalci.main.yml
@@ -1284,7 +1284,7 @@ test-only changes:
   interruptible: true
   allow_failure: true
   script:
-    - cd $$CI_PROJECT_DIR && pwd
+    - cd $CI_PROJECT_DIR && pwd
     - *check-composer-end-code
     - *show-environment-variables
     - *setup-webserver
-- 
GitLab


From 5ae22d35182253b65f8d2d9edc4f7828272bed20 Mon Sep 17 00:00:00 2001
From: Jonathan Smith <jonathan1055@sandfordsolutions.com>
Date: Wed, 12 Feb 2025 14:20:39 +0000
Subject: [PATCH 10/11] Add -v to some copy and move

---
 includes/include.drupalci.main-d7.yml |  4 ++--
 includes/include.drupalci.main.yml    | 14 +++++++-------
 2 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/includes/include.drupalci.main-d7.yml b/includes/include.drupalci.main-d7.yml
index 85de70de..7049f3ba 100644
--- a/includes/include.drupalci.main-d7.yml
+++ b/includes/include.drupalci.main-d7.yml
@@ -324,7 +324,7 @@ stages:
     - export PROJECT_FILES=$(ls -A)
     # Extract Core into default directory then rename to $_WEB_ROOT
     - curl https://ftp.drupal.org/files/projects/drupal-$_TARGET_D7_CORE.tar.gz | tar -xz
-    - mv drupal-$_TARGET_D7_CORE $CI_PROJECT_DIR/$_WEB_ROOT
+    - mv -v drupal-$_TARGET_D7_CORE $CI_PROJECT_DIR/$_WEB_ROOT
     # If composer.json exists then make a backup before it gets modified. Otherwise create an empty file.
     - |
       if [[ -f composer.json ]]; then
@@ -367,7 +367,7 @@ stages:
       if [[ -f composer.json.backup ]]; then
         rm $DRUPAL_PROJECT_FOLDER/composer.json
         echo "Restoring composer.json.backup to $DRUPAL_PROJECT_FOLDER/composer.json"
-        mv composer.json.backup $DRUPAL_PROJECT_FOLDER/composer.json
+        mv -v composer.json.backup $DRUPAL_PROJECT_FOLDER/composer.json
       fi
     # Give confirmation of the directories in vendor/drupal and sites/all/modules.
     - ls $CI_PROJECT_DIR/vendor/drupal
diff --git a/includes/include.drupalci.main.yml b/includes/include.drupalci.main.yml
index f1a65e75..b3172401 100644
--- a/includes/include.drupalci.main.yml
+++ b/includes/include.drupalci.main.yml
@@ -461,9 +461,9 @@ stages:
     # If composer.json exists then make a backup before it gets modified. Otherwise create an empty file.
     - |
       if [[ -f composer.json ]]; then
-        cp composer.json composer.json.backup
+        cp -v composer.json composer.json.backup
       else
-        echo "{}" > composer.json
+        echo "{}" > composer.json && echo "Project has no composer.json so creating an empty one"
       fi
     - php expand_composer_json.php || EXPAND_COMPOSER_EXIT_CODE=$?
     - if [[ "$EXPAND_COMPOSER_EXIT_CODE" != "" ]]; then echo "EXPAND_COMPOSER_EXIT_CODE=$EXPAND_COMPOSER_EXIT_CODE"; exit $EXPAND_COMPOSER_EXIT_CODE; fi
@@ -480,9 +480,9 @@ stages:
     # Delete the current composer.json, and then restore from backup if one was made earlier.
     - |
       if [[ -f composer.json.backup ]]; then
-        rm $DRUPAL_PROJECT_FOLDER/composer.json
+        rm -v $DRUPAL_PROJECT_FOLDER/composer.json
         echo "Restoring composer.json.backup to $DRUPAL_PROJECT_FOLDER/composer.json"
-        mv composer.json.backup $DRUPAL_PROJECT_FOLDER/composer.json
+        mv -v composer.json.backup $DRUPAL_PROJECT_FOLDER/composer.json
       fi
     # For Nightwatch et al.
     - cd $_WEB_ROOT/core && corepack enable && yarn install && cd $CI_PROJECT_DIR
@@ -602,9 +602,9 @@ composer-lint:
         echo "Validating the composer.json file from the project."
         cd $DRUPAL_PROJECT_FOLDER && pwd
         # Rename the lock file so it is not used in the validation command.
-        test -f composer.lock && mv composer.lock composer.lock.backup
+        test -f composer.lock && mv -v composer.lock composer.lock.backup
         composer validate
-        test -f composer.lock.backup && mv composer.lock.backup composer.lock
+        test -f composer.lock.backup && mv -v composer.lock.backup composer.lock
         cd $CI_PROJECT_DIR
       fi
     - vendor/bin/parallel-lint --version
@@ -940,7 +940,7 @@ cspell:
     - echo "Executing curl -OL https://git.drupalcode.org/$_CURL_TEMPLATES_REPO/-/raw/$_CURL_TEMPLATES_REF/scripts/prepare-cspell.php"
     - curl -OL https://git.drupalcode.org/$_CURL_TEMPLATES_REPO/-/raw/$_CURL_TEMPLATES_REF/scripts/prepare-cspell.php
     # Restore composer.json back to an unchanged version.
-    - test -f $DRUPAL_PROJECT_FOLDER/composer.json && cp $DRUPAL_PROJECT_FOLDER/composer.json composer.json
+    - test -f $DRUPAL_PROJECT_FOLDER/composer.json && cp -v $DRUPAL_PROJECT_FOLDER/composer.json composer.json
     - |
       if [ ! -f .cspell.json ]; then
         echo "Getting default .cspell.json from https://git.drupalcode.org/$_CURL_TEMPLATES_REPO/-/raw/$_CURL_TEMPLATES_REF/assets/.cspell.json"
-- 
GitLab


From 272ee97607b6c312d26f77576b854f18920775dd Mon Sep 17 00:00:00 2001
From: Jonathan Smith <jonathan1055@sandfordsolutions.com>
Date: Wed, 12 Feb 2025 15:18:30 +0000
Subject: [PATCH 11/11] simplify echo msg

---
 includes/include.drupalci.main-d7.yml | 6 +++---
 includes/include.drupalci.main.yml    | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/includes/include.drupalci.main-d7.yml b/includes/include.drupalci.main-d7.yml
index 7049f3ba..dc486242 100644
--- a/includes/include.drupalci.main-d7.yml
+++ b/includes/include.drupalci.main-d7.yml
@@ -362,11 +362,11 @@ stages:
     - php symlink_project.php "$CI_PROJECT_NAME" 'sites/all/modules/custom'
     - rm symlink_project.php
     - echo -e "\e[0Ksection_end:`date +%s`:symlink_output\r\e[0K"
-    # Delete the current composer.json, and then restore from backup if one was made earlier.
+    # Restore composer.json from backup if one was made earlier.
     - |
       if [[ -f composer.json.backup ]]; then
-        rm $DRUPAL_PROJECT_FOLDER/composer.json
-        echo "Restoring composer.json.backup to $DRUPAL_PROJECT_FOLDER/composer.json"
+        echo "Restoring composer.json from backup"
+        rm -v $DRUPAL_PROJECT_FOLDER/composer.json
         mv -v composer.json.backup $DRUPAL_PROJECT_FOLDER/composer.json
       fi
     # Give confirmation of the directories in vendor/drupal and sites/all/modules.
diff --git a/includes/include.drupalci.main.yml b/includes/include.drupalci.main.yml
index b3172401..91fc5825 100644
--- a/includes/include.drupalci.main.yml
+++ b/includes/include.drupalci.main.yml
@@ -477,11 +477,11 @@ stages:
     - php symlink_project.php "$CI_PROJECT_NAME" 'modules/custom'
     - rm symlink_project.php
     - echo -e "\e[0Ksection_end:`date +%s`:symlink_output\r\e[0K"
-    # Delete the current composer.json, and then restore from backup if one was made earlier.
+    # Restore composer.json from backup if one was made earlier.
     - |
       if [[ -f composer.json.backup ]]; then
+        echo "Restoring composer.json from backup"
         rm -v $DRUPAL_PROJECT_FOLDER/composer.json
-        echo "Restoring composer.json.backup to $DRUPAL_PROJECT_FOLDER/composer.json"
         mv -v composer.json.backup $DRUPAL_PROJECT_FOLDER/composer.json
       fi
     # For Nightwatch et al.
-- 
GitLab