Skip to content

Commit 3fd19d6

Browse files
committed
Don't leave a comment when no changes result.
When a pre-existing comment exists, update it.
1 parent 9f80170 commit 3fd19d6

2 files changed

Lines changed: 24 additions & 18 deletions

File tree

.github/workflows/pull-request-comments.yml

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,20 @@ jobs:
269269
}
270270
};
271271
272-
commentInfo.body = "## Build Server Comparison\n\n";
273-
274272
// Post or update the comment.
275273
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.
274+
if ( ! commentInfo.comment_id ) {
275+
core.info( 'No differences found and no existing comment. Skipping.' );
276+
return;
277+
}
278+
279+
commentInfo.body = "## Build Server Comparison\n\nThe changes in this pull request will not result in any differences with the WordPress/WordPress repository.";
280+
github.rest.issues.updateComment( commentInfo );
281+
return;
282+
}
283+
284+
commentInfo.body = "## Build Server Comparison\n\n";
285+
commentInfo.body += `The contents of the \`build\` directory after running \`npm run build\` has been compared with the contents of the WordPress/WordPress repository.
279286
280287
**Review these differences carefully for any unexpected results.**
281288
@@ -288,11 +295,11 @@ jobs:
288295
### Full Diff File
289296
`;
290297
291-
if ( diffContents.length > MAX_DIFF_LENGTH ) {
292-
const cutoff = diffContents.lastIndexOf( '\n', MAX_DIFF_LENGTH );
293-
const truncated = diffContents.substring( 0, cutoff );
298+
if ( diffContents.length > MAX_DIFF_LENGTH ) {
299+
const cutoff = diffContents.lastIndexOf( '\n', MAX_DIFF_LENGTH );
300+
const truncated = diffContents.substring( 0, cutoff );
294301
295-
commentInfo.body += `<details>
302+
commentInfo.body += `<details>
296303
<summary>Click to expand (truncated)</summary>
297304
298305
\`\`\`diff
@@ -302,22 +309,21 @@ jobs:
302309
⚠️ The diff was too large to display in full.
303310
304311
</details>`;
305-
} else {
306-
commentInfo.body += `<details>
312+
} else {
313+
commentInfo.body += `<details>
307314
<summary>Click to expand</summary>
308315
309316
\`\`\`diff
310317
${ diffContents }
311318
\`\`\`
312319
313320
</details>`;
314-
}
315-
316-
const sha = context.payload.workflow_run.head_sha;
317-
commentInfo.body += `\n\n_Comment updated using [${ sha.slice( 0, 7 ) }](https://github.com/${ context.repo.owner }/${ context.repo.repo }/commit/${ sha })._ ([commenting workflow run](https://github.com/${ context.repo.owner }/${ context.repo.repo }/actions/runs/${ context.runId })).`;
318-
commentInfo.body += `\n\n[Download the complete .diff file from the workflow run](https://github.com/${ context.repo.owner }/${ context.repo.repo }/actions/runs/${ context.payload.workflow_run.id }).`;
319321
}
320322
323+
const sha = context.payload.workflow_run.head_sha;
324+
commentInfo.body += `\n\n_Comment updated using [${ sha.slice( 0, 7 ) }](https://github.com/${ context.repo.owner }/${ context.repo.repo }/commit/${ sha })._ ([commenting workflow run](https://github.com/${ context.repo.owner }/${ context.repo.repo }/actions/runs/${ context.runId })).`;
325+
commentInfo.body += `\n\n[Download the complete .diff file from the workflow run](https://github.com/${ context.repo.owner }/${ context.repo.repo }/actions/runs/${ context.payload.workflow_run.id }).`;
326+
321327
if ( commentInfo.comment_id ) {
322328
github.rest.issues.updateComment( commentInfo );
323329
} else {

.github/workflows/reusable-compare-built-files-v1.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ jobs:
9191
run: mkdir artifacts
9292

9393
- name: Create a list of files that have changed
94-
run: diff --strip-trailing-cr --recursive --exclude='.git' ${{ github.workspace }}/build ${{ github.workspace }}/build-server | sed "s|${{ github.workspace }}/||g" > artifacts/file-changes.txt
94+
run: diff --strip-trailing-cr --recursive --exclude='.git' --exclude='version.php' ${{ github.workspace }}/build ${{ github.workspace }}/build-server | sed "s|${{ github.workspace }}/||g" > artifacts/file-changes.txt
9595

9696
- name: Create a list of files that have changed
97-
run: diff --strip-trailing-cr --recursive --exclude='.git' ${{ github.workspace }}/build ${{ github.workspace }}/build-server | sed "s|${{ github.workspace }}/||g" > artifacts/changes.diff
97+
run: diff --strip-trailing-cr --recursive --exclude='.git' --exclude='version.php' ${{ github.workspace }}/build ${{ github.workspace }}/build-server | sed "s|${{ github.workspace }}/||g" > artifacts/changes.diff
9898

9999
- name: Save PR number
100100
run: echo "${EVENT_NUMBER}" > ./artifacts/NR

0 commit comments

Comments
 (0)