-
Notifications
You must be signed in to change notification settings - Fork 975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support 'trunk' and 'nightly' version arguments for wp core download. #3127
Support 'trunk' and 'nightly' version arguments for wp core download. #3127
Conversation
- Modifies Core_Command::get_download_url() to interpret 'trunk' and 'nightly' versions - Core_Command::get_download_url() now conforms to WordPress coding standards - Adds support for downloading and extracting .zip files as nightly builds are own available in zip format. - wp core download --version=trunk is only supported if ZipArchive is present.
I'll follow up with some Behat tests. Documentation tells me md5 checksums are not available for trunk downloads so I just display a warning. You get a similar error when trying to overwrite an existing download. One future change, which would be nice but isn't within the scope of this issue would be to move the logic for determining which tool to use ( That would allow additional tools to be added easily, and would tidy the logic of extracting to a directory, and then moving the contents of the wordpress directory to the desired location out of the command class. |
Makes sense.
I agree. I think code abstraction could actually be a general theme for the following release (v0.25.0). Some of the internals have gotten quite messy. |
@@ -235,6 +259,29 @@ private static function _extract( $tarball, $dest ) { | |||
self::_rmdir( dirname( $tempdir ) ); | |||
} | |||
|
|||
private static function _extract_zip( $zipfile, $dest ) { | |||
if ( ! class_exists( 'ZipArchive' ) ) { | |||
throw new \Exception( 'Extracting a zip file requires PharData' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This exception isn't quite right. Where is it caught?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should WP_CLI::error()
if ZipArchive
isn't find. The check should actually happen much earlier, to make sure we don't leave a partially downloaded file around.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@danielbachhuber It's caught here: https://github.com/stephenharris/wp-cli/blob/9eea025df9b69eab496b6c2a5dc3207a05702f4a/php/commands/core.php#L216
R.e. the early check, makes sense
@danielbachhuber Any idea why that one test is failing? It failed for me locally too, but it appears to be false positive. I don't understand why a WordPress version already exists if I have a 'clean directory'? Oddly, it does seem to be specifically trunk. I ran it locally using nightly and it worked. |
Link to test: 9ec1d14#diff-5106025468b362f7cee39e2f2349ef80R99 |
@danielbachhuber ignore the above, I see the error in test now. I misread the error output. |
Is it somehow running |
@@ -134,7 +134,8 @@ public function download( $args, $assoc_args ) { | |||
$locale = \WP_CLI\Utils\get_flag_value( $assoc_args, 'locale', 'en_US' ); | |||
|
|||
if ( isset( $assoc_args['version'] ) ) { | |||
$version = $assoc_args['version']; | |||
$version = strtolower( $assoc_args['version'] ); | |||
$version = ( 'nightly' === $version ? 'trunk' : $version ); | |||
$download_url = $this->get_download_url($version, $locale, 'tar.gz'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When version=trunk
, we're passing tar.gz
as a file type and getting zip
in return. Will that cause bugs later on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potentially yes. What would be the best way of handling this? We should ask for what we actually want. But what should happen if we ask for a 'tar.gz' of the nightly build - an exception?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Potentially yes. What would be the best way of handling this? We should ask for what we actually want.
Given it's a private method, so we don't need to worry about backwards compat concerns, could we just remove the third argument and make sure the calling function handles the archive file correctly, regardless of type?
But what should happen if we ask for a 'tar.gz' of the nightly build - an exception?
Generally, we aren't using exceptions within WP-CLI. Calling WP_CLI::error()
is a better way of handling errors where WP-CLI doesn't know how to proceed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given it's a private method, so we don't need to worry about backwards compat concerns, could we just remove the third argument and make sure the calling function handles the archive file correctly, regardless of type?
That would be fine for the download command - but the update command passes responsibility to WordPress' Core_Upgrader
, which I believe only expects a zip
.
So I think we should either note in the docbloc that get_download_url()
always returns a zip for trunk version or call WP_CLI::error()
. The second option doesn't feel necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I think we should either note in the docbloc that get_download_url() always returns a zip for trunk version or call WP_CLI::error(). The second option doesn't feel necessary.
Ok. Just to make sure the execution path is accommodated for, let's call WP_CLI::error()
when tar.gz
is provided as a version for nightly.
The test was running download twice (as was intended), but I thought the error was occurring for the first command not the second. Fixed with 9eea025. |
Heh, good find. |
@@ -95,3 +95,87 @@ Feature: Download WordPress | |||
""" | |||
File removed: wp-content | |||
""" | |||
|
|||
Scenario: Installing trunk |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test case for a non-US locale too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the expected behaviour here? Currently it just ignores the locale setting as they aren't any language specific nightly builds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend erring if a non-en_US locale is provided. If someone is providing a locale, then they should receive an error that the nightly isn't provided in the locale, not have it unexpectedly work and download the wrong file.
@stephenharris Left some comments on small things to be fixed up. |
… a zip file as tarballs are not available.
@danielbachhuber implemented those changes. For the extension check I had to use regular expressions as |
|
||
When I run `wp core download --version=nightly` | ||
Then the wp-settings.php file should exist | ||
And the {SUITE_CACHE_DIR}/core/wordpress-nightly-en_US.zip file should exist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, given the cache expiry is set to 6 months, we probably shouldn't be caching the nightly build. Sorry I missed that before :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point, missed that.
@stephenharris Sorry, couple more things. Also, could we have some improved description for the |
@danielbachhuber The documentation for |
No, WP-CLI is trying to be smart by word-wrapping. You can just ignore it for now. |
🚢 Good work with this! |
Fixes #3113