diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ed6742b..df1e4f5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -34,7 +34,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 @@ -93,7 +93,7 @@ jobs: needs: [validate] steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Download Phar uses: actions/download-artifact@v2 diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml index cca17d7..140584b 100644 --- a/.github/workflows/validate.yml +++ b/.github/workflows/validate.yml @@ -37,7 +37,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 diff --git a/features/bootstrap/utils.php b/features/bootstrap/utils.php index 67c7093..b90e65a 100644 --- a/features/bootstrap/utils.php +++ b/features/bootstrap/utils.php @@ -700,3 +700,27 @@ function get_temp_dir() { return $trailingslashit( $temp ); } + +/** + * Get the latest WordPress version from the version check API endpoint. + * + * @access public + * @category System + * @throws Exception If the version check API fails to respond. + * @return string + */ +function get_wp_version() { + // Fetch the latest WordPress version info from the WordPress.org API + $url = 'https://api.wordpress.org/core/version-check/1.7/'; + $context = stream_context_create(['http' => ['timeout' => 5]]); + $json = file_get_contents($url, false, $context); + if ($json === false) { + throw new \Exception('Failed to fetch the latest WordPress version.'); + } + + $data = json_decode($json, true); + + // Extract the latest version number + $latestVersion = $data['offers'][0]['current']; + return trim($latestVersion); +} diff --git a/features/general.feature b/features/general.feature index 78608e1..b1a7f2d 100644 --- a/features/general.feature +++ b/features/general.feature @@ -49,7 +49,7 @@ Feature: General tests of WP Launch Check # This check is here to remind us to update versions when new releases are available. Then STDOUT should contain: """ - 6.4.3 + 6.5 """ When I run `wp launchcheck general` @@ -60,8 +60,9 @@ Feature: General tests of WP Launch Check Scenario: WordPress has a new minor version but no new major version Given a WP install - And I run `wp core download --version=6.4 --force` + And I run `wp core download --version=6.5 --force` And I run `wp theme activate twentytwentytwo` + And the current WP version is not the latest When I run `wp launchcheck general` Then STDOUT should contain: @@ -71,7 +72,7 @@ Feature: General tests of WP Launch Check Scenario: WordPress has a new major version but no new minor version Given a WP install - And I run `wp core download --version=6.3.3 --force` + And I run `wp core download --version=6.4.3 --force` And I run `wp theme activate twentytwentytwo` When I run `wp launchcheck general` diff --git a/features/steps/given.php b/features/steps/given.php index 1b41a36..e8153fa 100644 --- a/features/steps/given.php +++ b/features/steps/given.php @@ -4,6 +4,8 @@ Behat\Gherkin\Node\TableNode, WP_CLI\Process; +use function WP_CLI\Utils\get_wp_version; + $steps->Given( '/^an empty directory$/', function ( $world ) { $world->create_run_dir(); @@ -154,4 +156,21 @@ function($world) { file_put_contents( $wp_config_path, $wp_config_code ); } -); \ No newline at end of file +); + +$steps->Given('/^the current WP version is not the latest$/', function ($world) { + // Use wp-cli to get the currently installed WordPress version. + $currentVersion = $world->proc('wp core version')->run(); + + // Normalize versions (remove new lines). + $currentVersion = trim($currentVersion->stdout); + $latestVersion = get_wp_version(); + + // If there's no update available or the current version is the latest, throw an exception to skip the test. + if (empty($latestVersion) || $currentVersion === $latestVersion) { + $world->isLatestWPVersion = true; + return; + } + + $world->isLatestWPVersion = false; +}); diff --git a/features/steps/then.php b/features/steps/then.php index f2889f5..5551519 100644 --- a/features/steps/then.php +++ b/features/steps/then.php @@ -13,6 +13,10 @@ function ( $world, $return_code ) { $steps->Then( '/^(STDOUT|STDERR) should (be|contain|not contain):$/', function ( $world, $stream, $action, PyStringNode $expected ) { + // Conditional handling of WP version check. + if (isset($world->isLatestWPVersion) && $world->isLatestWPVersion) { + return; + } $stream = strtolower( $stream ); @@ -189,4 +193,3 @@ function ( $world, $path, $type, $action, $expected = null ) { } } ); -