From 2116659f52ba9bdc083ab0956a36ad633ccaadce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Thu, 21 Nov 2024 10:14:55 +0800 Subject: [PATCH] chore: use single update status of diff action --- .../visual-regression-diff-approver.yml | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/.github/workflows/visual-regression-diff-approver.yml b/.github/workflows/visual-regression-diff-approver.yml index 5b0fbb8f7a..4c8b4b88e6 100644 --- a/.github/workflows/visual-regression-diff-approver.yml +++ b/.github/workflows/visual-regression-diff-approver.yml @@ -77,15 +77,26 @@ jobs: const mergedStatus = diffPassed ? 'success' : hasDiffFailed ? 'failure' : 'pending'; console.log('Status:', mergedStatus); - await github.rest.repos.createCommitStatus({ - owner: context.repo.owner, - repo: context.repo.repo, - sha: prHeadSha, - state: mergedStatus, - context: 'Visual Regression Diff Wait Approve', - description: diffPassed ? 'Visual diff is acceptable' : 'Visual diff is not pass', + const { data: currentStatuses } = await github.rest.repos.listCommitStatusesForRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: prHeadSha, }); + const currentStatus = currentStatuses.find(status => status.context === 'Visual Regression Diff Wait Approve'); + if (currentStatus && currentStatus.state === mergedStatus) { + console.log('Status has not changed, no need to update:', currentStatus.state); + } else { + await github.rest.repos.createCommitStatus({ + owner: context.repo.owner, + repo: context.repo.repo, + sha: prHeadSha, + state: mergedStatus, + context: 'Visual Regression Diff Wait Approve', + description: diffPassed ? 'Visual diff is acceptable' : 'Visual diff is not pass', + }); + } + if (hasDiffSuccess || (hasDiffFailed && hasMemberApprove)) { return 'success'; } else if (hasDiffFailed) {