Skip to content

Commit

Permalink
Get the script working again to ensure comments are updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ingeniumed committed Feb 23, 2025
1 parent a79246a commit 536cdc5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 77 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/pr-build-live-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ jobs:
if-no-files-found: 'error'
overwrite: true

- name: Create comment with Playground preview
uses: peter-evans/create-or-update-comment@v4
- name: Comment on PR with WordPress Playground details
uses: actions/github-script@v7
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
Test this PR in [WordPress Playground](https://playground.wordpress.net/#{"landingPage":"/wp-admin/admin.php?page=remote-data-blocks-settings","features":{"networking":true},"login":true,"preferredVersions":{"php":"8.2","wp":"latest"},"steps":[{"step":"setSiteOptions","options":{"blogname":"Remote%20Data%20Blocks%20PR#${{ github.event.pull_request.number }}","blogdescription":"Explore%20the%20Remote%20Data%20Blocks%20plugin%20in%20a%20WordPress%20Playground"}},{"step":"defineWpConfigConsts","consts":{"USE_PLAYGROUND_CORS_PROXY":true}},{"step":"installPlugin","pluginData":{"caption":"Installing%20RDB","resource":"url","url":"https://wordpress-playground.atomicsites.blog/plugin-proxy.php?org=Automattic&repo=remote-data-blocks&workflow=Build%20Live%20Branch&artifact=remote-data-blocks-${{ github.event.pull_request.number }}&pr=${{ github.event.pull_request.number }}"},"options":{"activate":true,"targetFolderName":"remote-data-blocks"}}]}).
script: |
const { run } = require('./.github/workflows/scripts/generate-playground-blueprint');
run({ github, context });
74 changes: 2 additions & 72 deletions .github/workflows/scripts/generate-playground-blueprint.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,3 @@
const https = require( 'https' );

const generateWordpressPlaygroundBlueprint = prNumber => {
const defaultSchema = {
meta: {
title: `Remote Data Blocks - PR #${ prNumber }`,
description: `Installs remote-data-blocks plugin PR #${ prNumber } to WordPress Playground`,
author: 'WordPress VIP',
categories: [ 'Content' ],
},

features: {
networking: true,
},

landingPage: '/wp-admin/admin.php?page=remote-data-blocks-settings',

login: true,

preferredVersions: {
php: '8.2',
wp: 'latest',
},

steps: [
{
step: 'setSiteOptions',
options: {
blogname: `Remote Data Blocks - PR #${ prNumber }`,
blogdescription: `Explore the remote-data-blocks plugin PR #${ prNumber } in a WordPress Playground`,
},
},
{
step: 'defineWpConfigConsts',
consts: {
USE_PLAYGROUND_CORS_PROXY: true,
},
},
{
step: 'installPlugin',
pluginData: {
caption: 'Installing Remote Data Blocks',
resource: 'url',
url: `https://wordpress-playground.atomicsites.blog/plugin-proxy.php?org=Automattic&repo=remote-data-blocks&workflow=Build%20Live%20Branch&artifact=remote-data-blocks-${ prNumber }&pr=${ prNumber }`,
},
options: {
activate: true,
targetFolderName: 'remote-data-blocks',
},
},
],
};

return defaultSchema;
};

async function run( { github, context } ) {
const commentInfo = {
owner: context.repo.owner,
Expand All @@ -67,28 +11,14 @@ async function run( { github, context } ) {
for ( const currentComment of comments ) {
if (
currentComment.user.type === 'Bot' &&
currentComment.body.includes( 'Test using WordPress Playground' )
currentComment.body.includes( 'Test this PR in' )
) {
existingCommentId = currentComment.id;
break;
}
}

const defaultSchema = generateWordpressPlaygroundBlueprint( context.issue.number );

const uriComponent = encodeURIComponent( JSON.stringify( defaultSchema ) );

const url = `https://wordpress-playground.atomicsites.blog/#${ uriComponent }`;

const body = `
## Test using WordPress Playground
The changes in this pull request can be previewed and tested using a [WordPress Playground](https://developer.wordpress.org/playground/) instance.
[WordPress Playground](https://developer.wordpress.org/playground/) is an experimental project that creates a full WordPress instance entirely within the browser.
[Test this pull request with WordPress Playground](${ url }).
Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit.
`;
const body = `Test this PR in [WordPress Playground](https://playground.wordpress.net/#{"landingPage":"/wp-admin/admin.php?page=remote-data-blocks-settings","features":{"networking":true},"login":true,"preferredVersions":{"php":"8.2","wp":"latest"},"steps":[{"step":"setSiteOptions","options":{"blogname":"Remote%20Data%20Blocks%20PR#${ context.issue.number }","blogdescription":"Explore%20the%20Remote%20Data%20Blocks%20plugin%20in%20a%20WordPress%20Playground"}},{"step":"defineWpConfigConsts","consts":{"USE_PLAYGROUND_CORS_PROXY":true}},{"step":"installPlugin","pluginData":{"caption":"Installing%20RDB","resource":"url","url":"https://wordpress-playground.atomicsites.blog/plugin-proxy.php?org=Automattic&repo=remote-data-blocks&workflow=Build%20Live%20Branch&artifact=remote-data-blocks-${ context.issue.number }&pr=${ context.issue.number }"},"options":{"activate":true,"targetFolderName":"remote-data-blocks"}}]}).`

if ( existingCommentId ) {
await github.rest.issues.updateComment( {
Expand Down

0 comments on commit 536cdc5

Please sign in to comment.