Browse Source

chore: Improve changelog workflow (#23198)

*  improve changelog workflow

* chore: fill missing changelog

* allow custom input
pull/23199/head
偏右 5 years ago
committed by GitHub
parent
commit
f7ead77f88
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      package.json
  2. 81
      scripts/print-changelog.js

4
package.json

@ -49,8 +49,9 @@
"authors": "git log --format='%aN <%aE>' | sort -u | grep -v 'users.noreply.github.com' | grep -v 'gitter.im' | grep -v '.local>' | grep -v 'alibaba-inc.com' | grep -v 'alipay.com' | grep -v 'taobao.com' > AUTHORS.txt", "authors": "git log --format='%aN <%aE>' | sort -u | grep -v 'users.noreply.github.com' | grep -v 'gitter.im' | grep -v '.local>' | grep -v 'alibaba-inc.com' | grep -v 'alipay.com' | grep -v 'taobao.com' > AUTHORS.txt",
"build": "npm run compile && npm run dist", "build": "npm run compile && npm run dist",
"bundlesize": "bundlesize", "bundlesize": "bundlesize",
"check-commit": "node ./scripts/check-commit.js", "check-commit": "node ./scripts/check-commit",
"compile": "antd-tools run compile", "compile": "antd-tools run compile",
"changelog": "node ./scripts/print-changelog",
"predeploy": "antd-tools run clean && npm run site && cp netlify.toml CNAME _site && cp -r .circleci/ .github/ _site && npm run site:test", "predeploy": "antd-tools run clean && npm run site && cp netlify.toml CNAME _site && cp -r .circleci/ .github/ _site && npm run site:test",
"deploy": "bisheng gh-pages --push-only --dotfiles", "deploy": "bisheng gh-pages --push-only --dotfiles",
"deploy:china-mirror": "git checkout gh-pages && git pull origin gh-pages && git push git@gitee.com:ant-design/ant-design.git gh-pages", "deploy:china-mirror": "git checkout gh-pages && git pull origin gh-pages && git push git@gitee.com:ant-design/ant-design.git gh-pages",
@ -200,6 +201,7 @@
"husky": "^4.0.3", "husky": "^4.0.3",
"ignore-emit-webpack-plugin": "^2.0.2", "ignore-emit-webpack-plugin": "^2.0.2",
"immutability-helper": "^3.0.0", "immutability-helper": "^3.0.0",
"inquirer": "^7.1.0",
"intersection-observer": "^0.7.0", "intersection-observer": "^0.7.0",
"jest": "^25.1.0", "jest": "^25.1.0",
"jquery": "^3.4.1", "jquery": "^3.4.1",

81
scripts/print-changelog.js

@ -1,5 +1,4 @@
/* eslint-disable no-await-in-loop */ /* eslint-disable no-await-in-loop, no-console */
/* eslint-disable no-console */
const chalk = require('chalk'); const chalk = require('chalk');
const { spawn } = require('child_process'); const { spawn } = require('child_process');
const jsdom = require('jsdom'); const jsdom = require('jsdom');
@ -9,6 +8,7 @@ const open = require('open');
const fs = require('fs-extra'); const fs = require('fs-extra');
const path = require('path'); const path = require('path');
const simpleGit = require('simple-git/promise'); const simpleGit = require('simple-git/promise');
const inquirer = require('inquirer');
const { JSDOM } = jsdom; const { JSDOM } = jsdom;
const { window } = new JSDOM(); const { window } = new JSDOM();
@ -24,12 +24,13 @@ const MAINTAINERS = ['zombiej', 'afc163', 'chenshuai2144', 'shaodahong', 'xrkffg
author.toLowerCase(), author.toLowerCase(),
); );
const fromVersion = process.argv[process.argv.length - 2];
const toVersion = process.argv[process.argv.length - 1];
const cwd = process.cwd(); const cwd = process.cwd();
const git = simpleGit(cwd); const git = simpleGit(cwd);
function getDescription(entity) { function getDescription(entity) {
if (!entity) {
return '';
}
const descEle = entity.element.find('td:last'); const descEle = entity.element.find('td:last');
let htmlContent = descEle.html(); let htmlContent = descEle.html();
htmlContent = htmlContent.replace(/<code>([^<]*)<\/code>/g, '`$1`'); htmlContent = htmlContent.replace(/<code>([^<]*)<\/code>/g, '`$1`');
@ -37,12 +38,40 @@ function getDescription(entity) {
} }
async function printLog() { async function printLog() {
const tags = await git.tags();
const { fromVersion } = await inquirer.prompt([
{
type: 'list',
name: 'fromVersion',
message: '🏷 Please choose tag to compare with current branch:',
choices: tags.all.reverse().slice(0, 10),
},
]);
let { toVersion } = await inquirer.prompt([
{
type: 'list',
name: 'toVersion',
message: `🔀 Please choose branch to compare with ${chalk.magenta(fromVersion)}:`,
choices: ['master', '3.x-stable', 'feature', 'custom input ⌨️'],
},
]);
if (toVersion.startsWith('custom input')) {
const result = await inquirer.prompt([
{
type: 'input',
name: 'toVersion',
message: `🔀 Please input custom git hash id or branch name to compare with ${chalk.magenta(
fromVersion,
)}:`,
default: 'master',
},
]);
toVersion = result.toVersion;
}
if (!/\d+\.\d+\.\d+/.test(fromVersion)) { if (!/\d+\.\d+\.\d+/.test(fromVersion)) {
console.log( console.log(chalk.red(`🤪 tag (${chalk.magenta(fromVersion)}) is not valid.`));
chalk.red(
'🤪 Not pass validate tags. Please execute like `print-changelog.js 3.26.0 master` instead.',
),
);
} }
const logs = await git.log({ from: fromVersion, to: toVersion }); const logs = await git.log({ from: fromVersion, to: toVersion });
@ -50,7 +79,7 @@ async function printLog() {
let prList = []; let prList = [];
for (let i = 0; i < logs.all.length; i += 1) { for (let i = 0; i < logs.all.length; i += 1) {
const { message, body, hash } = logs.all[i]; const { message, body, hash, author_name } = logs.all[i];
const text = `${message} ${body}`; const text = `${message} ${body}`;
@ -91,6 +120,12 @@ async function printLog() {
const english = getDescription(lines.find(line => line.text.includes('🇺🇸 English'))); const english = getDescription(lines.find(line => line.text.includes('🇺🇸 English')));
const chinese = getDescription(lines.find(line => line.text.includes('🇨🇳 Chinese'))); const chinese = getDescription(lines.find(line => line.text.includes('🇨🇳 Chinese')));
if (english) {
console.log(` 🇨🇳 ${english}`);
}
if (chinese) {
console.log(` 🇺🇸 ${chinese}`);
}
validatePRs.push({ validatePRs.push({
pr, pr,
@ -112,6 +147,9 @@ async function printLog() {
prList.push({ prList.push({
hash, hash,
title: message, title: message,
author: author_name,
english: message,
chinese: message,
}); });
} }
} }
@ -145,19 +183,27 @@ async function printLog() {
} }
// Chinese // Chinese
console.log(chalk.yellow('Chinese changelog:')); console.log('\n');
printPR('chinese', chinese => (chinese[chinese.length - 1] === '。' ? chinese : `${chinese}`)); console.log(chalk.yellow('🇨🇳 Chinese changelog:'));
console.log('\n');
printPR('chinese', chinese => {
return chinese[chinese.length - 1] === '。' || !chinese ? chinese : `${chinese}`;
});
console.log('\n-----\n'); console.log('\n-----\n');
// English // English
console.log(chalk.yellow('English changelog:')); console.log(chalk.yellow('🇺🇸 English changelog:'));
console.log('\n');
printPR('english', english => { printPR('english', english => {
english = english.trim(); english = english.trim();
if (english[english.length - 1] !== '.') { if (english[english.length - 1] !== '.' || !english) {
english = `${english}.`; english = `${english}.`;
} }
return `${english} `; if (english) {
return `${english} `;
}
return '';
}); });
// Preview editor generate // Preview editor generate
@ -178,11 +224,10 @@ async function printLog() {
console.log(data.toString()); console.log(data.toString());
}); });
console.log(chalk.green('Start preview editor...')); console.log(chalk.green('Start changelog preview editor...'));
setTimeout(function openPreview() { setTimeout(() => {
open('http://localhost:2893/'); open('http://localhost:2893/');
}, 1000); }, 1000);
} }
printLog(); printLog();
/* eslint-enable */

Loading…
Cancel
Save