mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 02:59:58 +08:00
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
This commit is contained in:
parent
ecfdc05b21
commit
61aa6407b3
@ -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 }}"
|
||||
|
@ -140,3 +140,30 @@ jobs:
|
||||
<!-- VISUAL_DIFF_REGRESSION_HOOK -->
|
||||
body-include: '<!-- VISUAL_DIFF_REGRESSION_HOOK -->'
|
||||
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(/<!-- timestamp:[^>]-->/, '').trim();
|
||||
newBody = newBody + `\n\n<!-- timestamp: ${timestamp} -->`;
|
||||
|
||||
github.rest.pulls.update({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
pull_number: prNumber,
|
||||
body: newBody
|
||||
});
|
Loading…
Reference in New Issue
Block a user