@@ -101,15 +101,32 @@ jobs:
101101 retention-days : 30
102102
103103 - name : Comment PR with Playwright artifact link
104- if : failure () && github.event_name == 'pull_request'
104+ if : always () && github.event_name == 'pull_request'
105105 uses : actions/github-script@v7
106106 with :
107107 script : |
108108 const runId = context.runId;
109109 const repo = context.repo;
110110 const artifactUrl = `https://github.com/${repo.owner}/${repo.repo}/actions/runs/${runId}`;
111+ const identifier = '<!-- playwright-test-status -->';
111112
112- const comment = `## ❌ Playwright Tests Failed
113+ // Find existing comment
114+ const { data: comments } = await github.rest.issues.listComments({
115+ issue_number: context.issue.number,
116+ owner: repo.owner,
117+ repo: repo.repo,
118+ });
119+
120+ const existingComment = comments.find(comment =>
121+ comment.body?.includes(identifier)
122+ );
123+
124+ // Determine if tests passed or failed
125+ const testsFailed = '${{ job.status }}' !== 'success';
126+
127+ if (testsFailed) {
128+ const comment = `${identifier}
129+ ## ❌ Playwright Tests Failed
113130
114131 The Playwright tests have failed. Please download the test report artifact to see detailed information about the failures:
115132
@@ -123,12 +140,29 @@ jobs:
123140
124141 The report includes screenshots, videos, and detailed traces of the failed tests.`;
125142
126- github.rest.issues.createComment({
127- issue_number: context.issue.number,
128- owner: repo.owner,
129- repo: repo.repo,
130- body: comment
131- });
143+ if (existingComment) {
144+ await github.rest.issues.updateComment({
145+ owner: repo.owner,
146+ repo: repo.repo,
147+ comment_id: existingComment.id,
148+ body: comment
149+ });
150+ } else {
151+ await github.rest.issues.createComment({
152+ issue_number: context.issue.number,
153+ owner: repo.owner,
154+ repo: repo.repo,
155+ body: comment
156+ });
157+ }
158+ } else if (existingComment) {
159+ // Tests passed - delete the failure comment
160+ await github.rest.issues.deleteComment({
161+ owner: repo.owner,
162+ repo: repo.repo,
163+ comment_id: existingComment.id
164+ });
165+ }
132166
133167 report_coverage :
134168 runs-on : ubuntu-latest
0 commit comments