Blueprints: wp-cli step - #1017
Merged
Merged
Conversation
Adds a new step to the blueprints that allows to run WP-CLI commands.
Example:
```ts
{
"landingPage": "/wp-admin/post.php",
"login": true,
"steps": [
{
"step": "wp-cli",
"command": "wp post create --post_title='Test post' --post_excerpt='Some content' --no-color"
}
]
}
```
The command may also be an array of strings to ease dealing with quotes:
```ts
{
"landingPage": "/wp-admin/post.php",
"login": true,
"steps": [
{
"step": "wp-cli",
"command": ["wp", "post", "create", "--post_title=Test post", "--post_excerpt=Some content", "--no-color"]
}
]
}
```
## Trade-offs
* WP-CLI requires ~7MB of additional downloads: 1.4MB for the compressed WP-CLI.phar, and 5.6MB for the kitchen-sink
PHP extensions bundle.
## Implementation
* Whenever the Blueprints compiler finds a `wp-cli` step, it:
* Downloads the wp-cli.phar file
* Forces the `kitchen-sink` PHP extensions bundle as WP-CLI requires mbstring and iconv
* `wp-cli.phar` is shipped at playground.wordpress.net. Downloading the official release from
raw.githubusercontent.com transfers 7MB, while downloading the pre-compressed version from
playground.wordpress.net only transfers 1.4MB.
* playground.wordpress.net now always sets the `PHP_SAPI` constant to `cli` to ensure this check
in WP-CLI passes: https://github.com/wp-cli/wp-cli-bundle/blob/970d0d4c22d4a89ca890def26ec82e559625abc6/php/boot-phar.php#L3-L10
## Future work
* Minify wp-cli.phar to reduce its size even further. We can remove redundant whitespaces and
comments, remove the JavaScript parser library that is unlikely to be useful in Playground,
remove parts of the Composer library, and perhaps more. cc @schlessera @swissspidy @danielbachhuber
* Move the hardcoded WP-CLI-related parts of the Blueprint `compile()` function into a separate, modular
function associated with the `wp-cli` step.
## Testing instructions
* Confirm the CI checks pass
* Run the local dev server, [click here](http://localhost:5400/website-server/#{%20%22landingPage%22:%20%22/wp-admin/post.php%22,%20%22login%22:%20true,%20%22steps%22:%20[%20{%20%22step%22:%20%22wp-cli%22,%20%22command%22:%20[%22wp%22,%20%22post%22,%20%22create%22,%20%22--post_title=Test%20post%22,%20%22--post_excerpt=Some%20content%22,%20%22--no-color%22]%20}%20]%20}),
and confirm that a new post is created in the WordPress admin.
CC @dmsnell @bgrgicak @sejas @eliot-akira
adamziel
commented
Feb 8, 2024
| `choice and load the kitchen-sink PHP extensions bundle to prevent the WP-CLI step from failing. ` | ||
| ); | ||
| } | ||
| blueprint.steps?.splice(wpCliStepIndex, 0, { |
Collaborator
Author
There was a problem hiding this comment.
Let's only trigger this request if wp-cli.phar doesn't yet exist in VFS, or else running this Blueprint step in wp-now will always trigger fetch().
Collaborator
Author
There was a problem hiding this comment.
The step works on the web. Let's figure out node.js in a follow-up PR.
bgrgicak
approved these changes
Feb 9, 2024
bgrgicak
left a comment
Collaborator
There was a problem hiding this comment.
Great work on getting this out so fast!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a new step to the blueprints that allows to run WP-CLI commands.
Example:
The command may also be an array of strings to ease dealing with quotes:
Trade-offs
Implementation
wp-clistep, it:kitchen-sinkPHP extensions bundle as WP-CLI requires mbstring and iconvwp-cli.pharis shipped from playground.wordpress.net. Downloading the official release from raw.githubusercontent.com transfers 7MB, while downloading the pre-compressed version from playground.wordpress.net only transfers 1.4MB.PHP_SAPIconstant toclito ensure this check in WP-CLI passes: https://github.com/wp-cli/wp-cli-bundle/blob/970d0d4c22d4a89ca890def26ec82e559625abc6/php/boot-phar.php#L3-L10Future work
compile()function into a separate, modular function associated with thewp-clistep.Testing instructions
CC @dmsnell @bgrgicak @sejas @eliot-akira