From 247d6b9e7e4d3779ed75cd04262bf9c39ae1723c Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 4 May 2022 11:42:42 +0000 Subject: [PATCH] Build/Test Tools: Pass GitHub Actions environment variables to the Docker container. This ensures that `WP_UnitTestCase::skipOnAutomatedBranches()` has access to the `GITHUB_REF` and `GITHUB_EVENT_NAME` variables, so that some tests can be skipped when appropriate. Additionally, account for renaming the `master` branch to `trunk` in November 2021. Follow-up to [40241], [46999], [49264], [49267], [51868]. Merges [53349] to the 6.0 branch. Fixes #55668. git-svn-id: https://develop.svn.wordpress.org/branches/6.0@53350 602fd350-edb4-49c9-b593-d223f7449a82 --- docker-compose.yml | 2 ++ tests/phpunit/includes/abstract-testcase.php | 10 +++++----- tests/phpunit/tests/basic.php | 4 ++-- tests/phpunit/tests/external-http/basic.php | 6 +++--- tests/phpunit/tests/theme.php | 2 +- 5 files changed, 13 insertions(+), 11 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 7fe9b524c7..060fd130e9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -41,6 +41,8 @@ services: - LOCAL_PHP_MEMCACHED=${LOCAL_PHP_MEMCACHED-false} - PHP_FPM_UID=${PHP_FPM_UID-1000} - PHP_FPM_GID=${PHP_FPM_GID-1000} + - GITHUB_REF=${GITHUB_REF-false} + - GITHUB_EVENT_NAME=${GITHUB_EVENT_NAME-false} volumes: - ./tools/local-env/php-config.ini:/usr/local/etc/php/conf.d/php-config.ini diff --git a/tests/phpunit/includes/abstract-testcase.php b/tests/phpunit/includes/abstract-testcase.php index 765b514aa9..c0dc30b189 100644 --- a/tests/phpunit/includes/abstract-testcase.php +++ b/tests/phpunit/includes/abstract-testcase.php @@ -202,20 +202,20 @@ abstract class WP_UnitTestCase_Base extends PHPUnit_Adapter_TestCase { /** * Allows tests to be skipped on some automated runs. * - * For test runs on GitHub Actions for something other than trunk/master, - * we want to skip tests that only need to run for master. + * For test runs on GitHub Actions for something other than trunk, + * we want to skip tests that only need to run for trunk. */ public function skipOnAutomatedBranches() { // https://docs.github.com/en/free-pro-team@latest/actions/reference/environment-variables#default-environment-variables $github_event_name = getenv( 'GITHUB_EVENT_NAME' ); $github_ref = getenv( 'GITHUB_REF' ); - if ( $github_event_name && 'false' !== $github_event_name ) { + if ( $github_event_name ) { // We're on GitHub Actions. $skipped = array( 'pull_request', 'pull_request_target' ); - if ( in_array( $github_event_name, $skipped, true ) || 'refs/heads/master' !== $github_ref ) { - $this->markTestSkipped( 'For automated test runs, this test is only run on trunk/master' ); + if ( in_array( $github_event_name, $skipped, true ) || 'refs/heads/trunk' !== $github_ref ) { + $this->markTestSkipped( 'For automated test runs, this test is only run on trunk' ); } } } diff --git a/tests/phpunit/tests/basic.php b/tests/phpunit/tests/basic.php index 5ffd6b2470..e8df915d07 100644 --- a/tests/phpunit/tests/basic.php +++ b/tests/phpunit/tests/basic.php @@ -8,7 +8,7 @@ class Tests_Basic extends WP_UnitTestCase { public function test_license() { - // This test is designed to only run on trunk/master. + // This test is designed to only run on trunk. $this->skipOnAutomatedBranches(); $license = file_get_contents( ABSPATH . 'license.txt' ); @@ -18,7 +18,7 @@ class Tests_Basic extends WP_UnitTestCase { } public function test_security_md() { - // This test is designed to only run on trunk/master. + // This test is designed to only run on trunk. $this->skipOnAutomatedBranches(); $security = file_get_contents( dirname( ABSPATH ) . '/SECURITY.md' ); diff --git a/tests/phpunit/tests/external-http/basic.php b/tests/phpunit/tests/external-http/basic.php index b160e2b56f..16bef21847 100644 --- a/tests/phpunit/tests/external-http/basic.php +++ b/tests/phpunit/tests/external-http/basic.php @@ -10,7 +10,7 @@ class Tests_External_HTTP_Basic extends WP_UnitTestCase { * @covers ::wp_remote_retrieve_body */ public function test_readme_php_version() { - // This test is designed to only run on trunk/master. + // This test is designed to only run on trunk. $this->skipOnAutomatedBranches(); $readme = file_get_contents( ABSPATH . 'readme.html' ); @@ -31,7 +31,7 @@ class Tests_External_HTTP_Basic extends WP_UnitTestCase { * @covers ::wp_remote_retrieve_body */ public function test_readme_mysql_version() { - // This test is designed to only run on trunk/master. + // This test is designed to only run on trunk. $this->skipOnAutomatedBranches(); $readme = file_get_contents( ABSPATH . 'readme.html' ); @@ -63,7 +63,7 @@ class Tests_External_HTTP_Basic extends WP_UnitTestCase { * @covers ::wp_remote_retrieve_body */ public function test_readme_mariadb_version() { - // This test is designed to only run on trunk/master. + // This test is designed to only run on trunk. $this->skipOnAutomatedBranches(); $readme = file_get_contents( ABSPATH . 'readme.html' ); diff --git a/tests/phpunit/tests/theme.php b/tests/phpunit/tests/theme.php index e16dd4c900..14eccdf6da 100644 --- a/tests/phpunit/tests/theme.php +++ b/tests/phpunit/tests/theme.php @@ -213,7 +213,7 @@ class Tests_Theme extends WP_UnitTestCase { * @ticket 48566 */ public function test_year_in_readme() { - // This test is designed to only run on trunk/master. + // This test is designed to only run on trunk. $this->skipOnAutomatedBranches(); foreach ( $this->default_themes as $theme ) {