2023-12-09 21:49:47 +08:00
|
|
|
# Each PR will visual-regression diff that help to check code is work as expect.
|
|
|
|
|
|
|
|
name: 👀 Visual Regression Diff Finish
|
|
|
|
|
|
|
|
on:
|
|
|
|
workflow_run:
|
|
|
|
workflows: ["👀 Visual Regression Diff Build"]
|
|
|
|
types:
|
|
|
|
- completed
|
|
|
|
|
|
|
|
permissions:
|
|
|
|
contents: read
|
|
|
|
|
|
|
|
jobs:
|
|
|
|
upstream-workflow-summary:
|
|
|
|
name: upstream workflow summary
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
outputs:
|
|
|
|
jobs: ${{ steps.visual_diff_build_job_status.outputs.result }}
|
|
|
|
build-success: ${{ steps.visual_diff_build_job_status.outputs.build-success }}
|
|
|
|
build-failure: ${{ steps.visual_diff_build_job_status.outputs.build-failure }}
|
|
|
|
steps:
|
|
|
|
- name: summary jobs status
|
|
|
|
uses: actions/github-script@v6
|
|
|
|
id: visual_diff_build_job_status
|
|
|
|
with:
|
|
|
|
script: |
|
|
|
|
const response = await github.rest.actions.listJobsForWorkflowRun({
|
|
|
|
owner: context.repo.owner,
|
|
|
|
repo: context.repo.repo,
|
|
|
|
run_id: ${{ github.event.workflow_run.id }},
|
|
|
|
});
|
|
|
|
|
|
|
|
// { [name]: [conclusion] }, e.g. { 'test image': 'success' }
|
|
|
|
const jobs = (response.data?.jobs ?? []).reduce((acc, job) => {
|
|
|
|
if(job?.status === 'completed' && 'name' in job && 'conclusion' in job) {
|
|
|
|
acc[job.name] = job.conclusion;
|
|
|
|
}
|
|
|
|
return acc;
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
const total = Object.keys(jobs).length;
|
|
|
|
if(total === 0) core.setFailed('no jobs found');
|
|
|
|
|
|
|
|
// the name here must be the same as `jobs.xxx.{name}` in preview-build.yml
|
|
|
|
// set output
|
|
|
|
core.setOutput('build-success', jobs['visual-diff report'] === 'success');
|
|
|
|
core.setOutput('build-failure', jobs['visual-diff report'] === 'failure');
|
|
|
|
return jobs;
|
|
|
|
|
|
|
|
download-visual-regression-report:
|
|
|
|
name: download visual-regression report
|
|
|
|
permissions:
|
|
|
|
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
|
|
|
|
runs-on: ubuntu-latest
|
2023-12-09 23:54:58 +08:00
|
|
|
needs: [upstream-workflow-summary]
|
2023-12-09 21:49:47 +08:00
|
|
|
steps:
|
2023-12-10 12:44:39 +08:00
|
|
|
- name: checkout
|
|
|
|
uses: actions/checkout@v4
|
|
|
|
|
2023-12-09 21:49:47 +08:00
|
|
|
# We need get persist-index first
|
|
|
|
- name: download image snapshot artifact
|
|
|
|
uses: dawidd6/action-download-artifact@v2
|
|
|
|
with:
|
|
|
|
workflow: ${{ github.event.workflow_run.workflow_id }}
|
|
|
|
run_id: ${{ github.event.workflow_run.id }}
|
|
|
|
name: visual-regression-diff-ref
|
|
|
|
|
|
|
|
# Save PR id to output
|
|
|
|
- name: save PR id
|
|
|
|
id: pr
|
|
|
|
run: echo "id=$(<visual-regression-pr-id.txt)" >> $GITHUB_OUTPUT
|
|
|
|
|
|
|
|
# Download report artifact
|
|
|
|
- name: download report artifact
|
|
|
|
if: ${{ fromJSON(needs.upstream-workflow-summary.outputs.build-success) }}
|
|
|
|
uses: dawidd6/action-download-artifact@v2
|
|
|
|
with:
|
|
|
|
workflow: ${{ github.event.workflow_run.workflow_id }}
|
|
|
|
run_id: ${{ github.event.workflow_run.id }}
|
|
|
|
name: visual-regression-report
|
|
|
|
|
|
|
|
# unzip report and then upload them to oss
|
|
|
|
- name: upload visual-regression report
|
|
|
|
id: report
|
|
|
|
env:
|
|
|
|
ALI_OSS_AK_ID: ${{ secrets.ALI_OSS_AK_ID }}
|
|
|
|
ALI_OSS_AK_SECRET: ${{ secrets.ALI_OSS_AK_SECRET }}
|
|
|
|
ALI_OSS_BUCKET: ${{ secrets.ALI_OSS_BUCKET }}
|
|
|
|
run: |
|
2023-12-10 11:43:00 +08:00
|
|
|
tar -xzvf visualRegressionReport.tar.gz
|
2023-12-09 21:49:47 +08:00
|
|
|
echo "✅ Uncompress Finished"
|
|
|
|
|
|
|
|
rm package.json
|
|
|
|
npm i ali-oss --no-save
|
|
|
|
echo "✅ Install `ali-oss` Finished"
|
|
|
|
|
|
|
|
echo "🤖 Uploading"
|
|
|
|
node scripts/visual-regression/upload.js ./visualRegressionReport --ref=pr-${{ steps.pr.outputs.id }}
|
|
|
|
echo "✅ Uploaded"
|
|
|
|
|
|
|
|
echo "content=$(<visualRegressionReport/report.md)" >> $GITHUB_OUTPUT
|
|
|
|
|
|
|
|
- name: success comment
|
|
|
|
uses: actions-cool/maintain-one-comment@v3
|
|
|
|
if: ${{ steps.report.outcome == 'success' }}
|
|
|
|
with:
|
|
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
body: |
|
|
|
|
Visual-Regression Report Success
|
|
|
|
🥳 ✅ 📊 🎉 🎈
|
|
|
|
${{ steps.report.outputs.content }}
|
|
|
|
<!-- VISUAL_DIFF_REGRESSION_HOOK -->
|
|
|
|
body-include: '<!-- VISUAL_DIFF_REGRESSION_HOOK -->'
|
|
|
|
number: ${{ steps.pr.outputs.id }}
|
|
|
|
|
|
|
|
- name: failed comment
|
|
|
|
if: ${{ fromJSON(needs.upstream-workflow-summary.outputs.build-failure) || steps.report.outcome == 'failure' || failure() }}
|
|
|
|
uses: actions-cool/maintain-one-comment@v3
|
|
|
|
with:
|
|
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
body: |
|
|
|
|
Visual-Regression Report Failed
|
|
|
|
😔 📉 📊 ❌ 🚫
|
|
|
|
<!-- VISUAL_DIFF_REGRESSION_HOOK -->
|
|
|
|
body-include: '<!-- VISUAL_DIFF_REGRESSION_HOOK -->'
|
|
|
|
number: ${{ steps.pr.outputs.id }}
|