Skip to content

Commit a7f0ef9

Browse files
denikIsaac
andcommitted
ci: delete the regression report comment when no tests are selected anymore
Co-authored-by: Isaac <no-reply@databricks.com>
1 parent 901fc4a commit a7f0ef9

1 file changed

Lines changed: 18 additions & 15 deletions

File tree

‎.github/workflows/regression-report.yml‎

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,32 @@ jobs:
5959
if-no-files-found: ignore
6060
retention-days: 7
6161

62-
# No report means no acceptance tests were changed, which needs no comment.
63-
- name: Post or update PR comment
62+
# No report means no acceptance tests are changed (anymore), so there is nothing to
63+
# comment: drop the comment of an earlier commit instead of leaving it stale.
64+
- name: Post, update or delete PR comment
6465
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
6566
with:
6667
script: |-
6768
const fs = require('fs');
6869
const path = process.env.GITHUB_WORKSPACE + '/regression_report.md';
69-
if (!fs.existsSync(path)) {
70-
core.info('No regression report, nothing to post');
71-
return;
72-
}
7370
7471
// Other comments by the same bot are left alone: ours is found by this marker.
7572
const MARKER = '<!-- regression-test-report -->';
7673
const { owner, repo } = context.repo;
74+
const issue_number = context.issue.number;
75+
const comments = await github.paginate(github.rest.issues.listComments, {
76+
owner, repo, issue_number,
77+
});
78+
const existing = comments.find(c =>
79+
c.user.login === 'github-actions[bot]' && c.body && c.body.startsWith(MARKER));
80+
81+
if (!fs.existsSync(path)) {
82+
if (existing) {
83+
await github.rest.issues.deleteComment({ owner, repo, comment_id: existing.id });
84+
}
85+
return;
86+
}
87+
7788
const sha = context.payload.pull_request.head.sha;
7889
const runUrl = `${context.serverUrl}/${owner}/${repo}/actions/runs/${context.runId}`;
7990
const commitUrl = `${context.serverUrl}/${owner}/${repo}/commit/${sha}`;
@@ -87,16 +98,8 @@ jobs:
8798
8899
const body = `${MARKER}\nCommit: [\`${sha.slice(0, 9)}\`](${commitUrl}) | [Workflow run](${runUrl})\n\n${report}`;
89100
90-
const comments = await github.paginate(github.rest.issues.listComments, {
91-
owner, repo, issue_number: context.issue.number,
92-
});
93-
const existing = comments.find(c =>
94-
c.user.login === 'github-actions[bot]' && c.body && c.body.startsWith(MARKER));
95-
96101
if (existing) {
97102
await github.rest.issues.updateComment({ owner, repo, comment_id: existing.id, body });
98103
} else {
99-
await github.rest.issues.createComment({
100-
owner, repo, issue_number: context.issue.number, body,
101-
});
104+
await github.rest.issues.createComment({ owner, repo, issue_number, body });
102105
}

0 commit comments

Comments
 (0)