Commit 052d0fa7c6 for woocommerce
commit 052d0fa7c6407c18b34795772e5c322622e62ada
Author: Allison Levine <1689238+allilevine@users.noreply.github.com>
Date: Wed Jan 14 14:39:25 2026 -0500
Github workflows: Add reminder comment to test email editor changes on WP.com (#62669)
* Github workflows: Add reminder comment to test email editor changes on WPCOM.
* Clarify step 1.
* Add pagination.
* Address workflow feedback and add clearer testing steps.
* Move scripts out of yml file to reduce duplication and improve maintainability.
* Update comment language and replace some steps with a link to the Field Guide.
* Update title to remove mandatory tone.
diff --git a/.github/workflows/pr-email-editor-test-reminder.yml b/.github/workflows/pr-email-editor-test-reminder.yml
new file mode 100644
index 0000000000..1d96e7f9cf
--- /dev/null
+++ b/.github/workflows/pr-email-editor-test-reminder.yml
@@ -0,0 +1,52 @@
+name: Email Editor Test Reminder
+
+on:
+ pull_request:
+ types: [opened, synchronize, reopened]
+
+concurrency:
+ group: email-editor-test-reminder-${{ github.event.pull_request.number }}
+ cancel-in-progress: true
+
+permissions:
+ pull-requests: write
+ contents: read
+
+jobs:
+ check-and-comment:
+ name: Check and add test reminder comment
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v4
+
+ - name: Setup Node
+ uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
+ with:
+ node-version-file: '.nvmrc'
+
+ - name: Check if PR touches email editor
+ id: check-email-editor
+ uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7.0.1
+ with:
+ script: |
+ const { checkEmailEditorTestReminderComment } = require( './.github/workflows/scripts/check-email-editor-test-reminder-comment.js' );
+ const result = await checkEmailEditorTestReminderComment( github, context, core );
+ core.setOutput( 'touches-email-editor', result.touchesEmailEditor ? 'true' : 'false' );
+
+ - name: Create or update test reminder comment
+ if: steps.check-email-editor.outputs.touches-email-editor == 'true'
+ uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7.0.1
+ with:
+ script: |
+ const { createOrUpdateTestReminderComment } = require( './.github/workflows/scripts/manage-email-editor-test-reminder-comment.js' );
+ await createOrUpdateTestReminderComment( github, context, core );
+
+ - name: Delete test reminder comment
+ if: steps.check-email-editor.outputs.touches-email-editor == 'false'
+ uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea #v7.0.1
+ with:
+ script: |
+ const { deleteTestReminderComment } = require( './.github/workflows/scripts/manage-email-editor-test-reminder-comment.js' );
+ await deleteTestReminderComment( github, context, core );
+
diff --git a/.github/workflows/scripts/check-email-editor-test-reminder-comment.js b/.github/workflows/scripts/check-email-editor-test-reminder-comment.js
new file mode 100644
index 0000000000..ad44ecf3d1
--- /dev/null
+++ b/.github/workflows/scripts/check-email-editor-test-reminder-comment.js
@@ -0,0 +1,48 @@
+/**
+ * Check if a PR touches the email editor package and needs a test reminder comment.
+ *
+ * @param {Object} github - Pre-authenticated octokit/rest.js client
+ * @param {Object} context - Context of the workflow run
+ * @param {Object} core - A reference to the `@actions/core` package
+ * @return {Promise<Object>} Promise resolving to an object with:
+ * - {boolean} touchesEmailEditor - Whether the PR touches packages/php/email-editor
+ */
+async function checkEmailEditorTestReminderComment( github, context, core ) {
+ const { repo, issue } = context;
+ const { owner, repo: repoName } = repo;
+ const prNumber = issue.number;
+
+ core.info( `Checking if PR #${ prNumber } touches packages/php/email-editor` );
+
+ // Get the list of files changed in this PR (paginated to get all files)
+ const files = await github.paginate( github.rest.pulls.listFiles, {
+ owner,
+ repo: repoName,
+ pull_number: prNumber,
+ per_page: 100,
+ } );
+
+ // Check if any file is in packages/php/email-editor
+ const touchesEmailEditor = files.some( ( file ) =>
+ file.filename.startsWith( 'packages/php/email-editor/' )
+ );
+
+ if ( touchesEmailEditor ) {
+ core.info(
+ `PR #${ prNumber } touches packages/php/email-editor - test reminder needed`
+ );
+ } else {
+ core.info(
+ `PR #${ prNumber } does not touch packages/php/email-editor - no test reminder needed`
+ );
+ }
+
+ return {
+ touchesEmailEditor,
+ };
+}
+
+module.exports = {
+ checkEmailEditorTestReminderComment,
+};
+
diff --git a/.github/workflows/scripts/manage-email-editor-test-reminder-comment.js b/.github/workflows/scripts/manage-email-editor-test-reminder-comment.js
new file mode 100644
index 0000000000..9bd2fdd46e
--- /dev/null
+++ b/.github/workflows/scripts/manage-email-editor-test-reminder-comment.js
@@ -0,0 +1,118 @@
+/**
+ * Helper function to find an existing email editor test reminder comment.
+ *
+ * @param {Object} github - Pre-authenticated octokit/rest.js client
+ * @param {Object} context - Context of the workflow run
+ * @return {Promise<Object|null>} Promise resolving to the comment object or null if not found
+ */
+async function findExistingComment( github, context ) {
+ const comments = await github.paginate( github.rest.issues.listComments, {
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ issue_number: context.issue.number,
+ per_page: 100,
+ } );
+
+ return (
+ comments.find(
+ ( comment ) =>
+ comment.user.login === 'github-actions[bot]' &&
+ comment.body.includes( '<!-- email-editor-test-reminder -->' )
+ ) || null
+ );
+}
+
+/**
+ * Generate the comment body for the email editor test reminder.
+ *
+ * @param {number} prNumber - The PR number
+ * @return {string} The formatted comment body
+ */
+function generateCommentBody( prNumber ) {
+ return `<!-- email-editor-test-reminder -->
+## Email Editor Testing (WordPress.com)
+
+Are you an Automattician? If this PR relates to email rendering or reading site data, please test it on WordPress.com.
+
+To test, run the downloader script on your sandbox:
+\`\`\`bash
+bash bin/woocommerce-email-editor-downloader test ${ prNumber }
+\`\`\`
+
+To remove the changes after testing:
+\`\`\`bash
+bash bin/woocommerce-email-editor-downloader reset
+\`\`\`
+
+For a complete list of steps, see: PCYsg-19om-p2`;
+}
+
+/**
+ * Create or update the email editor test reminder comment on a PR.
+ *
+ * @param {Object} github - Pre-authenticated octokit/rest.js client
+ * @param {Object} context - Context of the workflow run
+ * @param {Object} core - A reference to the `@actions/core` package
+ * @return {Promise<void>}
+ */
+async function createOrUpdateTestReminderComment( github, context, core ) {
+ const prNumber = context.issue.number;
+ const commentBody = generateCommentBody( prNumber );
+
+ core.info( `Creating or updating test reminder comment for PR #${ prNumber }` );
+
+ const existingComment = await findExistingComment( github, context );
+
+ if ( existingComment ) {
+ // Update existing comment
+ await github.rest.issues.updateComment( {
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ comment_id: existingComment.id,
+ body: commentBody,
+ } );
+ core.info( `Updated existing test reminder comment for PR #${ prNumber }` );
+ } else {
+ // Create new comment
+ await github.rest.issues.createComment( {
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ issue_number: context.issue.number,
+ body: commentBody,
+ } );
+ core.info( `Created new test reminder comment for PR #${ prNumber }` );
+ }
+}
+
+/**
+ * Delete the email editor test reminder comment from a PR if it exists.
+ *
+ * @param {Object} github - Pre-authenticated octokit/rest.js client
+ * @param {Object} context - Context of the workflow run
+ * @param {Object} core - A reference to the `@actions/core` package
+ * @return {Promise<void>}
+ */
+async function deleteTestReminderComment( github, context, core ) {
+ const prNumber = context.issue.number;
+
+ core.info( `Checking for test reminder comment to delete for PR #${ prNumber }` );
+
+ const existingComment = await findExistingComment( github, context );
+
+ if ( existingComment ) {
+ await github.rest.issues.deleteComment( {
+ owner: context.repo.owner,
+ repo: context.repo.repo,
+ comment_id: existingComment.id,
+ } );
+ core.info( `Deleted test reminder comment for PR #${ prNumber }` );
+ } else {
+ core.info( `No test reminder comment found for PR #${ prNumber }` );
+ }
+}
+
+module.exports = {
+ createOrUpdateTestReminderComment,
+ deleteTestReminderComment,
+};
+