Skip to content
This repository was archived by the owner on May 30, 2025. It is now read-only.

Blueprints v2 all-PHP Runner #9

Merged
merged 197 commits into from
May 20, 2025
Merged

Blueprints v2 all-PHP Runner #9

merged 197 commits into from
May 20, 2025

Conversation

adamziel
Copy link
Contributor

@adamziel adamziel commented May 7, 2025

Blueprints v2 runner

Warning

This is an early alpha version. Proceed with caution!

This PR ships a reference implementation of a subset of the Blueprints version 2 spec. It consists of:

  • A CLI runner tool (bundled as .phar) for easy consumption
  • A PHP library that can be integrated in other PHP software

These tools are compatible with PHP 7.2+ on Mac, Linux, Windows and require no PHP extensions. Libraries for processing ZIP, HTTP, XML, HTML, and Git are included.

This huge PR also:

  • Downgrades the codebase to PHP 7.2
  • Gets the unit tests to run
  • Resolves a number of bugs in most components (HttpClient, Zip, Filesystem, ByteStream, and more)
  • Introduces an all-php TCP server for testing

Splitting it into atomic changes and documenting them could easily take a week. Therefore I apologize, but I am not going to do that. Let's treat it as the new initial commit and apply atomic changes from this point forward.

Remaining work

First and foremost: stabilize this runner with a large and meaningful suite of tests.

Other than that:

In this PR

  • Remove the buggy, experimental HTTP cache support from this PR

Independently of this PR

  • Consolidate and prioritize the @TODO comments in a way that can be discussed and tracked
  • A large set of unit tests for the HTTP client covering all sorts of use-cases
  • (nice to have) An actual, reliable HTTP cache implementation for faster execution
  • A unit test suite running the 100 most popular Blueprints

Out of scope until the baseline functionality works

Using it

Download blueprints.phar from the latest alpha release and follow the instructions there.

For running from source, use this command:

> php ./components/Blueprints/bin/blueprint.php
WordPress Blueprint Runner
Usage: php blueprint.php exec <blueprint> --site-url=<url> --site-path=<path> [options]

Positional arguments:
  blueprint            Path / URL / DataReference to the blueprint (required)

Options:
  -u, --site-url <value>           Public site URL (https://example.com)
      --site-path <value>          Target directory with WordPress install context) (required)
  -x, --execution-context <value>  Source directory with Blueprint context files
  -m, --mode <value>               Execution mode (create|apply) (default 'create')
  -d, --db-engine <value>          Database engine (mysql|sqlite) (default 'mysql')
      --db-host <value>            MySQL host (default 'localhost')
      --db-user <value>            MySQL user (default 'root')
      --db-pass <value>            MySQL password (default '')
      --db-name <value>            MySQL database (default 'wordpress')
  -p, --db-path <value>            SQLite file path (default 'wp.db')
      --dry-run                    Don’t change anything, just validate (default false)
  -h, --help                       Show full help (default false)
  -V, --version                    Show version (default false)

Examples:
  php blueprint.php exec my-blueprint.json --site-url https://mysite.test --site-path /var/www/mysite.com
  php blueprint.php exec my-blueprint.json --execution-context /var/www --site-url https://mysite.test --mode apply --site-path ./site

Here's an example of using it to create a new site (with a complex v1 Blueprint to showcase compatibility):

> php ./components/Blueprints/bin/blueprint.php exec https://github.com/wordpress/blueprints/blob/trunk/blueprints/stylish-press/blueprint.json --site-path=./newsite/ --site-url=http://127.0.0.1:4356 --db-engine=sqlite --mode create
Creating a new site
  Site URL:  http://127.0.0.1:4356
  Site path: /www/php-toolkit/untracked/newsite
  Blueprint: /www/php-toolkit/untracked/blueprint.json
[100%] Complete                                                                
✔ Blueprint successfully executed.
CleanShot.2025-05-12.at.21.17.02.mp4

