WordPress / wordpress-playground

Run WordPress in the browser via WebAssembly PHP
https://w.org/playground/
GNU General Public License v2.0
1.65k stars 263 forks source link

[Blueprints] Add a github:artifact resource type #1796

Open adamziel opened 2 months ago

adamziel commented 2 months ago

GitHub artifacts are difficult to use as Blueprint resources. As doubly zipped archives, they need convoluted peeling. Let's introduce a new resource type called github:artifact that would take handle the peeling for the developer.

What I want the Blueprint to look like

{
    "steps": [
        {
            step: 'installPlugin',
            pluginData: {
                resource: 'github:artifact',
                url: zipArtifactUrl
            },
        }
    ]
}

What the Blueprint looks like today

{
    "steps": [
        {
            step: 'mkdir',
            path: '/wordpress/pr',
        },
        /*
         * This is the most important step.
         * It download the built plugin zip file exposed by GitHub CI.
         *
         * Because the zip file is not publicly accessible, we use the
         * plugin-proxy API endpoint to download it. The source code of
         * that endpoint is available at:
         * https://github.com/WordPress/wordpress-playground/blob/trunk/packages/playground/website/public/plugin-proxy.php
         */
        {
            step: 'writeFile',
            path: '/wordpress/pr/pr.zip',
            data: {
                resource: 'url',
                url: zipArtifactUrl,
                caption: `Downloading Gutenberg PR ${prNumber}`,
            },
            progress: {
                weight: 2,
                caption: `Applying Gutenberg PR ${prNumber}`,
            },
        },
        /**
         * GitHub CI artifacts are doubly zipped:
         *
         * pr.zip
         *    gutenberg.zip
         *       gutenberg.php
         *       ... other files ...
         *
         * This step extracts the inner zip file so that we get
         * access directly to gutenberg.zip and can use it to
         * install the plugin.
         */
        {
            step: 'unzip',
            zipPath: '/wordpress/pr/pr.zip',
            extractToPath: '/wordpress/pr',
        },
        {
            step: 'installPlugin',
            pluginData: {
                resource: 'vfs',
                path: '/wordpress/pr/gutenberg.zip',
            },
        }
    ]
}
adamziel commented 1 month ago

Explorations in https://github.com/WordPress/wordpress-playground/pull/1799