55 pull_request_target :
66 types : [ 'opened', 'synchronize', 'reopened', 'edited' ]
77 workflow_run :
8- workflows : [ 'Test Build Processes' ]
8+ workflows : [ 'Check Built Files (PRs)', ' Test Build Processes' ]
99 types :
1010 - completed
1111
@@ -22,6 +22,7 @@ permissions: {}
2222jobs :
2323 # Comments on a pull request when the author is a first time contributor.
2424 post-welcome-message :
25+ name : Contributor welcome message
2526 runs-on : ubuntu-24.04
2627 permissions :
2728 issues : write
@@ -79,14 +80,15 @@ jobs:
7980
8081 # Leaves a comment on a pull request with a link to test the changes in a WordPress Playground instance.
8182 playground-details :
82- name : Comment on a pull request with Playground details
83+ name : Leave Playground testing details
8384 runs-on : ubuntu-24.04
8485 permissions :
8586 issues : write
8687 pull-requests : write
8788 if : >
8889 github.repository == 'WordPress/wordpress-develop' &&
8990 github.event.workflow_run.event == 'pull_request' &&
91+ github.event.workflow_run.name == 'Test Build Processes' &&
9092 github.event.workflow_run.conclusion == 'success'
9193 steps :
9294 - name : Download artifact
@@ -180,6 +182,146 @@ jobs:
180182
181183 github.rest.issues.createComment( commentInfo );
182184
185+ # Leaves a comment on a pull request noting differences between the PR and the build server.
186+ build-server-comparison :
187+ name : Note differences with the build server
188+ runs-on : ubuntu-24.04
189+ permissions :
190+ issues : write
191+ pull-requests : write
192+ if : >
193+ github.repository == 'WordPress/wordpress-develop' &&
194+ github.event.workflow_run.event == 'pull_request' &&
195+ github.event.workflow_run.name == 'Check Built Files (PRs)' &&
196+ github.event.workflow_run.conclusion == 'success'
197+ steps :
198+ - name : Download artifact
199+ uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
200+ env :
201+ RUN_ID : ${{ github.event.workflow_run.id }}
202+ with :
203+ script : |
204+ const artifacts = await github.rest.actions.listWorkflowRunArtifacts( {
205+ owner: context.repo.owner,
206+ repo: context.repo.repo,
207+ run_id: process.env.RUN_ID,
208+ } );
209+
210+ const matchArtifact = artifacts.data.artifacts.filter( ( artifact ) => {
211+ return artifact.name === 'build-server-comparison'
212+ } )[0];
213+
214+ if ( ! matchArtifact ) {
215+ core.setFailed( 'No artifact found!' );
216+ return;
217+ }
218+
219+ const download = await github.rest.actions.downloadArtifact( {
220+ owner: context.repo.owner,
221+ repo: context.repo.repo,
222+ artifact_id: matchArtifact.id,
223+ archive_format: 'zip',
224+ } );
225+
226+ const fs = require( 'fs' );
227+ fs.writeFileSync( '${{github.workspace}}/build-server-comparison.zip', Buffer.from( download.data ) )
228+
229+ - name : Unzip the artifact containing the comparison info
230+ run : unzip build-server-comparison.zip
231+
232+ - name : Leave a comment with any differences noticed
233+ uses : actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
234+ with :
235+ script : |
236+ const fs = require( 'fs' );
237+ const issue_number = Number( fs.readFileSync( './NR' ) );
238+ const fileChanges = fs.readFileSync( './file-changes.txt', 'utf8' );
239+ const diffContents = fs.readFileSync( './changes.diff', 'utf8' );
240+ const MAX_DIFF_LENGTH = 50000; // GitHub has a 65,536 character limit for comments.
241+
242+ core.info( `Checking pull request #${issue_number}.` );
243+
244+ // Confirm that the pull request is still open before leaving a comment.
245+ const pr = await github.rest.pulls.get({
246+ owner: context.repo.owner,
247+ repo: context.repo.repo,
248+ pull_number: issue_number,
249+ });
250+
251+ if ( pr.data.state !== 'open' ) {
252+ core.info( 'The pull request has been closed. No comment will be left.' );
253+ return;
254+ }
255+
256+ // Comments are only added after the first successful build. Check for the presence of a comment and bail early.
257+ const commentInfo = {
258+ owner: context.repo.owner,
259+ repo: context.repo.repo,
260+ issue_number,
261+ };
262+
263+ const comments = ( await github.rest.issues.listComments( commentInfo ) ).data;
264+
265+ for ( const currentComment of comments ) {
266+ if ( currentComment.user.type === 'Bot' && currentComment.body.includes( 'Build Script Results Comparison' ) ) {
267+ commentInfo.comment_id = currentComment.id;
268+ break;
269+ }
270+ };
271+
272+ commentInfo.body = '## Build Server Comparison';
273+
274+ // Post or update the comment.
275+ if ( fileChanges.trim() === '' ) {
276+ commentInfo.body += 'The contents of the `build` directory after running `npm run build` matches the contents of the WordPress/WordPress repository. No differences were found.';
277+ } else {
278+ commentInfo.body += 'The contents of the `build` directory after running `npm run build` has been compared with the contents of the WordPress/WordPress repository.
279+
280+ **Review these differences carefully for any unexpected results.**
281+
282+ ### List of Modified Files
283+
284+ \`\`\`
285+ ${ fileChanges }
286+ \`\`\`
287+
288+ ### Full Diff File
289+ `;
290+
291+ if ( diffContents.length > MAX_DIFF_LENGTH ) {
292+ const cutoff = diffContents.lastIndexOf( '\n', MAX_DIFF_LENGTH );
293+ const truncated = diffContents.substring( 0, cutoff );
294+
295+ commentInfo.body += `<details>
296+ <summary>Click to expand (truncated)</summary>
297+
298+ \`\`\`diff
299+ ${ truncated }
300+ \`\`\`
301+
302+ ⚠️ The diff was too large to display in full.
303+
304+ </details>`;
305+ } else {
306+ commentInfo.body += `<details>
307+ <summary>Click to expand</summary>
308+
309+ \`\`\`diff
310+ ${ diffContents }
311+ \`\`\`
312+
313+ </details>`;
314+ }
315+
316+ commentInfo.body += `[Download the complete .diff file from the workflow run](https://github.com/${ context.repo.owner }/${ context.repo.repo }/actions/runs/${ process.env.RUN_ID }).`;
317+ }
318+
319+ if ( commentInfo.comment_id ) {
320+ github.rest.issues.updateComment( commentInfo );
321+ } else {
322+ github.rest.issues.createComment( commentInfo );
323+ }
324+
183325 # Manages comments reminding contributors to include a Trac ticket link when opening a pull request.
184326 trac-ticket-check :
185327 name : Manage Trac ticket reminders for pull requests
0 commit comments