The command above created a new WordPress site in a newsite directory. Here's what it did under the hood:

  • Validated Blueprint v1 and transpiled it to v2 schema
  • Reported live progress
  • Downloaded files in parallel
  • Imported content and media files
  • Ran code in subprocesses

With another Blueprint, you could also create new post types, source data directly from a git repo, and more.

Scripts

Bundle blueprints.phar

To build a single blueprints.phar executable, install box and run:

composer build-blueprints-phar
# Under the hood it runs:
#    box compile -c phar-box.json
# and recreates dist/blueprints.phar

Regenerate JSON Schema based on TypeScript types

This PR ships a copy of the Blueprints v2 proposal including the TypeScript types. To regenerate the JSON schema used to validate input Blueprints, run:

# Install dependencies
npm install
composer regenerate-json-schema

# Under the hood, it runs:
#     node components/Blueprints/json-schema/regenerate-schema.ts
# and recreates components/Blueprints/json-schema/blueprint-v2-schema.json

adamziel added 30 commits April 19, 2025 21:33
@adamziel adamziel merged commit a017acf into trunk May 20, 2025
14 of 21 checks passed
adamziel added a commit to WordPress/wordpress-playground that referenced this pull request May 30, 2025
# WordPress Extension Proposal: Blueprints v2

WordPress needs a first-class tool for creating new sites. The current
Blueprints v1 format, while expressive, lacks conciseness and
standardization. This proposal addresses these shortcomings to enable
rapid Blueprint development by people and AI tools.

## What's included in the spec?

This PR introduces WEP-1 (WordPress Extension Proposal 1) which defines
version 2 of WordPress Blueprints. The proposal consists of:

- **Blueprint Schema** — comprehensive set of TypeScript definitions
with rationale and usage examples
- **Blueprint Bundle format** — A standardized ways of bundling data
with a Blueprint
- **Blueprint Execution Algorithm**
- **Blueprint Merging Algorithm**
- A separation boundary between the Blueprint and the runner
- A lot more!

## What's intentionally left out?

- **Blueprints distribution workflow**. @akirk had an idea about an
internal, WordPress-based platform that would play a similar role as the
community [Blueprint Gallery](https://github.com/WordPress/blueprints/).
There's also a case to make for storing Blueprints directly in a git
repo. Whichever way it goes, this is a separate discussion.
- **Static data format**. It is a rabbit hole that warrants another
discussion. For sure we'll support block markup. There's also a case to
make for Markdown, which is already supported by the [Data Liberation
importer](https://github.com/Automattic/php-toolkit/tree/trunk/components/DataLiberation).
How will we express metadata? Via `<meta>` tags? A custom block explored
by @dmsnell? In an entirely different way? Who knows! It's out of scope
here.
- **Multisites**. They may require an entirely different schema. Let's
leave that for v3 or v4.
- **Tooling details**. While the spec defines requirement a runner must
fulfill, it leaves out specific APIs and CLI commands these tools will
expose.

## Next steps

Please comment on this Pull Request with any thoughts and concerns. If
you're unsure what to focus on, here's a few prompts:

* **Expresiveness** – Does the v2 schema capture the 90 % of use‑cases
your business cares about, without forcing custom workarounds?
* **Bundle format** – Is there anything missing from the proposed
Blueprint Bundle format?
* **Security** – Does anything proposed in this spec stand out to you as
a potential security issue?

Once we're sufficiently aligned, this proposal will be merged and we'll
move on to implementation.

Note that even after merging we still may do minor adjustments until the
reference implementation is ready.

From there, we'll move the discussion focus over to the [Blueprints v2
runner PR](Automattic/php-toolkit#9)

## Other notes

If this proposal model will stick, we might want to start a new
repository similarly to how PSR documents [have their own
repo](https://github.com/php-fig/fig-standards/tree/master/accepted).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants