Skip to content
16 changes: 16 additions & 0 deletions configuration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ DRUPAL_TESTING_SITES_DIRECTORY=${DRUPAL_TESTING_SITES_DIRECTORY:-default}
# This directory gets removed after successful tests.
DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY=${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY:-${DRUPAL_TESTING_TEST_BASE_DIRECTORY}/install}

# The version of the project to upgrade from.
DRUPAL_TESTING_UPGRADE_VERSION=${DRUPAL_TESTING_UPGRADE_VERSION:-""}

# The version of the composer project to upgrade from.
DRUPAL_TESTING_UPGRADE_COMPOSER_PROJECT_VERSION=${DRUPAL_TESTING_UPGRADE_COMPOSER_PROJECT_VERSION:-""}

# The path to the git checkout under test.
DRUPAL_TESTING_WORKSPACE=${DRUPAL_TESTING_WORKSPACE:-${GITHUB_WORKSPACE}}

# The version of Drush to use prior to upgrading.
DRUPAL_TESTING_UPGRADE_DRUSH_VERSION=${DRUPAL_TESTING_UPGRADE_DRUSH_VERSION:-"10.3.6"}

# The location where the project will be copied to and the version to upgrade
# from will be checkout out here.
DRUPAL_TESTING_UPGRADE_DRUPAL_INSTALLATION_DIRECTORY=${DRUPAL_TESTING_UPGRADE_DRUPAL_INSTALLATION_DIRECTORY:-${DRUPAL_TESTING_TEST_BASE_DIRECTORY}/old_install}

# The directory, where the tests are located relative to the docroot. This will default to the project directory.
DRUPAL_TESTING_TEST_LOCATION=${DRUPAL_TESTING_TEST_LOCATION:-""}

Expand Down
5 changes: 5 additions & 0 deletions lib/clean_up.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ clean_up() {
docker rm -f -v "${DRUPAL_TESTING_SELENIUM_DOCKER_NAME}"
fi

if [[ -d ${DRUPAL_TESTING_UPGRADE_DRUPAL_INSTALLATION_DIRECTORY} ]]; then
chmod -R u+w "${DRUPAL_TESTING_UPGRADE_DRUPAL_INSTALLATION_DIRECTORY}"
rm -rf "${DRUPAL_TESTING_UPGRADE_DRUPAL_INSTALLATION_DIRECTORY}"
fi

if [[ -d ${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY} ]]; then
chmod -R u+w "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
rm -rf "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
Expand Down
6 changes: 6 additions & 0 deletions lib/stage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ stage_dependency() {
prepare_build)
dep="requirements"
;;
prepare_old_install)
dep="requirements"
;;
prepare_upgrade)
dep="prepare_old_install"
;;
requirements)
dep="coding_style"
;;
Expand Down
62 changes: 62 additions & 0 deletions lib/stages/prepare_old_install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/env bash

