From 9db1cd056e22cd26151e1a174cc5652869ec1c03 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 21 Jul 2022 14:44:02 +1200 Subject: [PATCH 1/3] MNT Add GitHub Actions CI --- .github/workflows/ci.yml | 18 ++++++++++++++++++ .github/workflows/keepalive.yml | 16 ++++++++++++++++ README.md | 2 +- 3 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/keepalive.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..d5bcaf3c7 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,18 @@ +name: CI + +on: + push: + pull_request: + workflow_dispatch: + # Every Tuesday at 2:20pm UTC + schedule: + - cron: '20 14 * * 2' + +jobs: + ci: + uses: silverstripe/gha-ci/.github/workflows/ci.yml@v1 + with: + # Turn phpcoverage off because it causes a segfault + phpcoverage_force_off: true + # There is a strange behat.yml file in framework that runs behat tests in the admin module + endtoend: false diff --git a/.github/workflows/keepalive.yml b/.github/workflows/keepalive.yml new file mode 100644 index 000000000..084225b8a --- /dev/null +++ b/.github/workflows/keepalive.yml @@ -0,0 +1,16 @@ + +name: Keepalive + +on: + # The 4th of every month at 10:50am UTC + schedule: + - cron: '50 10 4 * *' + workflow_dispatch: + +jobs: + keepalive: + name: Keepalive + runs-on: ubuntu-latest + steps: + - name: Keepalive + uses: silverstripe/gha-keepalive@v1 diff --git a/README.md b/README.md index 0da87b0d5..327ea656c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ## SilverStripe Framework -[![Build Status](https://api.travis-ci.com/silverstripe/silverstripe-framework.svg?branch=4)](https://travis-ci.com/silverstripe/silverstripe-framework) +[![CI](https://github.com/silverstripe/silverstripe-framework/actions/workflows/ci.yml/badge.svg)](https://github.com/silverstripe/silverstripe-framework/actions/workflows/ci.yml) [![Build Docs](https://github.com/silverstripe/silverstripe-framework/workflows/Build%20Docs/badge.svg)](https://docs.silverstripe.org/) [![Latest Stable Version](https://poser.pugx.org/silverstripe/framework/version.svg)](https://www.silverstripe.org/stable-download/) [![Latest Unstable Version](https://poser.pugx.org/silverstripe/framework/v/unstable.svg)](https://packagist.org/packages/silverstripe/framework) From 674e6d9b7ba31b6be838140367885f61ff9ea727 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Thu, 21 Jul 2022 15:19:16 +1200 Subject: [PATCH 2/3] MNT Update utf8 aliases for mysql 8 and mariadb 10.6 --- tests/php/ORM/MySQLPDOConnectorTest.php | 11 ++-- tests/php/ORM/MySQLiConnectorTest.php | 10 +++- tests/php/ORM/Utf8/Utf8TestHelper.php | 69 +++++++++++++++++++++++++ 3 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 tests/php/ORM/Utf8/Utf8TestHelper.php diff --git a/tests/php/ORM/MySQLPDOConnectorTest.php b/tests/php/ORM/MySQLPDOConnectorTest.php index 9ce68399d..f027edb36 100644 --- a/tests/php/ORM/MySQLPDOConnectorTest.php +++ b/tests/php/ORM/MySQLPDOConnectorTest.php @@ -9,6 +9,7 @@ use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\TestOnly; use SilverStripe\ORM\Tests\MySQLPDOConnectorTest\PDOConnector; use SilverStripe\ORM\DB; +use SilverStripe\Tests\ORM\Utf8\Utf8TestHelper; /** * @requires extension PDO @@ -38,8 +39,9 @@ class MySQLPDOConnectorTest extends SapphireTest implements TestOnly $cset = $connection->query('show variables like "character_set_connection"')->fetch(PDO::FETCH_NUM)[1]; $collation = $connection->query('show variables like "collation_connection"')->fetch(PDO::FETCH_NUM)[1]; - $this->assertEquals($charset, $cset); - $this->assertEquals($defaultCollation, $collation); + $helper = new Utf8TestHelper(); + $this->assertEquals($helper->getUpdatedUtfCharsetForCurrentDB($charset), $cset); + $this->assertEquals($helper->getUpdatedUtfCollationForCurrentDB($defaultCollation), $collation); unset($cset, $connection, $connector, $config); } @@ -66,8 +68,9 @@ class MySQLPDOConnectorTest extends SapphireTest implements TestOnly $cset = $connection->query('show variables like "character_set_connection"')->fetch(PDO::FETCH_NUM)[1]; $collation = $connection->query('show variables like "collation_connection"')->fetch(PDO::FETCH_NUM)[1]; - $this->assertEquals($charset, $cset); - $this->assertEquals($customCollation, $collation); + $helper = new Utf8TestHelper(); + $this->assertEquals($helper->getUpdatedUtfCharsetForCurrentDB($charset), $cset); + $this->assertEquals($helper->getUpdatedUtfCollationForCurrentDB($customCollation), $collation); unset($cset, $connection, $connector, $config); } diff --git a/tests/php/ORM/MySQLiConnectorTest.php b/tests/php/ORM/MySQLiConnectorTest.php index 001c18cdb..e4c9a34f6 100644 --- a/tests/php/ORM/MySQLiConnectorTest.php +++ b/tests/php/ORM/MySQLiConnectorTest.php @@ -6,6 +6,7 @@ use SilverStripe\Dev\SapphireTest; use SilverStripe\Dev\TestOnly; use SilverStripe\ORM\Tests\MySQLiConnectorTest\MySQLiConnector; use SilverStripe\ORM\DB; +use SilverStripe\Tests\ORM\Utf8\Utf8TestHelper; /** * @requires extension mysqli @@ -31,6 +32,10 @@ class MySQLiConnectorTest extends SapphireTest implements TestOnly $cset = $connection->get_charset(); + // Note: we do not need to update the utf charset here because mysqli with newer + // version of mysql/mariadb still self-reports as 'utf8' rather than 'utf8mb3' + // This is unlike self::testConnectionCollationControl() + // And also unlike MySQLPDOConnectorTest::testConnectionCharsetControl() $this->assertEquals($charset, $cset->charset); $this->assertEquals($defaultCollation, $cset->collation); @@ -77,8 +82,9 @@ class MySQLiConnectorTest extends SapphireTest implements TestOnly $cset = $connection->query('show variables like "character_set_connection"')->fetch_array()[1]; $collation = $connection->query('show variables like "collation_connection"')->fetch_array()[1]; - $this->assertEquals($charset, $cset); - $this->assertEquals($customCollation, $collation); + $helper = new Utf8TestHelper(); + $this->assertEquals($helper->getUpdatedUtfCharsetForCurrentDB($charset), $cset); + $this->assertEquals($helper->getUpdatedUtfCollationForCurrentDB($customCollation), $collation); $connection->close(); unset($cset, $connection, $connector, $config); diff --git a/tests/php/ORM/Utf8/Utf8TestHelper.php b/tests/php/ORM/Utf8/Utf8TestHelper.php new file mode 100644 index 000000000..57379b0e8 --- /dev/null +++ b/tests/php/ORM/Utf8/Utf8TestHelper.php @@ -0,0 +1,69 @@ +isMySqlGte80() || $this->isMariaDBGte106() ? 'utf8mb3' : 'utf8'; + } + + public function getUpdatedUtfCollationForCurrentDB(string $collation): string + { + if ($collation === 'utf8_general_ci') { + return $this->isMariaDBGte106() ? 'utf8mb3_general_ci' : 'utf8_general_ci'; + } + if ($collation === 'utf8_unicode_520_ci') { + return $this->isMariaDBGte106() ? 'utf8mb3_unicode_520_ci' : 'utf8_unicode_520_ci'; + } + return $collation; + } + + /** + * MySQL has used utf8 as an alias for utf8mb3 + * Beginning with MySQL 8.0.28, utf8mb3 is used + * https://dev.mysql.com/doc/refman/8.0/en/charset-unicode-utf8mb3.html + */ + private function isMySqlGte80(): bool + { + // Example MySQL version: 8.0.29 + if (preg_match('#^([0-9]+)\.[0-9]+\.[0-9]+$#', $this->getDBVersion(), $m)) { + return (int) $m[1] >= 8; + } + return false; + } + + /** + * Until MariaDB 10.5, utf8mb3 was an alias for utf8. + * From MariaDB 10.6, utf8 is by default an alias for utf8mb3 + * https://mariadb.com/kb/en/unicode/ + */ + private function isMariaDBGte106(): bool + { + // Example mariadb version: 5.5.5-10.6.8-mariadb-1:10.6.8+maria~focal + if (preg_match('#([0-9]+)\.([0-9]+)\.[0-9]+-mariadb#', $this->getDBVersion(), $m)) { + return (int) $m[1] >= 11 || ((int) $m[1] >= 10 && (int) $m[2] >= 6); + } + return false; + } + + private function getDBVersion(): string + { + if (is_null($this->dbVersion)) { + $this->dbVersion = strtolower(DB::get_conn()->getVersion()); + } + return $this->dbVersion; + } +} From 5eb8d3e25fad01507b9aa995174cf4d41b6f78f8 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Fri, 22 Jul 2022 11:16:32 +1200 Subject: [PATCH 3/3] MNT Skip test in MySQL8 --- .github/workflows/ci.yml | 2 -- behat.yml | 34 ------------------- .../ORM/DataObjectSchemaGenerationTest.php | 20 +++++++++++ 3 files changed, 20 insertions(+), 36 deletions(-) delete mode 100644 behat.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d5bcaf3c7..6afb73b67 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,5 +14,3 @@ jobs: with: # Turn phpcoverage off because it causes a segfault phpcoverage_force_off: true - # There is a strange behat.yml file in framework that runs behat tests in the admin module - endtoend: false diff --git a/behat.yml b/behat.yml deleted file mode 100644 index f74288345..000000000 --- a/behat.yml +++ /dev/null @@ -1,34 +0,0 @@ -# Run framework behat tests with this command (installed with silverstripe/installer) -# Note that framework behat tests require CMS module -# ========================================================================= # -# vendor/bin/selenium-server-standalone -Dwebdriver.firefox.bin="/Applications/Firefox31.app/Contents/MacOS/firefox-bin" -# vendor/bin/serve --bootstrap-file vendor/silverstripe/framework/tests/behat/serve-bootstrap.php -# vendor/bin/behat @framework -# ========================================================================= # -default: - suites: - framework: - paths: - - "%paths.modules.admin%/tests/behat/features" - contexts: - - SilverStripe\Framework\Tests\Behaviour\FeatureContext - - SilverStripe\Framework\Tests\Behaviour\CmsFormsContext - - SilverStripe\Framework\Tests\Behaviour\CmsUiContext - - SilverStripe\BehatExtension\Context\BasicContext - - SilverStripe\BehatExtension\Context\EmailContext - - SilverStripe\BehatExtension\Context\LoginContext - - - SilverStripe\BehatExtension\Context\FixtureContext: - - "%paths.modules.admin%/tests/behat/features/files/" - - extensions: - SilverStripe\BehatExtension\MinkExtension: - default_session: facebook_web_driver - javascript_session: facebook_web_driver - facebook_web_driver: - browser: chrome - wd_host: "http://127.0.0.1:9515" #chromedriver port - - SilverStripe\BehatExtension\Extension: - screenshot_path: "%paths.base%/artifacts/screenshots" - bootstrap_file: "tests/behat/serve-bootstrap.php" diff --git a/tests/php/ORM/DataObjectSchemaGenerationTest.php b/tests/php/ORM/DataObjectSchemaGenerationTest.php index 5822f0c76..ec40ca059 100644 --- a/tests/php/ORM/DataObjectSchemaGenerationTest.php +++ b/tests/php/ORM/DataObjectSchemaGenerationTest.php @@ -8,6 +8,7 @@ use SilverStripe\ORM\DB; use SilverStripe\ORM\FieldType\DBEnum; use SilverStripe\ORM\DataObject; use SilverStripe\Dev\SapphireTest; +use SilverStripe\ORM\Connect\MySQLiConnector; use SilverStripe\ORM\Tests\DataObjectSchemaGenerationTest\SortedObject; use SilverStripe\ORM\Tests\DataObjectSchemaGenerationTest\TestIndexObject; use SilverStripe\ORM\Tests\DataObjectSchemaGenerationTest\TestObject; @@ -67,11 +68,26 @@ class DataObjectSchemaGenerationTest extends SapphireTest ); } + private function isMySQL8(): bool + { + $connector = DB::get_conn()->getConnector(); + if ($connector instanceof MySQLiConnector && + preg_match('#^8\.#', $connector->getVersion()) + ) { + return true; + } + return false; + } + /** * Check that once a schema has been generated, then it doesn't need any more updating */ public function testFieldsDontRerequestChanges() { + // TODO: remove the MySQL8 skip when `int(11)` is no longer the default field type for integers and has been replaced with `int` + if ($this->isMySQL8()) { + $this->markTestSkipped(); + } $schema = DB::get_schema(); $test = $this; DB::quiet(); @@ -126,6 +142,10 @@ class DataObjectSchemaGenerationTest extends SapphireTest */ public function testIndexesDontRerequestChanges() { + // TODO: remove the MySQL8 skip when `int(11)` is no longer the default field type for integers and has been replaced with `int` + if ($this->isMySQL8()) { + $this->markTestSkipped(); + } $schema = DB::get_schema(); $test = $this; DB::quiet();