ci: Adjust to duplicate write status (#49005)

* chore: diff for it

* chore: status
This commit is contained in:
二货爱吃白萝卜 2024-05-21 14:42:29 +08:00 committed by GitHub
parent 4b44c737b9
commit 9b916f6f32
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -59,6 +59,7 @@ jobs:
actions: read # for dawidd6/action-download-artifact to query and download artifacts
issues: write # for actions-cool/maintain-one-comment to modify or create issue comments
pull-requests: write # for actions-cool/maintain-one-comment to modify or create PR comments
statuses: write
runs-on: ubuntu-latest
needs: [upstream-workflow-summary]
steps:
@ -141,29 +142,31 @@ jobs:
body-include: '<!-- VISUAL_DIFF_REGRESSION_HOOK -->'
number: ${{ steps.pr.outputs.id }}
# Update PR description with updated time: `snapshot:[TIMESTAMP]`
- name: Update timestamp
if: ${{ always() }}
# Resync commit status. This will be also reset by `visual-regression-diff-approver`
- name: Reset Commit Status
uses: actions/github-script@v7
if: ${{ steps.report.outcome == 'success' }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const timestamp = Date.now();
const prNumber = ${{ steps.pr.outputs.id }};
const { data } = await github.rest.pulls.get({
const prResponse = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
pull_number: ${{ steps.pr.outputs.id }},
});
const { body: currentBody } = data;
const prHeadSha = prResponse.data.head.sha;
let newBody = currentBody.replace(/<!-- timestamp:[^>]-->/, '').trim();
newBody = newBody + `\n\n<!-- timestamp: ${timestamp} -->`;
const fullContent = `${{ toJSON(steps.report.outputs.content) }}`;
const hasVisualDiffSuccess = fullContent.includes('VISUAL_DIFF_SUCCESS');
const hasVisualDiffFailed = fullContent.includes('VISUAL_DIFF_FAILED');
github.rest.pulls.update({
const mergedStatus = hasVisualDiffSuccess ? 'success' : hasVisualDiffFailed ? 'failure' : 'pending';
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
body: newBody
});
sha: prHeadSha,
state: mergedStatus,
context: 'Visual Regression Diff Wait Approve',
description: hasVisualDiffSuccess ? 'Visual diff check pass' : 'Visual diff check failed',
});