diff --git a/.github/workflows/visual-regression-diff-approver.yml b/.github/workflows/visual-regression-diff-approver.yml index 186ab6097f..b0244d0344 100644 --- a/.github/workflows/visual-regression-diff-approver.yml +++ b/.github/workflows/visual-regression-diff-approver.yml @@ -1,6 +1,6 @@ # Check the report passed or developer confirmed the diff -name: 🤖 Visual Regression Diff Approver +name: 🤖 Visual Regression Diff Approval # on comment event on: @@ -11,9 +11,9 @@ permissions: contents: read jobs: - rebase: + approval: permissions: - pull-requests: read + pull-requests: write name: Check Virtual Regression Approval if: github.event.issue.pull_request != '' runs-on: ubuntu-latest @@ -25,13 +25,27 @@ jobs: id: check_approval uses: actions/github-script@v7 with: + github-token: ${{ secrets.GITHUB_TOKEN }} script: | + const issue_number = context.payload.issue.number; + console.log('PR:', issue_number); + + const prResponse = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: issue_number, + }); + const prHeadSha = prResponse.data.head.sha; + console.log('Head SHA:', prHeadSha); + const { data: comments } = await github.rest.issues.listComments({ owner: context.repo.owner, repo: context.repo.repo, - issue_number: context.issue.number, + issue_number: issue_number }); + console.log('Comments:', comments.length); + let hasDiffSuccess = false; let hasDiffFailed = false; let hasMemberApprove = false; @@ -48,6 +62,23 @@ jobs: } } + console.log('hasDiffSuccess:', hasDiffSuccess); + console.log('hasDiffFailed:', hasDiffFailed); + console.log('hasMemberApprove:', hasMemberApprove); + + const diffPassed = hasDiffSuccess || (hasDiffFailed && hasMemberApprove); + 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', + }); + if (hasDiffSuccess || (hasDiffFailed && hasMemberApprove)) { return 'success'; } else if (hasDiffFailed) { @@ -56,9 +87,6 @@ jobs: return 'waiting'; } - # Console need approve message and throw failure if the result is `failed` - - name: Fail if Visual Diff Failed - if: steps.check_approval.outputs.result == 'failed' - run: | - echo "Visual Diff Failed, please check the diff and approve it." - exit 1 + # Console check_approval status + - name: Console Status + run: echo "Result -> ${{ steps.check_approval.outputs.result }}" diff --git a/.github/workflows/visual-regression-diff-finish.yml b/.github/workflows/visual-regression-diff-finish.yml index 095290e6dd..b391247e4c 100644 --- a/.github/workflows/visual-regression-diff-finish.yml +++ b/.github/workflows/visual-regression-diff-finish.yml @@ -140,3 +140,30 @@ jobs: body-include: '' number: ${{ steps.pr.outputs.id }} + + # Update PR description with updated time: `snapshot:[TIMESTAMP]` + - name: Update timestamp + if: ${{ always() }} + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const timestamp = Date.now(); + + const prNumber = ${{ steps.pr.outputs.id }}; + const { data } = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: prNumber + }); + const { body: currentBody } = data; + + let newBody = currentBody.replace(//, '').trim(); + newBody = newBody + `\n\n`; + + github.rest.pulls.update({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: prNumber, + body: newBody + }); \ No newline at end of file