Skip to content

Commit

Permalink
Bump WP Core version to 6.5 and 6.4.3 (#155)
Browse files Browse the repository at this point in the history
* Bump WP Core version to 6.5 and 6.4.3

* 6.5.3 doesn't exist

* add a new step that checks the latest wp version

* the current version should not be the latest

* use world_proc since wp isn't actually installed at behat runtime

* stdout isn't actually a method

* simplify how we're invoking proc

* get stdout from the returned values

* an array should be returned actually

* run the proc?

* run is a method, not a property

* bump checkout version

* remove the thing that's not working and replace with a long bash thing

* remove our bash thing

* store the state of wp version

* add an exception to the stdout check

* missing semicolon

* fix the THEN where it should actually execute

* maybe force a different kind of end?

* remove the exception

* return after the check

* remove the check and just return

* return after we set the wp version

* that's not how check-updates works, instead return the latest version

* move the version check to a utility function

* tabs to spaces

* add error handling if the version-check api is unavailable for some reason

---------

Co-authored-by: Pantheon Automation <bot@getpantheon.com>
Co-authored-by: Chris Reynolds <chris@jazzsequence.com>
  • Loading branch information
3 people authored Apr 3, 2024
1 parent b5919f6 commit e120b4f
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand Down
24 changes: 24 additions & 0 deletions features/bootstrap/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
7 changes: 4 additions & 3 deletions features/general.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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:
Expand All @@ -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`
Expand Down
21 changes: 20 additions & 1 deletion features/steps/given.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -154,4 +156,21 @@ function($world) {

file_put_contents( $wp_config_path, $wp_config_code );
}
);
);

$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;
});
5 changes: 4 additions & 1 deletion features/steps/then.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down Expand Up @@ -189,4 +193,3 @@ function ( $world, $path, $type, $action, $expected = null ) {
}
}
);

0 comments on commit e120b4f

Please sign in to comment.