2023-12-09 21:49:47 +08:00
|
|
|
/* eslint-disable compat/compat */
|
|
|
|
/* eslint-disable no-console, no-await-in-loop, import/no-extraneous-dependencies, lodash/import-scope, no-restricted-syntax */
|
2023-12-21 10:30:08 +08:00
|
|
|
import { assert } from 'console';
|
2023-12-09 21:49:47 +08:00
|
|
|
import fs from 'fs';
|
|
|
|
import os from 'os';
|
2023-12-21 10:30:08 +08:00
|
|
|
import path from 'path';
|
2023-12-09 21:49:47 +08:00
|
|
|
import { Readable } from 'stream';
|
|
|
|
import { finished } from 'stream/promises';
|
|
|
|
import chalk from 'chalk';
|
2023-12-21 10:30:08 +08:00
|
|
|
import fse from 'fs-extra';
|
2023-12-09 21:49:47 +08:00
|
|
|
import _ from 'lodash';
|
2023-12-21 10:30:08 +08:00
|
|
|
import minimist from 'minimist';
|
2023-12-09 21:49:47 +08:00
|
|
|
import pixelmatch from 'pixelmatch';
|
|
|
|
import { PNG } from 'pngjs';
|
2023-12-21 10:30:08 +08:00
|
|
|
import { remark } from 'remark';
|
|
|
|
import remarkGfm from 'remark-gfm';
|
|
|
|
import remarkHtml from 'remark-html';
|
2023-12-09 21:49:47 +08:00
|
|
|
import sharp from 'sharp';
|
2023-12-21 10:30:08 +08:00
|
|
|
import tar from 'tar';
|
2023-12-09 21:49:47 +08:00
|
|
|
|
2024-02-06 12:52:43 +08:00
|
|
|
const ROOT_DIR = process.cwd();
|
2023-12-11 13:22:24 +08:00
|
|
|
const ALI_OSS_BUCKET = 'antd-visual-diff';
|
|
|
|
|
2024-02-06 12:52:43 +08:00
|
|
|
const REPORT_DIR = path.join(ROOT_DIR, './visualRegressionReport');
|
|
|
|
|
2023-12-15 21:06:40 +08:00
|
|
|
const isLocalEnv = process.env.LOCAL;
|
|
|
|
|
2023-12-09 21:49:47 +08:00
|
|
|
const compareScreenshots = async (
|
|
|
|
baseImgPath: string,
|
|
|
|
currentImgPath: string,
|
|
|
|
diffImagePath: string,
|
|
|
|
): Promise<number> => {
|
|
|
|
const baseImgBuf = await sharp(baseImgPath).toBuffer();
|
|
|
|
const currentImgBuf = await sharp(currentImgPath).toBuffer();
|
|
|
|
|
|
|
|
const basePng = PNG.sync.read(baseImgBuf);
|
2024-01-15 19:22:33 +08:00
|
|
|
const currentPng = PNG.sync.read(currentImgBuf);
|
|
|
|
|
|
|
|
const targetWidth = Math.max(basePng.width, currentPng.width);
|
|
|
|
const targetHeight = Math.max(basePng.height, currentPng.height);
|
|
|
|
|
|
|
|
// fill color for transparent png
|
|
|
|
const fillColor =
|
|
|
|
baseImgPath.endsWith('dark.png') || baseImgPath.endsWith('dark.css-var.png')
|
|
|
|
? { r: 0, g: 0, b: 0, alpha: 255 }
|
|
|
|
: { r: 255, g: 255, b: 255, alpha: 255 };
|
|
|
|
|
|
|
|
const resizeOptions = {
|
|
|
|
width: targetWidth,
|
|
|
|
height: targetHeight,
|
|
|
|
position: 'left top',
|
|
|
|
fit: sharp.fit.contain,
|
|
|
|
background: fillColor,
|
|
|
|
};
|
|
|
|
|
|
|
|
const resizedBasePng = PNG.sync.read(
|
|
|
|
await sharp(baseImgBuf).resize(resizeOptions).png().toBuffer(),
|
|
|
|
);
|
|
|
|
|
|
|
|
const resizedCurrentPng = PNG.sync.read(
|
|
|
|
await sharp(currentImgBuf).resize(resizeOptions).png().toBuffer(),
|
2023-12-09 21:49:47 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
const diffPng = new PNG({ width: targetWidth, height: targetHeight });
|
|
|
|
|
|
|
|
const mismatchedPixels = pixelmatch(
|
2024-01-15 19:22:33 +08:00
|
|
|
resizedBasePng.data,
|
|
|
|
resizedCurrentPng.data,
|
2023-12-09 21:49:47 +08:00
|
|
|
diffPng.data,
|
|
|
|
targetWidth,
|
|
|
|
targetHeight,
|
|
|
|
{ threshold: 0.1, diffMask: false },
|
|
|
|
);
|
|
|
|
|
|
|
|
// if mismatched then write diff image
|
|
|
|
if (mismatchedPixels) {
|
|
|
|
diffPng.pack().pipe(fs.createWriteStream(diffImagePath));
|
|
|
|
}
|
|
|
|
|
2023-12-18 14:25:40 +08:00
|
|
|
return mismatchedPixels / (targetWidth * targetHeight);
|
2023-12-09 21:49:47 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const readPngs = (dir: string) => fs.readdirSync(dir).filter((n) => n.endsWith('.png'));
|
|
|
|
|
|
|
|
const prettyList = (list: string[]) => list.map((i) => ` * ${i}`).join('\n');
|
|
|
|
|
2023-12-11 13:22:24 +08:00
|
|
|
const ossDomain = `https://${ALI_OSS_BUCKET}.oss-cn-shanghai.aliyuncs.com`;
|
2023-12-09 21:49:47 +08:00
|
|
|
|
|
|
|
async function downloadFile(url: string, destPath: string) {
|
|
|
|
const response = await fetch(url);
|
|
|
|
if (!response.ok || response.status !== 200) {
|
|
|
|
throw new Error(`Download file failed: ${new URL(url).pathname}`);
|
|
|
|
}
|
|
|
|
// @ts-ignore
|
|
|
|
const body = Readable.fromWeb(response.body);
|
|
|
|
await finished(body.pipe(fs.createWriteStream(destPath)));
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getBranchLatestRef(branchName: string) {
|
|
|
|
const baseImageRefUrl = `${ossDomain}/${branchName}/visual-regression-ref.txt`;
|
|
|
|
// get content from baseImageRefText
|
|
|
|
const res = await fetch(baseImageRefUrl);
|
|
|
|
const text = await res.text();
|
|
|
|
const ref = text.trim();
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function downloadBaseSnapshots(ref: string, targetDir: string) {
|
|
|
|
// download imageSnapshotsUrl
|
|
|
|
const imageSnapshotsUrl = `${ossDomain}/${ref}/imageSnapshots.tar.gz`;
|
|
|
|
const targzPath = path.resolve(os.tmpdir(), `./${path.basename(targetDir)}.tar.gz`);
|
|
|
|
await downloadFile(imageSnapshotsUrl, targzPath);
|
|
|
|
// untar
|
|
|
|
return tar.x({
|
2023-12-10 15:23:58 +08:00
|
|
|
// remove top-level dir
|
2023-12-09 21:49:47 +08:00
|
|
|
strip: 1,
|
|
|
|
C: targetDir,
|
|
|
|
file: targzPath,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
interface IBadCase {
|
|
|
|
type: 'removed' | 'changed';
|
|
|
|
filename: string;
|
2023-12-18 14:25:40 +08:00
|
|
|
/**
|
|
|
|
* 0 - 1
|
|
|
|
*/
|
|
|
|
weight: number;
|
2023-12-09 21:49:47 +08:00
|
|
|
}
|
|
|
|
|
2023-12-11 17:37:07 +08:00
|
|
|
function md2Html(md: string) {
|
|
|
|
return remark().use(remarkGfm).use(remarkHtml).processSync(md).toString();
|
|
|
|
}
|
|
|
|
|
2023-12-14 17:02:31 +08:00
|
|
|
function parseArgs() {
|
|
|
|
// parse args from -- --pr-id=123 --base_ref=feature
|
|
|
|
const argv = minimist(process.argv.slice(2));
|
|
|
|
const prId = argv['pr-id'];
|
|
|
|
assert(prId, 'Missing --pr-id');
|
|
|
|
const baseRef = argv['base-ref'];
|
|
|
|
assert(baseRef, 'Missing --base-ref');
|
|
|
|
return {
|
|
|
|
prId,
|
|
|
|
baseRef,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-12-11 17:37:07 +08:00
|
|
|
function generateReport(
|
|
|
|
badCases: IBadCase[],
|
|
|
|
targetBranch: string,
|
|
|
|
targetRef: string,
|
2023-12-14 17:02:31 +08:00
|
|
|
prId: string,
|
2023-12-11 17:37:07 +08:00
|
|
|
): [string, string] {
|
2024-02-06 12:52:43 +08:00
|
|
|
const reportDirname = path.basename(REPORT_DIR);
|
|
|
|
|
|
|
|
const publicPath = isLocalEnv ? '.' : `${ossDomain}/pr-${prId}/${reportDirname}`;
|
2023-12-09 21:49:47 +08:00
|
|
|
|
2023-12-18 14:25:40 +08:00
|
|
|
const passed = badCases.length === 0;
|
|
|
|
|
2023-12-10 23:37:16 +08:00
|
|
|
const commonHeader = `
|
2024-02-05 13:35:16 +08:00
|
|
|
## 👁 Visual Regression Report for PR #${prId} ${passed ? 'Passed ✅' : 'Failed ❌'}
|
|
|
|
> **🎯 Target branch:** ${targetBranch} (${targetRef})
|
2023-12-10 23:37:16 +08:00
|
|
|
`.trim();
|
|
|
|
|
2024-02-06 12:52:43 +08:00
|
|
|
const htmlReportLink = `${publicPath}/report.html`;
|
2024-02-05 13:35:16 +08:00
|
|
|
const addonFullReportDesc = `\n\nCheck <a href="${htmlReportLink}" target="_blank">Full Report</a> for details`;
|
|
|
|
|
2024-02-05 14:29:44 +08:00
|
|
|
const fullReport = `> 📖 <a href="${htmlReportLink}" target="_blank">View Full Report ↗︎</a>`;
|
2023-12-18 14:25:40 +08:00
|
|
|
if (passed) {
|
2023-12-11 17:37:07 +08:00
|
|
|
const mdStr = [
|
2023-12-10 23:37:16 +08:00
|
|
|
commonHeader,
|
2024-02-05 13:35:16 +08:00
|
|
|
fullReport,
|
2024-02-05 14:29:44 +08:00
|
|
|
'\n🎊 Congrats! No visual-regression diff found.\n',
|
2024-02-05 13:35:16 +08:00
|
|
|
'<img src="https://github.com/ant-design/ant-design/assets/507615/2d1a77dc-dbc6-4b0f-9cbc-19a43d3c29cd" width="300" />',
|
2023-12-10 23:37:16 +08:00
|
|
|
].join('\n');
|
2023-12-11 17:37:07 +08:00
|
|
|
|
|
|
|
return [mdStr, md2Html(mdStr)];
|
2023-12-10 23:37:16 +08:00
|
|
|
}
|
|
|
|
|
2023-12-09 21:49:47 +08:00
|
|
|
let reportMdStr = `
|
2023-12-10 23:37:16 +08:00
|
|
|
${commonHeader}
|
2024-02-05 13:35:16 +08:00
|
|
|
${fullReport}
|
2024-02-05 21:08:36 +08:00
|
|
|
|
2024-02-05 13:35:16 +08:00
|
|
|
| Image name | Expected | Actual | Diff |
|
2023-12-09 21:49:47 +08:00
|
|
|
| --- | --- | --- | --- |
|
|
|
|
`.trim();
|
2024-02-06 12:52:43 +08:00
|
|
|
|
2023-12-09 21:49:47 +08:00
|
|
|
reportMdStr += '\n';
|
|
|
|
|
2023-12-10 23:37:16 +08:00
|
|
|
let fullVersionMd = reportMdStr;
|
|
|
|
|
2023-12-21 10:30:08 +08:00
|
|
|
let diffCount = 0;
|
2023-12-10 23:37:16 +08:00
|
|
|
|
2023-12-09 21:49:47 +08:00
|
|
|
for (const badCase of badCases) {
|
|
|
|
const { filename, type } = badCase;
|
2023-12-10 23:37:16 +08:00
|
|
|
let lineReportMdStr = '';
|
2023-12-09 21:49:47 +08:00
|
|
|
if (type === 'changed') {
|
2023-12-10 23:37:16 +08:00
|
|
|
lineReportMdStr += '| ';
|
|
|
|
lineReportMdStr += [
|
2024-02-05 13:35:16 +08:00
|
|
|
`\`${badCase.filename}\``,
|
2024-02-06 12:52:43 +08:00
|
|
|
`![${targetBranch}: ${targetRef}](${publicPath}/images/base/${filename})`,
|
|
|
|
`![current: pr-${prId}](${publicPath}/images/current/${filename})`,
|
|
|
|
`![diff](${publicPath}/images/diff/${filename})`,
|
2023-12-09 21:49:47 +08:00
|
|
|
].join(' | ');
|
2023-12-10 23:37:16 +08:00
|
|
|
lineReportMdStr += ' |\n';
|
2023-12-09 21:49:47 +08:00
|
|
|
} else if (type === 'removed') {
|
2023-12-10 23:37:16 +08:00
|
|
|
lineReportMdStr += '| ';
|
|
|
|
lineReportMdStr += [
|
2024-02-05 13:35:16 +08:00
|
|
|
`\`${badCase.filename}\``,
|
2024-02-06 12:52:43 +08:00
|
|
|
`![${targetBranch}: ${targetRef}](${publicPath}/images/base/${filename})`,
|
2023-12-10 19:58:23 +08:00
|
|
|
`⛔️⛔️⛔️ Missing ⛔️⛔️⛔️`,
|
|
|
|
`🚨🚨🚨 Removed 🚨🚨🚨`,
|
2023-12-09 21:49:47 +08:00
|
|
|
].join(' | ');
|
2023-12-10 23:37:16 +08:00
|
|
|
lineReportMdStr += ' |\n';
|
|
|
|
}
|
|
|
|
|
2023-12-21 10:30:08 +08:00
|
|
|
diffCount += 1;
|
|
|
|
if (diffCount <= 10) {
|
|
|
|
reportMdStr += lineReportMdStr;
|
2023-12-09 21:49:47 +08:00
|
|
|
}
|
2023-12-21 10:30:08 +08:00
|
|
|
|
|
|
|
fullVersionMd += lineReportMdStr;
|
2023-12-09 21:49:47 +08:00
|
|
|
}
|
2023-12-10 23:37:16 +08:00
|
|
|
|
2023-12-21 10:30:08 +08:00
|
|
|
reportMdStr += addonFullReportDesc;
|
|
|
|
|
2023-12-10 23:37:16 +08:00
|
|
|
// convert fullVersionMd to html
|
2023-12-11 17:37:07 +08:00
|
|
|
return [reportMdStr, md2Html(fullVersionMd)];
|
2023-12-09 21:49:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
async function boot() {
|
2023-12-14 17:02:31 +08:00
|
|
|
const { prId, baseRef: targetBranch = 'master' } = parseArgs();
|
2023-12-13 12:42:24 +08:00
|
|
|
|
2024-02-06 12:52:43 +08:00
|
|
|
const baseImgSourceDir = path.resolve(ROOT_DIR, `./imageSnapshots-${targetBranch}`);
|
2023-12-09 21:49:47 +08:00
|
|
|
|
2023-12-18 14:25:40 +08:00
|
|
|
/* --- prepare stage --- */
|
2023-12-15 21:24:20 +08:00
|
|
|
console.log(
|
|
|
|
chalk.green(
|
|
|
|
`Preparing image snapshots from latest \`${targetBranch}\` branch for pr \`${prId}\`\n`,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
await fse.ensureDir(baseImgSourceDir);
|
2023-12-15 21:06:40 +08:00
|
|
|
|
2023-12-18 14:25:40 +08:00
|
|
|
const targetCommitSha = await getBranchLatestRef(targetBranch);
|
|
|
|
assert(targetCommitSha, `Missing commit sha from ${targetBranch}`);
|
2023-12-15 21:06:40 +08:00
|
|
|
|
2023-12-15 21:24:20 +08:00
|
|
|
if (!isLocalEnv) {
|
2023-12-18 14:25:40 +08:00
|
|
|
await downloadBaseSnapshots(targetCommitSha, baseImgSourceDir);
|
2023-12-15 21:24:20 +08:00
|
|
|
} else if (!fse.existsSync(baseImgSourceDir)) {
|
|
|
|
console.log(
|
|
|
|
chalk.yellow(
|
|
|
|
`Please prepare image snapshots in folder \`$projectRoot/${path.basename(
|
|
|
|
baseImgSourceDir,
|
|
|
|
)}\` from latest \`${targetBranch}\` branch`,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
process.exit(1);
|
2023-12-15 21:06:40 +08:00
|
|
|
}
|
2023-12-09 21:49:47 +08:00
|
|
|
|
2024-02-06 12:52:43 +08:00
|
|
|
const currentImgSourceDir = path.resolve(ROOT_DIR, './imageSnapshots');
|
2023-12-09 21:49:47 +08:00
|
|
|
|
|
|
|
// save diff images(x3) to reportDir
|
2024-02-06 12:52:43 +08:00
|
|
|
const diffImgReportDir = path.resolve(REPORT_DIR, './images/diff');
|
|
|
|
const baseImgReportDir = path.resolve(REPORT_DIR, './images/base');
|
|
|
|
const currentImgReportDir = path.resolve(REPORT_DIR, './images/current');
|
2023-12-09 21:49:47 +08:00
|
|
|
|
|
|
|
await fse.ensureDir(diffImgReportDir);
|
|
|
|
await fse.ensureDir(baseImgReportDir);
|
|
|
|
await fse.ensureDir(currentImgReportDir);
|
|
|
|
|
2023-12-10 15:23:58 +08:00
|
|
|
console.log(chalk.blue('⛳ Checking image snapshots with branch %s'), targetBranch);
|
2023-12-09 21:49:47 +08:00
|
|
|
console.log('\n');
|
|
|
|
|
|
|
|
const baseImgFileList = readPngs(baseImgSourceDir);
|
|
|
|
|
2023-12-18 14:25:40 +08:00
|
|
|
/* --- compare stage --- */
|
2023-12-09 21:49:47 +08:00
|
|
|
const badCases: IBadCase[] = [];
|
|
|
|
|
2023-12-13 12:42:24 +08:00
|
|
|
// compare cssinjs and css-var png from pr
|
|
|
|
// to the same cssinjs png in `master` branch
|
|
|
|
const cssInJsImgNames = baseImgFileList
|
|
|
|
.filter((i) => !i.endsWith('.css-var.png'))
|
|
|
|
.map((n) => path.basename(n, path.extname(n)));
|
|
|
|
|
|
|
|
for (const basename of cssInJsImgNames) {
|
|
|
|
for (const extname of ['.png', '.css-var.png']) {
|
|
|
|
// baseImg always use cssinjs png
|
|
|
|
const baseImgName = `${basename}.png`;
|
|
|
|
const baseImgPath = path.join(baseImgSourceDir, baseImgName);
|
|
|
|
|
|
|
|
// currentImg use cssinjs png or css-var png
|
|
|
|
const compareImgName = basename + extname;
|
|
|
|
const currentImgPath = path.join(currentImgSourceDir, compareImgName);
|
|
|
|
const diffImgPath = path.join(diffImgReportDir, compareImgName);
|
|
|
|
|
|
|
|
const currentImgExists = await fse.exists(currentImgPath);
|
|
|
|
if (!currentImgExists) {
|
|
|
|
console.log(chalk.red(`⛔️ Missing image: ${compareImgName}\n`));
|
|
|
|
badCases.push({
|
|
|
|
type: 'removed',
|
|
|
|
filename: compareImgName,
|
2023-12-18 14:25:40 +08:00
|
|
|
weight: 1,
|
2023-12-13 12:42:24 +08:00
|
|
|
});
|
|
|
|
await fse.copy(baseImgPath, path.join(baseImgReportDir, compareImgName));
|
|
|
|
continue;
|
|
|
|
}
|
2023-12-09 21:49:47 +08:00
|
|
|
|
2023-12-13 12:42:24 +08:00
|
|
|
const mismatchedPxPercent = await compareScreenshots(
|
|
|
|
baseImgPath,
|
|
|
|
currentImgPath,
|
|
|
|
diffImgPath,
|
2023-12-09 21:49:47 +08:00
|
|
|
);
|
2023-12-13 12:42:24 +08:00
|
|
|
|
|
|
|
if (mismatchedPxPercent > 0) {
|
|
|
|
console.log(
|
|
|
|
'Mismatched pixels for:',
|
|
|
|
chalk.yellow(compareImgName),
|
2023-12-18 14:25:40 +08:00
|
|
|
`${(mismatchedPxPercent * 100).toFixed(2)}%\n`,
|
2023-12-13 12:42:24 +08:00
|
|
|
);
|
|
|
|
// copy compare imgs(x2) to report dir
|
|
|
|
await fse.copy(baseImgPath, path.join(baseImgReportDir, compareImgName));
|
|
|
|
await fse.copy(currentImgPath, path.join(currentImgReportDir, compareImgName));
|
|
|
|
|
|
|
|
badCases.push({
|
|
|
|
type: 'changed',
|
|
|
|
filename: compareImgName,
|
2023-12-18 14:25:40 +08:00
|
|
|
weight: mismatchedPxPercent,
|
2023-12-13 12:42:24 +08:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
console.log('Passed for: %s\n', chalk.green(compareImgName));
|
|
|
|
}
|
2023-12-09 21:49:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-12-18 14:25:40 +08:00
|
|
|
/* --- generate report stage --- */
|
2023-12-09 21:49:47 +08:00
|
|
|
const jsonl = badCases.map((i) => JSON.stringify(i)).join('\n');
|
|
|
|
// write jsonl and markdown report to diffImgDir
|
2024-02-06 12:52:43 +08:00
|
|
|
await fse.writeFile(path.join(REPORT_DIR, './report.jsonl'), jsonl);
|
2023-12-18 14:25:40 +08:00
|
|
|
const [reportMdStr, reportHtmlStr] = generateReport(
|
|
|
|
badCases,
|
|
|
|
targetBranch,
|
|
|
|
targetCommitSha,
|
|
|
|
prId,
|
|
|
|
);
|
2024-02-06 12:52:43 +08:00
|
|
|
await fse.writeFile(path.join(REPORT_DIR, './report.md'), reportMdStr);
|
2023-12-11 17:37:07 +08:00
|
|
|
const htmlTemplate = await fse.readFile(path.join(__dirname, './report-template.html'), 'utf8');
|
|
|
|
|
|
|
|
await fse.writeFile(
|
2024-02-06 12:52:43 +08:00
|
|
|
path.join(REPORT_DIR, './report.html'),
|
2023-12-11 17:37:07 +08:00
|
|
|
htmlTemplate.replace('{{reportContent}}', reportHtmlStr),
|
|
|
|
'utf-8',
|
|
|
|
);
|
2023-12-09 21:49:47 +08:00
|
|
|
|
|
|
|
await tar.c(
|
|
|
|
{
|
|
|
|
gzip: true,
|
2023-12-10 15:23:58 +08:00
|
|
|
// ignore top-level dir(e.g. visualRegressionReport) and zip all files in it
|
2024-02-06 12:52:43 +08:00
|
|
|
cwd: REPORT_DIR,
|
|
|
|
file: `${path.basename(REPORT_DIR)}.tar.gz`,
|
2023-12-09 21:49:47 +08:00
|
|
|
},
|
2024-02-06 12:52:43 +08:00
|
|
|
await fse.readdir(REPORT_DIR),
|
2023-12-09 21:49:47 +08:00
|
|
|
);
|
2023-12-18 14:25:40 +08:00
|
|
|
|
|
|
|
const currentImgFileList = readPngs(currentImgSourceDir);
|
|
|
|
/* --- text report stage --- */
|
|
|
|
console.log(
|
|
|
|
chalk.blue(`📊 Text report from pr #${prId} comparing to ${targetBranch}@${targetCommitSha}\n`),
|
|
|
|
);
|
|
|
|
// new images
|
|
|
|
const newImgs = _.difference(currentImgFileList, baseImgFileList);
|
|
|
|
if (newImgs.length) {
|
|
|
|
console.log(chalk.green(`🆕 ${newImgs.length} images added from this pr`));
|
2023-12-18 17:10:22 +08:00
|
|
|
console.log(chalk.green('🆕 Added images list:\n'));
|
|
|
|
console.log(prettyList(newImgs));
|
2023-12-18 14:25:40 +08:00
|
|
|
console.log('\n');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!badCases.length) {
|
|
|
|
console.log(chalk.green('🎉 All passed!'));
|
|
|
|
console.log('\n');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const sortedBadCases = badCases.sort((a, b) => b.weight - a.weight);
|
2023-12-18 17:10:22 +08:00
|
|
|
console.log(chalk.red('⛔️ Failed cases:\n'));
|
|
|
|
console.log(prettyList(sortedBadCases.map((i) => `[${i.type}] ${i.filename}`)));
|
2023-12-18 14:25:40 +08:00
|
|
|
console.log('\n');
|
|
|
|
// let job failed
|
|
|
|
process.exit(1);
|
2023-12-09 21:49:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
boot();
|