Skip to content

Commit

Permalink
[#398] Add Drupal 9 readiness checks to CI. (#404)
Browse files Browse the repository at this point in the history
* [#398] Add Drupal 9 readiness checks to CI.

* [#398] Add Drupal 9 readiness checks to CI - updates.

* [#398] Allow build against D9.

* [#398] Testing matrix w/D8 and D9.

* [#398] Testing matrix w/D8 and D9 - adding back rest of steps.

* [#398] Fixing EdgeExceptionSubscriber and EdgeExceptionSubscriberTest for D9 (due to drupal.org/project/drupal/issues/3113876).

* [#398] Fixing functional tests for D9.

* [#398] Order of execution of jobs in CircleCI.

* [#398] Fixes tests.

* [#398] Fixing matrix of jobs in CircleCI.

* [#398] Fixing matrix of jobs in CircleCI.

* [#398] Fixing matrix of jobs in CircleCI.

* [#398] Fixing matrix of jobs in CircleCI.

* [#398] Fixing matrix of jobs in CircleCI.

* [#398] Fixing matrix of jobs in CircleCI.

* [#398] Fixing composer issue.

* [#398] Use d8 for tests.

* [#398] enable code sniffer and drupal-check.

* [#398] Fix deprecations from drupal-check.

* [#398] Reenable functional JS tests.

* [#398] Fix deprecation comment format.
  • Loading branch information
arlina-espinoza authored Aug 6, 2020
1 parent 453354d commit 6364c49
Show file tree
Hide file tree
Showing 17 changed files with 321 additions and 114 deletions.
74 changes: 61 additions & 13 deletions .circleci/RoboFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ public function setupSkeleton()
->mkdir('artifacts/phpcs')
->mkdir('artifacts/phpmd')
->mkdir('artifacts/phpmetrics')
->mkdir('artifacts/d9')
->mkdir('/tmp/artifacts/phpunit')
->mkdir('/tmp/artifacts/phpmd')
->run();

$this->taskFilesystemStack()
->chown('/tmp/artifacts', 'www-data', TRUE)
->copy('modules/apigee_edge/.circleci/d9.sh', '/var/www/html/d9.sh')
->chmod('/var/www/html/d9.sh', 0777)
->run();
}

Expand Down Expand Up @@ -95,6 +98,7 @@ public function addBehatDeps()
public function addModules(array $modules)
{
$config = json_decode(file_get_contents('composer.json'));
$config->extra->{"merge-plugin"}->{"ignore-duplicates"} = TRUE;

foreach ($modules as $module) {
list($module,) = explode(':', $module);
Expand Down Expand Up @@ -172,7 +176,11 @@ public function updateDependencies()
// on it fails for the first time.
$this->taskFilesystemStack()->remove('composer.lock')->run();

$this->taskDeleteDir('vendor/')->run();
// Remove all core files and vendor.
$this->taskFilesystemStack()
->taskDeleteDir('core')
->taskDeleteDir('vendor')
->run();

// Composer often runs out of memory when installing drupal.
$this->taskComposerInstall('php -d memory_limit=-1 /usr/local/bin/composer')
Expand All @@ -196,6 +204,8 @@ public function updateDependencies()
->run();

// Add composer version info to an artifact file.
$this->taskExec('composer show')
->run();
$this->taskExec('composer show > /tmp/artifacts/composer-show.txt')
->run();
}
Expand Down Expand Up @@ -401,22 +411,47 @@ public function extractCoverageStats($path)
}

/**
* Adds modules to the merge section.
* Set the Drupal core version.
*
* @param int $drupalCoreVersion
* The major version of Drupal required.
*/
public function configureModuleDependencies()
public function drupalVersion($drupalCoreVersion)
{
$config = json_decode(file_get_contents('composer.json'));

// The Drupal core image might need updating. Request the newest stable.
unset($config->require->{"drupal/core"});
$config->require->{"drupal/core-recommended"} = "~8.8";

// Add rules for testing apigee_edge_actions.
$config->require->{"drupal/rules"} = "3.0.0-alpha5";
switch ($drupalCoreVersion) {
case '9':
$config->require->{"drupal/core-recommended"} = '^9';
$config->require->{"drupal/core-dev"} = '^9';

break;

case '8':
$config->require->{"drupal/core-recommended"} = '~8';
$config->require->{"drupal/core-dev"} = '~8';

// We require Drupal console and drush for some tests.
$config->require->{"drupal/console"} = "~1.0";
$config->require->{"drush/drush"} = "^9.7";
// Add rules for testing apigee_edge_actions (only for D8).
$config->require->{"drupal/rules"} = "3.0.0-alpha5";

// We require Drupal drush and console for some tests.
$config->require->{"drupal/console"} = "~1.0";

default:
break;
}

file_put_contents('composer.json', json_encode($config, JSON_PRETTY_PRINT));
}

/**
* Adds modules to the merge section.
*/
public function configureModuleDependencies()
{
$config = json_decode(file_get_contents('composer.json'));

// If you require core, you must not replace it.
unset($config->replace);
Expand All @@ -433,10 +468,23 @@ public function configureModuleDependencies()
}
$config->extra->{"merge-plugin"}->include = array_values($config->extra->{"merge-plugin"}->include);

// Add dependencies for phpunit tests.
$config->require->{"drupal/core-dev"} = "~8.8";

file_put_contents('composer.json', json_encode($config, JSON_PRETTY_PRINT));
}

/**
* Perform extra tasks per Drupal core version.
*
* @param int $drupalCoreVersion
* The major version of Drupal required.
*/
public function doExtra($drupalCoreVersion) {
if ($drupalCoreVersion > 8) {

// Delete D8 only modules.
$this->taskFilesystemStack()
->taskDeleteDir('modules/apigee_edge/modules/apigee_edge_actions')
->run();
}
}

}
84 changes: 71 additions & 13 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@
# Check https://circleci.com/docs/2.0/language-php/ for more details
#

version: 2.1

defaults: &defaults
docker:
# specify the version you desire here (avoid latest except for testing)
- image: andrewberry/drupal_tests:0.4.0
- image: quay.io/deviantintegral/drupal_tests:0.5.0-drupal87

- image: selenium/standalone-chrome-debug:3.141.59-neon

Expand All @@ -34,6 +36,11 @@ defaults: &defaults
# https://discuss.circleci.com/t/bug-circleci-build-command-ignores-checkout-path-config/13004
working_directory: /var/www/html/modules/apigee_edge

parameters:
core-version:
type: integer
default: 8

# YAML does not support merging of lists. That means we can't have a default
# 'steps' configuration, though we can have defaults for individual step
# properties.
Expand All @@ -55,7 +62,11 @@ save_cache: &save_cache
# Install composer dependencies into the workspace to share with all jobs.
update_dependencies: &update_dependencies
<<: *defaults

steps:
- print:
message: Using Drupal core version << parameters.core-version >>

- checkout

- restore_cache: *restore_cache
Expand All @@ -64,7 +75,7 @@ update_dependencies: &update_dependencies
working_directory: /var/www/html
command: |
cp ./modules/apigee_edge/.circleci/update-dependencies.sh /var/www/html
./update-dependencies.sh apigee_edge
./update-dependencies.sh apigee_edge << parameters.core-version >>
- save_cache: *save_cache

Expand Down Expand Up @@ -92,7 +103,7 @@ unit_kernel_tests: &unit_kernel_tests
working_directory: /var/www/html
command: |
cp ./modules/apigee_edge/.circleci/test.sh /var/www/html
./test.sh apigee_edge
./test.sh apigee_edge << parameters.core-version >>
- store_test_results:
path: /tmp/artifacts/phpunit
Expand All @@ -115,7 +126,7 @@ functional_tests: &functional_tests
working_directory: /var/www/html
command: |
cp ./modules/apigee_edge/.circleci/test-functional.sh /var/www/html
./test-functional.sh apigee_edge
./test-functional.sh apigee_edge << parameters.core-version >>
- store_test_results:
path: /tmp/artifacts/phpunit
Expand All @@ -137,7 +148,7 @@ functional_js_tests: &functional_js_tests
working_directory: /var/www/html
command: |
cp ./modules/apigee_edge/.circleci/test-functional-js.sh /var/www/html
./test-functional-js.sh apigee_edge
./test-functional-js.sh apigee_edge << parameters.core-version >>
- store_test_results:
path: /tmp/artifacts/phpunit
Expand Down Expand Up @@ -180,8 +191,34 @@ code_coverage: &code_coverage
- store_artifacts:
path: /var/www/html/artifacts

# Run D9 deprecation checks.
d9_check: &d9_check
<<: *defaults
steps:
- attach_workspace:
at: /var/www/html

- checkout

- run:
working_directory: /var/www/html
command: |
./d9.sh modules/apigee_edge
- store_test_results:
path: /var/www/html/artifacts/d9
- store_artifacts:
path: /var/www/html/artifacts/d9

commands:
print:
parameters:
message:
type: string
steps:
- run: echo << parameters.message >>

# Declare all of the jobs we should run.
version: 2
jobs:
update-dependencies:
<<: *update_dependencies
Expand All @@ -195,6 +232,8 @@ jobs:
<<: *code_sniffer
run-code-coverage:
<<: *code_coverage
run-d9-check:
<<: *d9_check

workflows:
version: 2
Expand All @@ -203,19 +242,38 @@ workflows:
# Functional JS tests need to run after functional due to a conflict in apigee_edge_apiproduct_rbac tests.
test_and_lint:
jobs:
- update-dependencies
- update-dependencies:
name: update-dependencies-<< matrix.core-version >>
matrix:
parameters:
core-version: [8]
- run-code-sniffer:
requires:
- update-dependencies-8
- run-d9-check:
requires:
- update-dependencies-8
- run-unit-kernel-tests:
name: run-unit-kernel-tests-<< matrix.core-version >>
matrix:
parameters:
core-version: [8]
requires:
- update-dependencies
- update-dependencies-<< matrix.core-version >>
- run-functional-tests:
name: run-functional-tests-<< matrix.core-version >>
matrix:
parameters:
core-version: [8]
requires:
- update-dependencies
- update-dependencies-<< matrix.core-version >>
- run-functional-js-tests:
name: run-functional-js-tests-<< matrix.core-version >>
matrix:
parameters:
core-version: [8]
requires:
- update-dependencies
- run-code-sniffer:
requires:
- update-dependencies
- update-dependencies-<< matrix.core-version >>
# - run-code-coverage:
# requires:
# - update-dependencies
Expand Down
9 changes: 9 additions & 0 deletions .circleci/d9.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash -ex

if [ ! -f dependencies_updated ]
then
./update-dependencies.sh $1
fi

vendor/bin/drupal-check --no-progress --memory-limit=1000M --format=junit $1 > /var/www/html/artifacts/d9/d9check.xml

3 changes: 2 additions & 1 deletion .circleci/test-functional-js.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ export MINK_DRIVER_ARGS_WEBDRIVER='["chrome", null, "http://localhost:4444/wd/hu

if [ ! -f dependencies_updated ]
then
./update-dependencies.sh $1
./update-dependencies.sh $1 $2
fi

# This is the command used by the base image to serve Drupal.
apache2-foreground&

robo override:phpunit-config $1
robo do:extra $2

sudo -E -u www-data vendor/bin/phpunit -c core --group $1 --testsuite functional-javascript --debug --verbose --log-junit /tmp/artifacts/phpunit/phpunit.xml
3 changes: 2 additions & 1 deletion .circleci/test-functional.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ export BROWSERTEST_OUTPUT_DIRECTORY="/var/www/html/sites/simpletest"

if [ ! -f dependencies_updated ]
then
./update-dependencies.sh $1
./update-dependencies.sh $1 $2
fi

# This is the command used by the base image to serve Drupal.
apache2-foreground&

robo override:phpunit-config $1
robo do:extra $2

sudo -E -u www-data vendor/bin/phpunit -c core --group $1 --testsuite functional --debug --verbose --log-junit /tmp/artifacts/phpunit/phpunit.xml
4 changes: 3 additions & 1 deletion .circleci/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ export BROWSERTEST_OUTPUT_DIRECTORY="/var/www/html/sites/simpletest"

if [ ! -f dependencies_updated ]
then
./update-dependencies.sh $1
./update-dependencies.sh $1 $2
fi

# This is the command used by the base image to serve Drupal.
apache2-foreground&

robo override:phpunit-config $1
robo do:extra $2
composer show

sudo -E -u www-data vendor/bin/phpunit -c core --group $1 --testsuite unit,kernel --debug --verbose --log-junit /tmp/artifacts/phpunit/phpunit.xml
2 changes: 2 additions & 0 deletions .circleci/update-dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ cp modules/apigee_edge/.circleci/RoboFile.php ./

robo setup:skeleton
robo add:modules $1
robo drupal:version $2
robo configure:module-dependencies
robo update:dependencies
robo do:extra $2

# Touch a flag so we know dependencies have been set. Otherwise, there is no
# easy way to know this step needs to be done when running circleci locally since
Expand Down
6 changes: 3 additions & 3 deletions apigee_edge.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ services:
apigee_edge.exception_subscriber:
class: Drupal\apigee_edge\EventSubscriber\EdgeExceptionSubscriber
arguments:
- '@http_kernel'
- '@logger.channel.apigee_edge'
- '@redirect.destination'
- '@router.no_access_checks'
- '@config.factory'
- '@messenger'
- '@class_resolver'
- '@current_route_match'
- '%main_content_renderers%'
tags:
- { name: event_subscriber }

Expand Down
Loading

0 comments on commit 6364c49

Please sign in to comment.