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

Blueprints: wp-cli step #1017

Merged
merged 3 commits into from
Feb 9, 2024
Merged

Blueprints: wp-cli step #1017

merged 3 commits into from
Feb 9, 2024

Conversation

adamziel
Copy link
Collaborator

@adamziel adamziel commented Feb 8, 2024

Adds a new step to the blueprints that allows to run WP-CLI commands.

Example:

{
	"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:

{
    "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 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.
  • 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, and confirm that a new post is created in the WordPress admin.

CC @dmsnell @bgrgicak @sejas @eliot-akira

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
`choice and load the kitchen-sink PHP extensions bundle to prevent the WP-CLI step from failing. `
);
}
blueprint.steps?.splice(wpCliStepIndex, 0, {
Copy link
Collaborator Author

@adamziel adamziel Feb 8, 2024

Choose a reason for hiding this comment

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

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().

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The step works on the web. Let's figure out node.js in a follow-up PR.

Copy link
Collaborator

@bgrgicak bgrgicak left a comment

Choose a reason for hiding this comment

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

Great work on getting this out so fast!

@adamziel adamziel merged commit 1d25d6f into trunk Feb 9, 2024
5 checks passed
@adamziel adamziel deleted the wp-cli-step branch February 9, 2024 13:26
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