ant-design/.github/workflows/visual-regression-diff-approver.yml
二货爱吃白萝卜 61aa6407b3
ci: adjust approve (#48998)
* chore: simple code

* chore: more info

* chore: rename

* chore: rename

* chore: rename

* chore: adjust comment trigger

* chore: add auto comment update
2024-05-21 10:47:07 +08:00

93 lines
3.0 KiB
YAML

# Check the report passed or developer confirmed the diff
name: 🤖 Visual Regression Diff Approval
# on comment event
on:
issue_comment:
types: [created, edited, deleted]
permissions:
contents: read
jobs:
approval:
permissions:
pull-requests: write
name: Check Virtual Regression Approval
if: github.event.issue.pull_request != ''
runs-on: ubuntu-latest
steps:
# Check all the comments if contains `VISUAL_DIFF_SUCCESS` or `VISUAL_DIFF_FAILED`
# Check if member of repo comment `Pass Visual Diff`
# Return type: `success` or `failed` or `waiting`
- name: Statistic Visual Diff Approval
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: issue_number
});
console.log('Comments:', comments.length);
let hasDiffSuccess = false;
let hasDiffFailed = false;
let hasMemberApprove = false;
for (const comment of comments) {
if (comment.body.includes('VISUAL_DIFF_SUCCESS')) {
hasDiffSuccess = true;
}
if (comment.body.includes('VISUAL_DIFF_FAILED')) {
hasDiffFailed = true;
}
if (comment.body.includes('- [x] Visual diff is acceptable')) {
hasMemberApprove = true;
}
}
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) {
return 'failed';
} else {
return 'waiting';
}
# Console check_approval status
- name: Console Status
run: echo "Result -> ${{ steps.check_approval.outputs.result }}"