_stage_prepare_old_install() {
local docroot
docroot=$(get_distribution_docroot false)
export COMPOSER_ROOT_VERSION=${DRUPAL_TESTING_UPGRADE_COMPOSER_PROJECT_VERSION}

# When we test a full project, all we need is the project files itself.
if [[ ${DRUPAL_TESTING_PROJECT_TYPE} != "drupal-profile" ]]; then
printf "prepare_upgrade is only useful for profiles\n"
exit 1
fi

# Checkout the profile and get the version we want to upgrade from.
mkdir -p ${DRUPAL_TESTING_UPGRADE_DRUPAL_INSTALLATION_DIRECTORY}
cp -R ${DRUPAL_TESTING_WORKSPACE}/. ${DRUPAL_TESTING_UPGRADE_DRUPAL_INSTALLATION_DIRECTORY}
git -C ${DRUPAL_TESTING_UPGRADE_DRUPAL_INSTALLATION_DIRECTORY} fetch
git -C ${DRUPAL_TESTING_UPGRADE_DRUPAL_INSTALLATION_DIRECTORY} checkout ${DRUPAL_TESTING_UPGRADE_VERSION}

printf "Prepare composer.json\n\n"

# Build is based on drupal project
composer create-project "${DRUPAL_TESTING_COMPOSER_PROJECT}":"${DRUPAL_TESTING_UPGRADE_COMPOSER_PROJECT_VERSION}" "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}" --no-interaction --no-install

composer config "minimum-stability" dev --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
composer config "prefer-stable" true --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"

# Reorder repositories, to make sure, local path is first.
composer config repositories.0 path "${DRUPAL_TESTING_UPGRADE_DRUPAL_INSTALLATION_DIRECTORY}" --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"

jq '.repositories[0].options = {}' "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}""/composer.json" | awk 'BEGIN{RS="";getline<"-";print>ARGV[1]}' "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}""/composer.json"
jq '.repositories[0].options.symlink = false' "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}""/composer.json" | awk 'BEGIN{RS="";getline<"-";print>ARGV[1]}' "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}""/composer.json"

composer config repositories.1 composer https://asset-packagist.org --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
composer config repositories.2 composer https://packages.drupal.org/8 --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"

# Enable patching
composer require cweagans/composer-patches --no-update --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
composer config extra.enable-patching true --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"

composer require drush/drush:${DRUPAL_TESTING_UPGRADE_DRUSH_VERSION} --prefer-lowest --no-update --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"

# Allow required plugins
composer config allow-plugins.cweagans/composer-patches true --no-plugins --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
composer config allow-plugins.drupal/core-composer-scaffold true --no-plugins --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
composer config allow-plugins.drupal/core-project-message true --no-plugins --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
composer config allow-plugins.composer/installers true --no-plugins --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
composer config allow-plugins.oomphinc/composer-installers-extender true --no-plugins --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true --no-plugins --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
composer config allow-plugins.phpstan/extension-installer true --no-plugins --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"

# Install the lowest versions of everything.
composer update --prefer-lowest --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"

if [[ ! -d ${DRUPAL_TESTING_LOCK_FILES_DIRECTORY} ]]; then
mkdir -p "${DRUPAL_TESTING_LOCK_FILES_DIRECTORY}"
fi

# Fake stage completion so that install can run.
touch "${DRUPAL_TESTING_LOCK_FILES_DIRECTORY}/build"
touch "${DRUPAL_TESTING_LOCK_FILES_DIRECTORY}/prepare_build"
}
48 changes: 48 additions & 0 deletions lib/stages/prepare_upgrade.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash

_stage_prepare_upgrade() {
local docroot
docroot=$(get_distribution_docroot false)

# When we test a full project, all we need is the project files itself.
if [[ ${DRUPAL_TESTING_PROJECT_TYPE} != "drupal-profile" ]]; then
printf "prepare_upgrade is only useful for profiles\n"
exit 1
fi

# Add asset-packagist for projects, that require frontend assets
if ! composer_repository_exists "https://asset-packagist.org"; then
composer config extra."installer-types".0 bower-asset --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
composer config extra."installer-types".1 npm-asset --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"

jq '.extra."installer-paths"."'"${docroot}"'/libraries/{$name}" += ["type:bower-asset", "type:npm-asset"]' "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}""/composer.json" >"${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}""/composer.tmp"
mv "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}""/composer.tmp" "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}""/composer.json"

composer require oomphinc/composer-installers-extender --no-update --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
fi

composer require phpspec/prophecy-phpunit:^2 --dev --no-update --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"

# Require phpstan.
if [ "${DRUPAL_TESTING_TEST_DEPRECATION}" = true ]; then
composer require mglaman/phpstan-drupal:^1.1 --dev --no-update --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
composer require phpstan/phpstan-deprecation-rules:^1.0 --dev --no-update --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
fi

# Paratest.
if [ "${DRUPAL_TESTING_PARALLEL_TESTING}" = true ]; then
composer require brianium/paratest:^6.3 --dev --no-update --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
fi

# Set the path repository back to the project under test.
composer config repositories.0 path "${DRUPAL_TESTING_WORKSPACE}" --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"

# Use jq to find all dev dependencies of the project and add them to root composer file.
for dev_dependency in $(jq -r '.["require-dev"?] | keys[] as $k | "\($k):\(.[$k])"' "${DRUPAL_TESTING_PROJECT_BASEDIR}"/composer.json); do
composer require "${dev_dependency}" --dev --no-update --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
done

# Use the latest drush.
composer require drush/drush --no-update --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"

}