Skip to content

Commit

Permalink
wordpress-develop Pull Request previewer (#700)
Browse files Browse the repository at this point in the history
## What is this PR doing?

Support for previewing wordpress-develop Pull Requests.

<img width="1133" alt="CleanShot 2023-10-13 at 18 53 52@2x"
src="https://github.com/WordPress/wordpress-playground/assets/205419/e30e9ac6-c99e-4e81-b68f-45e14116f6c9">

The previewer lives in `/wordpress.html` and supports a few query
parameters:

* `?pr=5481` – preview that PR
* `?url=/wp-admin/post-new.php` – load that URL in WordPress
* `?mode=seamless` – redirect to a full-screen Playground without the
browser chrome and any other extra UI elements

## Caveats

The downloaded WordPress bundle is ~45MB and takes a while to download
without any visible progress information. Let's find a way to optimize
it.

## Testing instructions

1. Go to http://localhost:5400/website-server/wordpress.html
2. Preview PR 5481 (no other PR works yet, see
WordPress/wordpress-develop#5481)
3. Confirm in wp-admin the WordPress version is 6.4 dev

## Screenshots

<img width="1286" alt="CleanShot 2023-10-13 at 18 58 36@2x"
src="https://github.com/WordPress/wordpress-playground/assets/205419/ca25a714-4491-4f63-b82c-b2178a2828b5">

cc @spacedmonkey @fabiankaegy @dmsnell @jonathanbossenger @dawidurbanski
  • Loading branch information
adamziel authored Oct 17, 2023
1 parent aa8e2d2 commit ae7a8e0
Show file tree
Hide file tree
Showing 6 changed files with 497 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,26 @@ class WordPressPatcher {
}

async patchSecrets() {
await defineWpConfigConsts(this.php, {
consts: {
AUTH_KEY: randomString(40),
SECURE_AUTH_KEY: randomString(40),
LOGGED_IN_KEY: randomString(40),
NONCE_KEY: randomString(40),
AUTH_SALT: randomString(40),
SECURE_AUTH_SALT: randomString(40),
LOGGED_IN_SALT: randomString(40),
NONCE_SALT: randomString(40),
},
});
await updateFile(
this.php,
`${this.wordpressPath}/wp-config.php`,
(contents) =>
`<?php
define('AUTH_KEY', '${randomString(40)}');
define('SECURE_AUTH_KEY', '${randomString(40)}');
define('LOGGED_IN_KEY', '${randomString(40)}');
define('NONCE_KEY', '${randomString(40)}');
define('AUTH_SALT', '${randomString(40)}');
define('SECURE_AUTH_SALT', '${randomString(40)}');
define('LOGGED_IN_SALT', '${randomString(40)}');
define('NONCE_SALT', '${randomString(40)}');
?>${contents.replaceAll("', 'put your unique phrase here'", "__', ''")}`
contents.replaceAll(
"', 'put your unique phrase here'",
"__', ''"
)
);
}

Expand All @@ -139,11 +145,11 @@ class WordPressPatcher {
}

async prepareForRunningInsideWebBrowser() {
await updateFile(
this.php,
`${this.wordpressPath}/wp-config.php`,
(contents) => `${contents} define('USE_FETCH_FOR_REQUESTS', false);`
);
await defineWpConfigConsts(this.php, {
consts: {
USE_FETCH_FOR_REQUESTS: false,
},
});

// Force the fsockopen and cUrl transports to report they don't work:
const transports = [
Expand Down
10 changes: 5 additions & 5 deletions packages/playground/website/public/gutenberg.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
rel="stylesheet"
href="https://fonts.googleapis.com/css?family=Noto+Serif:400,700"
/>
<link rel="stylesheet" href="./gutenberg.css" />
<link rel="stylesheet" href="./previewer.css" />
</head>
<body>
<div id="main">
Expand All @@ -27,12 +27,12 @@
action="https://playground.wordpress.net"
method="GET"
>
<label for="gutenberg-pr">Pull request number or URL:</label>
<label for="pr-number">Pull request number or URL:</label>
<div id="createFields">
<input
id="gutenberg-pr"
id="pr-number"
type="text"
name="gutenberg-pr"
name="pr-number"
value=""
required
autofocus
Expand Down Expand Up @@ -92,7 +92,7 @@
submitButton.classList.add('loading');
submitButton.disabled = true;

let prNumber = document.getElementById('gutenberg-pr').value;
let prNumber = document.getElementById('pr-number').value;

// Extract number from a GitHub URL
if (
Expand Down
12 changes: 6 additions & 6 deletions packages/playground/website/public/plugin-proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function streamFromGithubPR($organization, $repo, $pr, $workflow_name, $a
}

foreach ($artifacts->artifacts as $artifact) {
if ($artifact->name === $artifact_name) {
if ($artifact_name === $artifact->name) {
$zip_download_api_endpoint = $artifact->archive_download_url;
break;
}
Expand Down Expand Up @@ -245,19 +245,19 @@ function ($curl, $body) use (&$extra_headers_sent, $default_headers) {
'org' => 'WordPress',
'repo' => 'gutenberg',
'workflow' => 'Build Gutenberg Plugin Zip',
'artifact' => 'gutenberg-plugin'
'artifact' => '#gutenberg-plugin#'
],
[
'org' => 'woocommerce',
'repo' => 'woocommerce',
'workflow' => 'Build Live Branch',
'artifact' => 'plugins'
'artifact' => '#plugins#'
],
[
'org' => 'WordPress',
'repo' => 'wordpress-develop',
'workflow' => 'Test npm',
'artifact' => 'wordpress-build-dev'
'workflow' => 'Build WordPress',
'artifact' => '#wordpress-build-\d+#'
],
];
$allowed = false;
Expand All @@ -266,7 +266,7 @@ function ($curl, $body) use (&$extra_headers_sent, $default_headers) {
$_GET['org'] === $allowedInput['org'] &&
$_GET['repo'] === $allowedInput['repo'] &&
$_GET['workflow'] === $allowedInput['workflow'] &&
$_GET['artifact'] === $allowedInput['artifact']
preg_match($allowedInput['artifact'], $_GET['artifact'])
) {
$allowed = true;
break;
Expand Down
190 changes: 190 additions & 0 deletions packages/playground/website/public/previewer.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
body,
html {
height: 100%;
}
html {
font-size: 16px;
}
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto,
Oxygen-Sans, Ubuntu, Cantarell, Helvetica Neue, sans-serif;
line-height: 1.8;
color: #191e23;
display: flex;
flex-direction: column;
justify-content: center;
}
svg {
fill: currentColor;
}
label {
margin-bottom: 4px;
font-size: 22px;
}
input[type='text'] {
appearance: none;
-webkit-appearance: none;
-moz-appearance: textfield;
border: 1px solid #8d96a0;
border-radius: 4px;
padding: 5px 8px;
outline: 0;
font-size: 26px;
}
input[type='text']::-webkit-inner-spin-button,
input[type='text']::-webkit-outer-spin-button {
-webkit-appearance: none;
margin: 0;
}
input[type='text']:focus {
border-color: #00a0d2;
box-shadow: 0 0 0 1px #00a0d2;
color: #191e23;
outline: 2px solid transparent;
outline-offset: -2px;
}
button {
border-radius: 3px;
vertical-align: top;
height: 40px;
line-height: 38px;
padding: 0 12px;
webkit-appearance: none;
border: 0;
cursor: pointer;
display: inline-flex;
font-size: 30px;
margin: 0;
background: #0085ba;
border-color: #006a95 #00648c #00648c;
box-shadow: inset 0 -1px 0 #00648c;
color: #fff;
text-shadow: 0 -1px 1px #005d82, 1px 0 1px #005d82, 0 1px 1px #005d82,
-1px 0 1px #005d82;
}
button:hover {
box-shadow: inset 0 -1px 0 #00435d;
background: #007eb1;
border-color: #00435d;
}
button:active {
background: #006a95;
border-color: #00435d;
box-shadow: inset 0 1px 0 #00435d;
vertical-align: top;
}
button:focus {
outline: 2px solid transparent;
outline-offset: -2px;
box-shadow: inset 0 -1px 0 #00435d, 0 0 0 2px #bfe7f3;
background: #007eb1;
border-color: #00435d;
}
#main {
display: flex;
flex-direction: column;
align-items: center;
height: 50vh;
width: 100%;
margin: 0 auto;
}
#logo {
flex-shrink: 1;
flex-grow: 0;
flex-basis: 100%;
}
#create,
#run {
height: 60px;
margin: 5vh 0;
flex-shrink: 0;
}
#createFields {
display: flex;
align-items: center;
}
#pr-number {
width: 280px;
margin-right: 4px;
}
#run {
width: 100%;
display: flex;
flex-direction: column;
justify-content: space-between;
}
#status {
display: block;
font-weight: 400;
font-size: 1.4rem;
text-align: center;
font-family: 'Noto Serif', serif;
}
#progress {
max-width: 360px;
width: 90%;
margin: 0 auto;
height: 5px;
background: #eaeaea;
padding: 3px;
}
#progressFill {
height: 5px;
background: #191e23;
transition: width 0.6s ease-in-out;
}
#links {
text-align: center;
padding: 0 10px;
}
#error {
text-align: center;
padding: 0 10px;
margin-bottom: 5vh;
color: #8b0000;
font-weight: bold;
font-size: 1.5em;
}

#submit {
display: flex;
align-items: center;
justify-content: center;
}

#submit:not(.loading) .verifying {
display: none;
}
#submit.loading .go {
display: none;
}

#submit.loading {
position: relative;
background: #00435d;
border-color: #00435d;
cursor: default;
}

#submit.loading:before {
content: '';
/* position: absolute;
top: 0;
left: 0; */
margin-right: 5px;
margin-left: -5px;
width: 15px;
height: 15px;
border-radius: 50%;
border: 2px solid #fff;
border-top-color: transparent;
border-right-color: transparent;
animation: spin 1s linear infinite;
}

@keyframes spin {
to {
transform: rotate(360deg);
}
}
Loading

0 comments on commit ae7a8e0

Please sign in to comment.