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

Support previewing Gutenberg Pull Requests #126

Merged
merged 3 commits into from
Apr 26, 2023

Conversation

adamziel
Copy link
Collaborator

@adamziel adamziel commented Feb 3, 2023

Description

Adds support for previewing Gutenberg Pull Requests via the a gutenberg-pr query parameter:

https://playground.wordpress.net/wordpress.html?gutenberg-pr=47739&url=/wp-admin/plugins.php?test=test

My test PR: WordPress/gutenberg#47739

CleanShot 2023-02-03 at 19 33 17@2x

Implementation

The plugin bundle is downloaded from GitHub CI and installed by applying the following Blueprint:

function applyGutenbergPRSteps(prNumber: number): StepDefinition[] {
	return [
		{
			step: 'mkdir',
			path: '/wordpress/pr',
		},
		{
			step: 'writeFile',
			path: '/wordpress/pr/pr.zip',
			data: {
				resource: 'url',
				url: `/plugin-proxy?org=WordPress&repo=gutenberg&workflow=Build%20Gutenberg%20Plugin%20Zip&artifact=gutenberg-plugin&pr=${prNumber}`,
				caption: `Downloading Gutenberg PR ${prNumber}`,
			},
			progress: {
				weight: 2,
				caption: `Applying Gutenberg PR ${prNumber}`,
			},
		},
		{
			step: 'unzip',
			zipPath: '/wordpress/pr/pr.zip',
			extractToPath: '/wordpress/pr',
		},
		{
			step: 'installPlugin',
			pluginZipFile: {
				resource: 'vfs',
				path: '/wordpress/pr/gutenberg.zip',
			},
		},
	];
}

Gutenberg PR preview from playground.wordpress.net can be embedded in other apps via an iframe.

To implement your own PR previewer that pulls data from another repo, you'll need to expose an API endpoint to download the ZIP bundle and then plug it in the writeFile step above. Once you have that, here's how you'd apply a custom blueprint:

import { startPlaygroundWeb } from "https://unpkg.com/@wp-playground/client@0.1.32/index.js";
startPlaygroundWeb({
	iframe,
	remoteUrl: `https://playground.wordpress.net/remote.html`,
	blueprint: {
		steps: applyPR( 47339 )
	}
})

function applyPR( prNumber ) {
	return [
		{
			step: 'mkdir',
			path: '/wordpress/pr',
		},
		// ...
	];
}

@adamziel
Copy link
Collaborator Author

With Playground Blueprints, a PR bundle could be just another Resource.

@adamziel adamziel force-pushed the explore/gutenberg-pr-preview branch from 85367c7 to ccd9550 Compare April 25, 2023 22:28
@adamziel adamziel closed this Apr 26, 2023
@adamziel adamziel deleted the explore/gutenberg-pr-preview branch April 26, 2023 07:56
@adamziel adamziel restored the explore/gutenberg-pr-preview branch April 26, 2023 07:56
@adamziel adamziel reopened this Apr 26, 2023
@adamziel adamziel changed the title Support previewing Gutenbeg Pull requests by installing them as plugins Support previewing Gutenbeg Pull Requests Apr 26, 2023
@adamziel adamziel marked this pull request as ready for review April 26, 2023 08:07
@adamziel adamziel self-assigned this Apr 26, 2023
@adamziel adamziel added the [Type] Enhancement New feature or request label Apr 26, 2023
@adamziel
Copy link
Collaborator Author

I redid this PR with Blueprints and, other than the PHP Proxy, it's took about 60 lines of code (vs 1000+ before we had Blueprints). Not bad!

@akirk akirk changed the title Support previewing Gutenbeg Pull Requests Support previewing Gutenberg Pull Requests Apr 26, 2023
@adamziel adamziel merged commit a7a16ae into trunk Apr 26, 2023
@adamziel adamziel deleted the explore/gutenberg-pr-preview branch April 26, 2023 08:16
@adamziel adamziel mentioned this pull request Apr 27, 2023
56 tasks
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.

1 participant