Skip to content

Commit bcc4b69

Browse files
authored
Add upgrade commands (#79)
1 parent fcf201e commit bcc4b69

File tree

5 files changed

+137
-0
lines changed

5 files changed

+137
-0
lines changed

configuration.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,22 @@ DRUPAL_TESTING_SITES_DIRECTORY=${DRUPAL_TESTING_SITES_DIRECTORY:-default}
9595
# This directory gets removed after successful tests.
9696
DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY=${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY:-${DRUPAL_TESTING_TEST_BASE_DIRECTORY}/install}
9797

98+
# The version of the project to upgrade from.
99+
DRUPAL_TESTING_UPGRADE_VERSION=${DRUPAL_TESTING_UPGRADE_VERSION:-""}
100+
101+
# The version of the composer project to upgrade from.
102+
DRUPAL_TESTING_UPGRADE_COMPOSER_PROJECT_VERSION=${DRUPAL_TESTING_UPGRADE_COMPOSER_PROJECT_VERSION:-""}
103+
104+
# The path to the git checkout under test.
105+
DRUPAL_TESTING_WORKSPACE=${DRUPAL_TESTING_WORKSPACE:-${GITHUB_WORKSPACE}}
106+
107+
# The version of Drush to use prior to upgrading.
108+
DRUPAL_TESTING_UPGRADE_DRUSH_VERSION=${DRUPAL_TESTING_UPGRADE_DRUSH_VERSION:-"10.3.6"}
109+
110+
# The location where the project will be copied to and the version to upgrade
111+
# from will be checkout out here.
112+
DRUPAL_TESTING_UPGRADE_DRUPAL_INSTALLATION_DIRECTORY=${DRUPAL_TESTING_UPGRADE_DRUPAL_INSTALLATION_DIRECTORY:-${DRUPAL_TESTING_TEST_BASE_DIRECTORY}/old_install}
113+
98114
# The directory, where the tests are located relative to the docroot. This will default to the project directory.
99115
DRUPAL_TESTING_TEST_LOCATION=${DRUPAL_TESTING_TEST_LOCATION:-""}
100116

lib/clean_up.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ clean_up() {
77
docker rm -f -v "${DRUPAL_TESTING_SELENIUM_DOCKER_NAME}"
88
fi
99

10+
if [[ -d ${DRUPAL_TESTING_UPGRADE_DRUPAL_INSTALLATION_DIRECTORY} ]]; then
11+
chmod -R u+w "${DRUPAL_TESTING_UPGRADE_DRUPAL_INSTALLATION_DIRECTORY}"
12+
rm -rf "${DRUPAL_TESTING_UPGRADE_DRUPAL_INSTALLATION_DIRECTORY}"
13+
fi
14+
1015
if [[ -d ${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY} ]]; then
1116
chmod -R u+w "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
1217
rm -rf "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"

lib/stage.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ stage_dependency() {
5757
prepare_build)
5858
dep="requirements"
5959
;;
60+
prepare_old_install)
61+
dep="requirements"
62+
;;
63+
prepare_upgrade)
64+
dep="prepare_old_install"
65+
;;
6066
requirements)
6167
dep="coding_style"
6268
;;

lib/stages/prepare_old_install.sh

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/usr/bin/env bash
2+
3+
_stage_prepare_old_install() {
4+
local docroot
5+
docroot=$(get_distribution_docroot false)
6+
export COMPOSER_ROOT_VERSION=${DRUPAL_TESTING_UPGRADE_COMPOSER_PROJECT_VERSION}
7+
8+
# When we test a full project, all we need is the project files itself.
9+
if [[ ${DRUPAL_TESTING_PROJECT_TYPE} != "drupal-profile" ]]; then
10+
printf "prepare_upgrade is only useful for profiles\n"
11+
exit 1
12+
fi
13+
14+
# Checkout the profile and get the version we want to upgrade from.
15+
mkdir -p ${DRUPAL_TESTING_UPGRADE_DRUPAL_INSTALLATION_DIRECTORY}
16+
cp -R ${DRUPAL_TESTING_WORKSPACE}/. ${DRUPAL_TESTING_UPGRADE_DRUPAL_INSTALLATION_DIRECTORY}
17+
git -C ${DRUPAL_TESTING_UPGRADE_DRUPAL_INSTALLATION_DIRECTORY} fetch
18+
git -C ${DRUPAL_TESTING_UPGRADE_DRUPAL_INSTALLATION_DIRECTORY} checkout ${DRUPAL_TESTING_UPGRADE_VERSION}
19+
20+
printf "Prepare composer.json\n\n"
21+
22+
# Build is based on drupal project
23+
composer create-project "${DRUPAL_TESTING_COMPOSER_PROJECT}":"${DRUPAL_TESTING_UPGRADE_COMPOSER_PROJECT_VERSION}" "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}" --no-interaction --no-install
24+
25+
composer config "minimum-stability" dev --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
26+
composer config "prefer-stable" true --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
27+
28+
# Reorder repositories, to make sure, local path is first.
29+
composer config repositories.0 path "${DRUPAL_TESTING_UPGRADE_DRUPAL_INSTALLATION_DIRECTORY}" --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
30+
31+
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"
32+
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"
33+
34+
composer config repositories.1 composer https://asset-packagist.org --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
35+
composer config repositories.2 composer https://packages.drupal.org/8 --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
36+
37+
# Enable patching
38+
composer require cweagans/composer-patches --no-update --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
39+
composer config extra.enable-patching true --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
40+
41+
composer require drush/drush:${DRUPAL_TESTING_UPGRADE_DRUSH_VERSION} --prefer-lowest --no-update --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
42+
43+
# Allow required plugins
44+
composer config allow-plugins.cweagans/composer-patches true --no-plugins --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
45+
composer config allow-plugins.drupal/core-composer-scaffold true --no-plugins --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
46+
composer config allow-plugins.drupal/core-project-message true --no-plugins --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
47+
composer config allow-plugins.composer/installers true --no-plugins --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
48+
composer config allow-plugins.oomphinc/composer-installers-extender true --no-plugins --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
49+
composer config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true --no-plugins --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
50+
composer config allow-plugins.phpstan/extension-installer true --no-plugins --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
51+
52+
# Install the lowest versions of everything.
53+
composer update --prefer-lowest --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
54+
55+
if [[ ! -d ${DRUPAL_TESTING_LOCK_FILES_DIRECTORY} ]]; then
56+
mkdir -p "${DRUPAL_TESTING_LOCK_FILES_DIRECTORY}"
57+
fi
58+
59+
# Fake stage completion so that install can run.
60+
touch "${DRUPAL_TESTING_LOCK_FILES_DIRECTORY}/build"
61+
touch "${DRUPAL_TESTING_LOCK_FILES_DIRECTORY}/prepare_build"
62+
}

lib/stages/prepare_upgrade.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
3+
_stage_prepare_upgrade() {
4+
local docroot
5+
docroot=$(get_distribution_docroot false)
6+
7+
# When we test a full project, all we need is the project files itself.
8+
if [[ ${DRUPAL_TESTING_PROJECT_TYPE} != "drupal-profile" ]]; then
9+
printf "prepare_upgrade is only useful for profiles\n"
10+
exit 1
11+
fi
12+
13+
# Add asset-packagist for projects, that require frontend assets
14+
if ! composer_repository_exists "https://asset-packagist.org"; then
15+
composer config extra."installer-types".0 bower-asset --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
16+
composer config extra."installer-types".1 npm-asset --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
17+
18+
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"
19+
mv "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}""/composer.tmp" "${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}""/composer.json"
20+
21+
composer require oomphinc/composer-installers-extender --no-update --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
22+
fi
23+
24+
composer require phpspec/prophecy-phpunit:^2 --dev --no-update --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
25+
26+
# Require phpstan.
27+
if [ "${DRUPAL_TESTING_TEST_DEPRECATION}" = true ]; then
28+
composer require mglaman/phpstan-drupal:^1.1 --dev --no-update --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
29+
composer require phpstan/phpstan-deprecation-rules:^1.0 --dev --no-update --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
30+
fi
31+
32+
# Paratest.
33+
if [ "${DRUPAL_TESTING_PARALLEL_TESTING}" = true ]; then
34+
composer require brianium/paratest:^6.3 --dev --no-update --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
35+
fi
36+
37+
# Set the path repository back to the project under test.
38+
composer config repositories.0 path "${DRUPAL_TESTING_WORKSPACE}" --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
39+
40+
# Use jq to find all dev dependencies of the project and add them to root composer file.
41+
for dev_dependency in $(jq -r '.["require-dev"?] | keys[] as $k | "\($k):\(.[$k])"' "${DRUPAL_TESTING_PROJECT_BASEDIR}"/composer.json); do
42+
composer require "${dev_dependency}" --dev --no-update --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
43+
done
44+
45+
# Use the latest drush.
46+
composer require drush/drush --no-update --working-dir="${DRUPAL_TESTING_DRUPAL_INSTALLATION_DIRECTORY}"
47+
48+
}

0 commit comments

Comments
 (0)