From 536cdc5526b9c798c9114221b15425e03262bb87 Mon Sep 17 00:00:00 2001 From: ingeniumed Date: Mon, 24 Feb 2025 10:33:12 +1100 Subject: [PATCH] Get the script working again to ensure comments are updated --- .github/workflows/pr-build-live-branch.yml | 10 +-- .../scripts/generate-playground-blueprint.js | 74 +------------------ 2 files changed, 7 insertions(+), 77 deletions(-) diff --git a/.github/workflows/pr-build-live-branch.yml b/.github/workflows/pr-build-live-branch.yml index cd438b38..bf30a21a 100644 --- a/.github/workflows/pr-build-live-branch.yml +++ b/.github/workflows/pr-build-live-branch.yml @@ -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 }); diff --git a/.github/workflows/scripts/generate-playground-blueprint.js b/.github/workflows/scripts/generate-playground-blueprint.js index a8cc1b03..52d5ab92 100644 --- a/.github/workflows/scripts/generate-playground-blueprint.js +++ b/.github/workflows/scripts/generate-playground-blueprint.js @@ -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, @@ -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( {