mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-15 13:38:29 +02:00
chore: update checker logic (#53371)
This commit is contained in:
parent
8686e82fe1
commit
8af609a0b4
1 changed files with 15 additions and 44 deletions
|
@ -4,8 +4,9 @@ import { Octokit } from '@octokit/rest';
|
|||
import AdmZip from 'adm-zip';
|
||||
import axios from 'axios';
|
||||
import chalk from 'chalk';
|
||||
import Spinnies from 'spinnies';
|
||||
import dotnev from 'dotenv';
|
||||
import Spinnies from 'spinnies';
|
||||
|
||||
import checkRepo from './check-repo';
|
||||
|
||||
dotnev.config({ override: true });
|
||||
|
@ -13,13 +14,9 @@ dotnev.config({ override: true });
|
|||
const { Notification: Notifier } = require('node-notifier');
|
||||
const simpleGit = require('simple-git');
|
||||
|
||||
const blockStatus = ['failure', 'cancelled', 'timed_out'] as const;
|
||||
|
||||
const spinner = { interval: 80, frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'] };
|
||||
const spinnies = new Spinnies({ spinner });
|
||||
|
||||
const IGNORE_ACTIONS = ['Check Virtual Regression Approval', 'issue-remove-inactive'];
|
||||
|
||||
let spinniesId = 0;
|
||||
|
||||
// `spinnies` 为按条目进度,需要做简单的封装变成接近 `ora` 的形态
|
||||
|
@ -67,27 +64,6 @@ process.on('SIGINT', () => {
|
|||
process.exit(1);
|
||||
});
|
||||
|
||||
const emojify = (status = '') => {
|
||||
if (!status) {
|
||||
return '';
|
||||
}
|
||||
const emoji = {
|
||||
/* status */
|
||||
completed: '✅',
|
||||
queued: '🕒',
|
||||
in_progress: '⌛',
|
||||
/* conclusion */
|
||||
success: '✅',
|
||||
failure: '❌',
|
||||
neutral: '⚪',
|
||||
cancelled: '❌',
|
||||
skipped: '⏭️',
|
||||
timed_out: '⌛',
|
||||
action_required: '🔴',
|
||||
}[status];
|
||||
return `${emoji || ''} ${(status || '').padEnd(15)}`;
|
||||
};
|
||||
|
||||
const toMB = (bytes: number) => (bytes / 1024 / 1024).toFixed(2);
|
||||
|
||||
async function downloadArtifact(msgKey: string, url: string, filepath: string, token?: string) {
|
||||
|
@ -144,26 +120,15 @@ const runPrePublish = async () => {
|
|||
showMessage(`开始检查远程分支 ${currentBranch} 的 CI 状态`, true);
|
||||
|
||||
const failureUrlList: string[] = [];
|
||||
let {
|
||||
data: { check_runs },
|
||||
} = await octokit.checks.listForRef({
|
||||
|
||||
const { data } = await octokit.rest.repos.getCombinedStatusForRef({
|
||||
owner,
|
||||
repo,
|
||||
ref: sha,
|
||||
filter: 'all',
|
||||
});
|
||||
showMessage(`远程分支 CI 状态(${check_runs.length}):`, 'succeed');
|
||||
check_runs = check_runs.filter((run) =>
|
||||
IGNORE_ACTIONS.every((action) => !run.name.includes(action)),
|
||||
);
|
||||
check_runs.forEach((run) => {
|
||||
showMessage(` ${run.name.padEnd(36)} ${emojify(run.status)} ${emojify(run.conclusion || '')}`);
|
||||
if (blockStatus.some((status) => run.conclusion === status)) {
|
||||
failureUrlList.push(run.html_url!);
|
||||
}
|
||||
});
|
||||
const conclusions = check_runs.map((run) => run.conclusion);
|
||||
if (blockStatus.some((status) => conclusions.includes(status))) {
|
||||
|
||||
showMessage(`远程分支 CI 状态:${data.state}`, 'succeed');
|
||||
if (data.state === 'failure') {
|
||||
showMessage(chalk.bgRedBright('远程分支 CI 执行异常,无法继续发布,请尝试修复或重试'), 'fail');
|
||||
showMessage(` 点此查看状态:https://github.com/${owner}/${repo}/commit/${sha}`);
|
||||
|
||||
|
@ -174,12 +139,18 @@ const runPrePublish = async () => {
|
|||
process.exit(1);
|
||||
}
|
||||
|
||||
const statuses = check_runs.map((run) => run.status);
|
||||
if (check_runs.length < 1 || statuses.includes('queued') || statuses.includes('in_progress')) {
|
||||
if (data.state === 'pending') {
|
||||
showMessage(chalk.bgRedBright('远程分支 CI 还在执行中,请稍候再试'), 'fail');
|
||||
showMessage(` 点此查看状态:https://github.com/${owner}/${repo}/commit/${sha}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
if (data.state !== 'success') {
|
||||
showMessage(chalk.bgRedBright('远程分支 CI 状态异常'), 'fail');
|
||||
showMessage(` 点此查看状态:https://github.com/${owner}/${repo}/commit/${sha}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
showMessage(`远程分支 CI 已通过`, 'succeed');
|
||||
// clean up
|
||||
await runScript({ event: 'clean', path: '.', stdio: 'inherit' });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue