Skip to content

Implement wp cli update#1535

Merged
danielbachhuber merged 13 commits intowp-cli:masterfrom
nyordanov:issue-522
Dec 12, 2014
Merged

Implement wp cli update#1535
danielbachhuber merged 13 commits intowp-cli:masterfrom
nyordanov:issue-522

Conversation

@nyordanov
Copy link
Contributor

This implements wp cli self-update, originally proposed in #522

I've reused the code for getting the url of the latest phar from wp cli check-update. A new private function get_updates( $assoc_args ) is introduced which is used by both check_update and self_update.

An update is performed if all of these criteria are met:

  • WP-CLI is used as a Phar
  • The current Phar file is writable
  • There is an available update
  • The downloaded Phar can be executed (that is, the exit code of php /path/to/downloaded/update --version should be 0)
  • The permissions of the downloaded file can be changed so that they match the permissions of the current Phar

I haven't added any tests. However, in order to create a test for this command, it should be possible to set WP_CLI_VERSION at build time.

A manual test can be performed by decreasing WP_CLI_VERSION in php/wp-cli.php and running this in a shell:

php -dphar.readonly=0 ./utils/make-phar.php /tmp/wp-cli.phar &&\
chmod +x /tmp/wp-cli.phar &&\
/tmp/wp-cli.phar cli self-update --yes &&\
/tmp/wp-cli.phar --version

@nyordanov nyordanov changed the title Implement #522 Implement wp cli self-update Dec 2, 2014
@nyordanov
Copy link
Contributor Author

Related: #680, #1199, #1390

Also, one of the jobs of the Travis build fails because the WP Importer plugin is not installed. I don't see how this could have been caused by the changes introduced in this PR.

Copy link
Member

Choose a reason for hiding this comment

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

Let's call this update, instead of self-update, to follow the established pattern for wp core and wp plugin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure.

@danielbachhuber
Copy link
Member

However, in order to create a test for this command, it should be possible to set WP_CLI_VERSION at build time.

What do you think is the best way to do this?

Also, one of the jobs of the Travis build fails because the WP Importer plugin is not installed.

Yeah, that's #1493

Changes to WP_CLI::error():
- can now take an array of lines, which will be printed in a red box, similar to Composer's exceptions
- new boolean $exit param - if false will not exit(1); defaults to old behaviour

Both loggers get a new error_box( $message_lines ) function

`wp cli self-update` is now `wp cli update`
@nyordanov
Copy link
Contributor Author

What do you think is the best way to do this?

We could have make-phar.php take a parameter: --version=[patch|minor|major|x.y.z]. patch will be the default value. This will modify the define( 'WP_CLI_VERSION', '0.17.1' ); line - this way people who don't use the Phar release will still have version information.

Do you want me to open another PR for #680?

I'll create an issue with a task list for everything update-related.

nyordanov added a commit to nyordanov/wp-cli that referenced this pull request Dec 3, 2014
- Implements wp-cli#680
- It is now possibile to set the version at build time (required for wp-cli#1535): --version=x.y.z
- Keywords for incrementing the version number by one: --version=[patch|minor|major]
- When no arguments are passed, the old behaviour is preverved
- utils/update-phar takes an option argument: `update-phar [same|patch|minor|major|x.y.z]`
Copy link
Member

Choose a reason for hiding this comment

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

I don't want to make WP_CLI::error() a magical method that does different things based on what you pass to it. Let's keep the scope of the pull request to wp cli update

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would you rather have a WP_CLI::error_box() or remove this entirely?

Also, what the $exit param?

Copy link
Member

Choose a reason for hiding this comment

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

Would you rather have a WP_CLI::error_box() or remove this entirely?

I'm open to it. _box() doesn't strike me as very semantic though. How about error_multi_line()?

Also, what the $exit param?

I'd prefer not to change the behavior unless there's a good reason to do so. The one use you have in this pull request doesn't justify, in my opinion.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

WP_CLI::error_multi_line() is now in nyordanov@6fd93c2

@danielbachhuber
Copy link
Member

However, in order to create a test for this command, it should be possible to set WP_CLI_VERSION at build time.

Given that each build runs the full suite of tests, I'm not sure how I feel about setting WP_CLI_VERSION to an "incorrect" value at the beginning of the build just for the purposes of one test.

Instead, we probably should set it at runtime. How do you feel about this?

I like #1539 generally though, so I think we can keep that once you address the modifications I've proposed.

@nyordanov
Copy link
Contributor Author

[...] setting WP_CLI_VERSION to an "incorrect" value at the beginning of the build just for the purposes of one test.

Such test will need an entirely different build anyway. After performing wp cli update the Phar will be useless as it will be overwritten by the latest stable release.

Instead, we probably should set it at runtime. How do you feel about this?

How can we expose this to the tests but not to regular users?

@danielbachhuber
Copy link
Member

Such test will need an entirely different build anyway.

Good point. Ignore my runtime suggestion then. I think we'll just need to have a bespoke Travis build for testing the update process, outside of the standard matrix.

- change description of --patch and --minor
- introduce --ignore-patch and --ignore-minor
features/cli.feature:
 - wp cli check-updates should return at least one update after version 0.0.0
 - wp cli update should perform a successful update of version 0.0.0
- make-phar.php gains a new optional flag --store-version which defaults to false.
  The script will change the contents of VERSION only if this is true.
  This is false when building temporary Phars with custom versions for tests.

- Because of that there is a new function set_file_contents() in make-phar.php
  This is similar to add_file(), but the contents of the new file are passed
  as an argument, instead of reading them via file_get_contents()

- Behat test for building a temporary Phar with a fake version
  Also ensure that VERSION is not modified
@nyordanov
Copy link
Contributor Author

I've added a new features/cli.feature file which tests the following:

  • Building a temporary Phar with a custom version shouldn't change the contents of VERSION
  • There should be some updates after version 0.0.0 (output of wp cli check updates should contain package_url when the Phar's version is set as 0.0.0)
  • Successful wp cli update for a Phar with a version set as 0.0.0

Also:

  • A new --store-version flag for utils/make-phar.php - if missing the contents of VERSION will not be changed.
  • New function set_file_contents() in utils/make-phar.php which acts as add_file(), but instead of using file_get_contents() expects the contents to be passed as a third argument. I can merge it with add_file() if that's preferred.
  • New Given...:
    • a new Phar with version "..." - stores the path to the Phar in {PHAR_PATH}
    • save the ... file ... as ... (based on save (STDOUT|STDERR))
  • New Behat variable - $this->variables['SRC_DIR'] = realpath( __DIR__ . '/../..' );

Copy link
Member

Choose a reason for hiding this comment

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

s/list/perform

Also, I think we can skip --ignore-* by using our magic --no- prefix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@danielbachhuber
Copy link
Member

This is looking solid. A few minor comments to address. I'll set aside some time next week to check the branch out and test throughly.

@nyordanov
Copy link
Contributor Author

I'll set aside some time next week to check the branch out and test throughly.

Sure. I'll do #1011 when this is merged.

Edit: Sorry, didn't see #1547

@szepeviktor
Copy link
Contributor

This is my very-short and solid install/update script:

WPCLI_URL="https://raw.github.com/wp-cli/builds/gh-pages/phar/wp-cli.phar"
wget -O /usr/local/bin/wp "$WPCLI_URL" && chmod +x /usr/local/bin/wp
WPCLI_COMPLETION_URL="https://github.com/wp-cli/wp-cli/raw/master/utils/wp-completion.bash"
wget -O- "$WPCLI_COMPLETION_URL"|sed 's/wp cli completions/wp --allow-root cli completions/' > /etc/bash_completion.d/wp-cli

https://github.com/szepeviktor/debian-server-tools/blob/master/debian-setup.sh#L342-L348

Maybe you shouldn't update at the time of a new release. Wait for the bugs!

@danielbachhuber danielbachhuber added this to the next milestone Dec 12, 2014
@danielbachhuber
Copy link
Member

👍 Thanks for your work on this!

danielbachhuber added a commit that referenced this pull request Dec 12, 2014
Implement `wp cli self-update`
@danielbachhuber danielbachhuber merged commit 889ee09 into wp-cli:master Dec 12, 2014
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of adding ! $assoc_args['patch']?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Takes care of --no-patch. This will behave in the exact same way as --minor until 1.0.0 is released.

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you.

@nyordanov nyordanov deleted the issue-522 branch December 13, 2014 19:50
@danielbachhuber danielbachhuber changed the title Implement wp cli self-update Implement wp cli update Jan 14, 2015
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.

3 participants