diff --git a/.github/scripts/playground-comment.js b/.github/scripts/playground-comment.js
index 62adf427e..9452fb2f8 100644
--- a/.github/scripts/playground-comment.js
+++ b/.github/scripts/playground-comment.js
@@ -78,8 +78,13 @@ async function run({ github, context, core }) {
return;
}
- // Comments are only added after the first successful build.
- // The caller should check for existing comments before calling this function.
+ // Check for existing playground comment to update instead of creating duplicate
+ const comments = await github.rest.issues.listComments(commentInfo);
+
+ const existingComment = comments.data.find(comment =>
+ comment.user.type === 'Bot' &&
+ comment.body.includes('Test using WordPress Playground')
+ );
const defaultSchema = generateWordpressPlaygroundBlueprint(
context.runId,
@@ -111,19 +116,36 @@ The changes in this pull request can be previewed and tested using a [WordPress
> 💡 The demo environment resets each time you refresh. Perfect for testing!
>
-> ⚠️ This URL is valid for 30 days from when this comment was last updated. You can refresh it by pushing a new commit.
+> 🔄 This link updates automatically with each new commit to the PR.
+>
+> ⚠️ This URL is valid for 30 days from when this comment was last updated.
---
-🤖 Auto-generated for commit ${context.payload.pull_request.head.sha}`;
+🤖 Auto-generated for commit ${context.payload.pull_request.head.sha} • Last updated: ${new Date().toISOString()}`;
- // Create the comment
- commentInfo.body = body;
- await github.rest.issues.createComment(commentInfo);
+ if (existingComment) {
+ // Update existing comment
+ await github.rest.issues.updateComment({
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ comment_id: existingComment.id,
+ body: body
+ });
- core.info('Successfully created playground comment on PR');
+ core.info(`Successfully updated existing playground comment #${existingComment.id} on PR #${context.issue.number}`);
+ } else {
+ // Create new comment
+ await github.rest.issues.createComment({
+ ...commentInfo,
+ body: body
+ });
+
+ core.info(`Successfully created new playground comment on PR #${context.issue.number}`);
+ }
} catch (error) {
- core.setFailed(`Failed to create playground comment: ${error.message}`);
+ core.setFailed(`Failed to create/update playground comment: ${error.message}`);
+ core.error(`Error details: ${error.stack}`);
}
}
diff --git a/.github/workflows/pr-playground-demo.yml b/.github/workflows/pr-playground-demo.yml
index 7310c03e6..c4fb5a925 100644
--- a/.github/workflows/pr-playground-demo.yml
+++ b/.github/workflows/pr-playground-demo.yml
@@ -109,7 +109,7 @@ jobs:
- name: Unzip PR details
run: unzip pr-details.zip
- - name: Comment on PR with WordPress Playground link
+ - name: Create or update PR playground comment
uses: actions/github-script@v7
with:
script: |
@@ -118,21 +118,6 @@ jobs:
const plugin_version = fs.readFileSync('./VERSION', 'utf8').trim();
const artifact_name = fs.readFileSync('./ARTIFACT', 'utf8').trim();
- // Check for existing comment to avoid duplicates
- const commentInfo = {
- owner: context.repo.owner,
- repo: context.repo.repo,
- issue_number,
- };
-
- const comments = (await github.rest.issues.listComments(commentInfo)).data;
-
- for (const currentComment of comments) {
- if (currentComment.user.type === 'Bot' && currentComment.body.includes('Test using WordPress Playground')) {
- return;
- }
- }
-
// Load the comment script
const script = require('./.github/scripts/playground-comment.js');