Skip to content
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

Merged
merged 18 commits into from
Jul 9, 2016
Merged

Support 'trunk' and 'nightly' version arguments for wp core download. #3127

merged 18 commits into from
Jul 9, 2016

Conversation

stephenharris
Copy link

@stephenharris stephenharris commented Jul 8, 2016

Fixes #3113

  • 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.

- 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.
@stephenharris
Copy link
Author

I'll follow up with some Behat tests.

Documentation tells me PharData supports zip files too. But it just produced garbled file contents (filenames and directory structure was intact). I haven't explored the potential of using command line tools as is currently used if available for extracting tar files.

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 (tar,PharData,ZipArchive etc) to a factory class which gives us back a instance of class fulfilling a common interface - so the command doesn't know (or care) what tool is being used to extract and move the download.

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.

@danielbachhuber
Copy link
Member

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.

Makes sense.

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 (tar,PharData,ZipArchive etc) to a factory class which gives us back a instance of class fulfilling a common interface - so the command doesn't know (or care) what tool is being used to extract and move the download.

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' );
Copy link
Member

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?

Copy link
Member

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stephenharris
Copy link
Author

@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.

@stephenharris
Copy link
Author

@stephenharris
Copy link
Author

@danielbachhuber ignore the above, I see the error in test now. I misread the error output.

@danielbachhuber
Copy link
Member

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'?

Is it somehow running wp core download twice, and it's the second instance that's failing?

@@ -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');
Copy link
Member

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?

Copy link
Author

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?

Copy link
Member

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.

Copy link
Author

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.

Copy link
Member

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.

@stephenharris
Copy link
Author

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.

@danielbachhuber
Copy link
Member

The test was running download twice (as was intended), but I thought the error was occurring for the first command not the second.

Heh, good find.

@@ -95,3 +95,87 @@ Feature: Download WordPress
"""
File removed: wp-content
"""

Scenario: Installing trunk
Copy link
Member

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?

Copy link
Author

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.

Copy link
Member

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.

@danielbachhuber
Copy link
Member

@stephenharris Left some comments on small things to be fixed up.

@stephenharris
Copy link
Author

@danielbachhuber implemented those changes. For the extension check I had to use regular expressions as pathinfo() gives (correctly) the extension of file.tar.gz as .gz.


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
Copy link
Member

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 :(

Copy link
Author

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.

@danielbachhuber danielbachhuber added this to the 0.24.0 milestone Jul 8, 2016
@danielbachhuber
Copy link
Member

@stephenharris Sorry, couple more things.

Also, could we have some improved description for the --version=<version> parameter in the docs? Specifically, mention that you can include a version number or nightly.

@stephenharris
Copy link
Author

@danielbachhuber The documentation for --version is behaving weirdly for me. It's breaking before the 'latest' and 'nightly' (see https://cloudup.com/c6pMLEZScve). Are quotation marks not allowed there?

@danielbachhuber
Copy link
Member

The documentation for --version is behaving weirdly for me. It's breaking before the 'latest' and 'nightly' (see https://cloudup.com/c6pMLEZScve). Are quotation marks not allowed there?

No, WP-CLI is trying to be smart by word-wrapping. You can just ignore it for now.

@danielbachhuber
Copy link
Member

🚢 Good work with this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants