Skip to content
Snippets Groups Projects
Commit 01f5ac82 authored by Björn Brala's avatar Björn Brala
Browse files

Issue #3450581: Add checks for error counts. Multiple info.yml is fine, info...

Issue #3450581: Add checks for error counts. Multiple info.yml is fine, info errors can be ignores, multiple composer.json errors are fine.

This should enable a lot more projects to be updated
parent f9ef7d45
No related branches found
No related tags found
1 merge request!30Issue #3450581: Add checks for error counts. Multiple info.yml is fine, info...
Pipeline #185226 passed
......@@ -85,17 +85,28 @@ if [[ -d "$CHECKOUT_DIR/${EXTENTION_TYPE#project_}s/contrib/${MACHINE_NAME}" ]];
cd ${EXTENTION_TYPE#project_}s/contrib/${MACHINE_NAME} || exit 1
if [ -z "$(git status --porcelain)" ]; then
cd $CHECKOUT_DIR || exit 1
# No changes by rector, but we still need to check if info is updatable since there could be only
# info level php file changes.
# Check if the info file is updateable (only the info file and informational errors is left).
php -d sys_temp_dir=$CHECKOUT_DIR -d upload_tmp_dir=$CHECKOUT_DIR ./vendor/bin/info_updatable ${WORKSPACE_DIR}/phpstan-results/${MACHINE_NAME}/${MACHINE_NAME}.${VERSION}.upgrade_status.pre_rector.xml
info_updatable_result=$?
# Check if the composer.json is updateable (only the info file and informational error is left).
php -d sys_temp_dir=$CHECKOUT_DIR -d upload_tmp_dir=$CHECKOUT_DIR ./vendor/bin/composer_json_updatable ${WORKSPACE_DIR}/phpstan-results/${MACHINE_NAME}/${MACHINE_NAME}.${VERSION}.upgrade_status.pre_rector.xml
composer_json_updatable_result=$?
else
# Found uncommitted changes, so we will create a patch!
cd $CHECKOUT_DIR || exit 1
create_patch=1
# Run Upgrade Status again to see what remained after running rector.
php -d sys_temp_dir=$CHECKOUT_DIR -d upload_tmp_dir=$CHECKOUT_DIR ./vendor/bin/drush --root=$CHECKOUT_DIR upgrade_status:analyze --format=checkstyle ${MACHINE_NAME} > ${WORKSPACE_DIR}/phpstan-results/${MACHINE_NAME}/${MACHINE_NAME}.${VERSION}.upgrade_status.post_rector.xml 2>> ${WORKSPACE_DIR}/phpstan-results/${MACHINE_NAME}/${MACHINE_NAME}.${VERSION}.upgrade_status_stderr2
# Check if the info file is updateable (only the info file error is left).
# Check if the info file is updateable (only the info file and informational error is left).
php -d sys_temp_dir=$CHECKOUT_DIR -d upload_tmp_dir=$CHECKOUT_DIR ./vendor/bin/info_updatable ${WORKSPACE_DIR}/phpstan-results/${MACHINE_NAME}/${MACHINE_NAME}.${VERSION}.upgrade_status.post_rector.xml
info_updatable_result=$?
# Check if the composer.json is updateable (only the info file error is left).
# Check if the composer.json is updateable (only the info file and informational error is left).
php -d sys_temp_dir=$CHECKOUT_DIR -d upload_tmp_dir=$CHECKOUT_DIR ./vendor/bin/composer_json_updatable ${WORKSPACE_DIR}/phpstan-results/${MACHINE_NAME}/${MACHINE_NAME}.${VERSION}.upgrade_status.post_rector.xml
composer_json_updatable_result=$?
fi
......
......@@ -24,7 +24,6 @@ class UpdateStatusXmlChecker {
*/
protected $files;
/**
* UpdateStatusXmlChecker constructor.
*/
......@@ -77,16 +76,18 @@ class UpdateStatusXmlChecker {
// should update.
return FALSE;
}
if (count($this->xml->file) > 2) {
// If there is problem with more than 2 files we can't update.
return FALSE;
}
if (count($this->xml->file) === 1) {
return $this->errorsContainInfoYml();
$infoCount = $this->countInfoErrors();
$infoYmlCount = $this->errorsContainInfoYml();
$infoComposerCount = $this->errorsContainComposerJson();
$errorCount = $this->countErrors();
// There are errors that are not informational or based in composer.json or info.yml
if ($errorCount - ($infoCount + $infoComposerCount + $infoYmlCount) > 0) {
return FALSE;
}
return $this->errorsContainInfoYml() && $this->errorsContainComposerJson();
return $infoYmlCount > 0;
}
/**
......@@ -100,16 +101,18 @@ class UpdateStatusXmlChecker {
// should update.
return FALSE;
}
if (count($this->xml->file) > 2) {
// If there is problem with more than 2 files we can't update.
return FALSE;
}
if (count($this->xml->file) === 1) {
return $this->errorsContainComposerJson();
$infoCount = $this->countInfoErrors();
$infoYmlCount = $this->errorsContainInfoYml();
$infoComposerCount = $this->errorsContainComposerJson();
$errorCount = $this->countErrors();
// There are errors that are not informational or based in composer.json or info.yml
if ($errorCount - ($infoCount + $infoComposerCount + $infoYmlCount) > 0) {
return FALSE;
}
return $this->errorsContainComposerJson() && $this->errorsContainInfoYml();
return $infoComposerCount > 0;
}
private function isPhpfile(\SimpleXMLElement $file) {
......@@ -151,7 +154,8 @@ class UpdateStatusXmlChecker {
*
* @return bool
*/
public function errorsContainInfoYml(): bool {
public function errorsContainInfoYml(): int {
$count = 0;
foreach ($this->xml->file as $file) {
$parts = explode('.', (string) $file->attributes()->name);
$ext = array_pop($parts);
......@@ -163,20 +167,23 @@ class UpdateStatusXmlChecker {
foreach ($file->error as $error) {
$message = (string) $error->attributes()['message'];
// Make sure this one single error in this one file is about core version requirements.
return preg_match('/core_version_requirement/', $message) === 1;
if (preg_match('/core_version_requirement/', $message) === 1) {
$count++;
}
}
}
}
return FALSE;
}
return $count;
}
/**
* Determines if the composer.json file has one error
*
* @return bool
* @return int
*/
public function errorsContainComposerJson(): bool {
public function errorsContainComposerJson(): int {
$count = 0;
foreach ($this->xml->file as $file) {
$basename = basename((string) $file->attributes()->name);
// Make sure this is an 'composer.json' file.
......@@ -185,12 +192,35 @@ class UpdateStatusXmlChecker {
if (count($file->error) === 1) {
foreach ($file->error as $error) {
$message = (string) $error->attributes()['message'];
return preg_match('/The drupal\/core requirement is not compatible with the next major version of Drupal/', $message) === 1;
if (preg_match('/The drupal\/core requirement is not compatible with the next major version of Drupal/', $message) === 1) {
$count++;
}
}
}
}
return FALSE;
}
return $count;
}
public function countInfoErrors() {
$count = 0;
foreach ($this->xml->file as $file) {
foreach ($file->error as $error) {
if ((string) $error->attributes()['severity'] === 'info') {
$count++;
}
}
}
return $count;
}
public function countErrors() {
$count = 0;
foreach ($this->xml->file as $file) {
foreach ($file->error as $error) {
$count++;
}
}
return $count;
}
}
<?xml version="1.0"?>
<checkstyle><file name="modules/contrib/rest_views/rest_views.module"><error line="85" message="Call to deprecated method getName() of interface Drupal\Core\Extension\ModuleHandlerInterface. Deprecated in drupal:10.3.0 and is removed from drupal:12.0.0. Use Drupal::service('extension.list.module')-&gt;getName($module) instead." severity="info"/></file><file name="modules/contrib/rest_views/rest_views.info.yml"><error line="4" message="Value of core_version_requirement: ^9.3 || ^10 is not compatible with the next major version of Drupal core. See https://drupal.org/node/3070687." severity="error"/></file><file name="modules/contrib/rest_views/modules/rest_views_search_api/rest_views_search_api.info.yml"><error line="4" message="Value of core_version_requirement: ^9 | ^10 is not compatible with the next major version of Drupal core. See https://drupal.org/node/3070687." severity="error"/></file><file name="modules/contrib/rest_views/modules/rest_views_revisions/rest_views_revisions.info.yml"><error line="4" message="Value of core_version_requirement: ^9 | ^10 is not compatible with the next major version of Drupal core. See https://drupal.org/node/3070687." severity="error"/></file><file name="modules/contrib/rest_views/modules/rest_views_geo/rest_views_geo.info.yml"><error line="4" message="Value of core_version_requirement: ^9 | ^10 is not compatible with the next major version of Drupal core. See https://drupal.org/node/3070687." severity="error"/></file><file name="modules/contrib/rest_views/composer.json"><error line="1" message="The drupal/core requirement is not compatible with the next major version of Drupal. Either remove it or update it to be compatible. See https://www.drupal.org/docs/develop/using-composer/add-a-composerjson-file#core-compatibility." severity="error"/></file></checkstyle>
......@@ -11,6 +11,16 @@ use PHPUnit\Framework\TestCase;
*/
class UpdateStatusXmlCheckerTest extends TestBase {
public function testExpectedCounts() {
$checker = new UpdateStatusXmlChecker(static::FIXTURE_DIR . '/pre_rector_2_majors/pre_rector_2_majors.1.0.upgrade_status.pre_rector.xml');
$this->assertEquals(1, $checker->errorsContainComposerJson(), 'Errors contain composer.json');
$this->assertEquals(4, $checker->errorsContainInfoYml(), 'Errors contain info.yml');
$this->assertEquals(1, $checker->countInfoErrors(), 'Errors info only');
$this->assertEquals(6, $checker->countErrors(), 'Error count total');
}
/**
* @covers ::isInfoUpdatable
......@@ -34,6 +44,12 @@ class UpdateStatusXmlCheckerTest extends TestBase {
// When only an info.yml and composer.json update is required, we should also be updatable
$checker = new UpdateStatusXmlChecker(static::FIXTURE_DIR . '/country.1.x-dev.upgrade_status.pre_rector.xml');
$this->assertTrue($checker->isInfoUpdatable());
$checker = new UpdateStatusXmlChecker(static::FIXTURE_DIR . '/pre_rector_2_majors/pre_rector_2_majors.1.0.upgrade_status.pre_rector.xml');
$this->assertTrue($checker->isInfoUpdatable());
}
/**
......@@ -45,6 +61,9 @@ class UpdateStatusXmlCheckerTest extends TestBase {
$checker = new UpdateStatusXmlChecker(static::FIXTURE_DIR . '/viewfield.3.x-dev.upgrade_status.pre_rector.xml');
$this->assertFalse($checker->runRector());
$checker = new UpdateStatusXmlChecker(static::FIXTURE_DIR . '/pre_rector_2_majors/pre_rector_2_majors.1.0.upgrade_status.pre_rector.xml');
$this->assertTrue($checker->runRector());
}
......@@ -63,5 +82,8 @@ class UpdateStatusXmlCheckerTest extends TestBase {
// Don't allow an update if there is other errors
$checker = new UpdateStatusXmlChecker(static::FIXTURE_DIR . '/country.1.x-dev.upgrade_status.no_update.xml');
$this->assertFalse($checker->isComposerUpdatable());
$checker = new UpdateStatusXmlChecker(static::FIXTURE_DIR . '/pre_rector_2_majors/pre_rector_2_majors.1.0.upgrade_status.pre_rector.xml');
$this->assertTrue($checker->isComposerUpdatable());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment