mirror of
https://github.com/tenrok/axios.git
synced 2026-06-14 18:42:33 +03:00
chore(ci): fix release action;
* chore(ci): Add release-it script; * fix(utils): redesigned logic for obtaining the global link;; * chore(git): updated .gitignore; chore(npm): updated .npmignore; * chore(git): fix husky prepare script; * chore(github): reworked npm release action step; * chore(ci): add CHANGELOG.md contributors section generator; * chore(deps): add `auto-changelog` to package.json;
This commit is contained in:
@@ -12,8 +12,17 @@ console.log(`Axios version: v${axios.VERSION}`);
|
||||
console.log(`Axios build version: v${axiosBuild.VERSION}`);
|
||||
console.log(`----------------------------`);
|
||||
|
||||
assert.strictEqual(version, axios.VERSION, `Version mismatch between package and Axios`);
|
||||
assert.strictEqual(version, axiosBuild.VERSION, `Version mismatch between package and build`);
|
||||
assert.strictEqual(
|
||||
version,
|
||||
axios.VERSION,
|
||||
`Version mismatch between package and Axios ${version} != ${axios.VERSION}`
|
||||
);
|
||||
|
||||
assert.strictEqual(
|
||||
version,
|
||||
axiosBuild.VERSION,
|
||||
`Version mismatch between package and build ${version} != ${axiosBuild.VERSION}`
|
||||
);
|
||||
|
||||
console.log('✔️ PASSED\n');
|
||||
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
import axios from "../index.js";
|
||||
import util from "util";
|
||||
import cp from "child_process";
|
||||
import Handlebars from "handlebars";
|
||||
import fs from "fs/promises";
|
||||
|
||||
const exec = util.promisify(cp.exec);
|
||||
|
||||
const removeExtraLineBreaks = (str) => str.replace(/(?:\r\n|\r|\n){3,}/gm, '\r\n\r\n');
|
||||
|
||||
const cleanTemplate = template => template
|
||||
.replace(/\n +/g, '\n')
|
||||
.replace(/^ +/, '')
|
||||
.replace(/\n\n\n+/g, '\n\n')
|
||||
.replace(/\n\n$/, '\n');
|
||||
|
||||
const getUserInfo = ((userCache) => async (email) => {
|
||||
if (userCache[email] !== undefined) {
|
||||
return userCache[email];
|
||||
}
|
||||
try {
|
||||
const {data: {items: [user]}} = await axios.get(`https://api.github.com/search/users?q=${email}`);
|
||||
|
||||
return (userCache[email] = user ? {
|
||||
...user,
|
||||
avatar_url_sm: user.avatar_url + '&s=16'
|
||||
} : null);
|
||||
} catch (err) {
|
||||
console.warn(err);
|
||||
return {};
|
||||
}
|
||||
})({});
|
||||
|
||||
|
||||
const getReleaseInfo = async (version, useGithub) => {
|
||||
version = 'v' + version.replace(/^v/, '');
|
||||
|
||||
const releases = JSON.parse((await exec(
|
||||
`npx auto-changelog ${
|
||||
version ? '--starting-version ' + version + ' --ending-version ' + version: ''
|
||||
} --stdout --commit-limit false --template json`)).stdout
|
||||
);
|
||||
|
||||
for(const release of releases) {
|
||||
const authors = {};
|
||||
|
||||
const commits = [
|
||||
...release.commits,
|
||||
...release.fixes.map(fix => fix.commit),
|
||||
...release.merges.map(fix => fix.commit)
|
||||
].filter(Boolean);
|
||||
|
||||
for(const {author, email, insertions, deletions} of commits) {
|
||||
const user = Object.assign({
|
||||
name: author,
|
||||
email
|
||||
}, useGithub ? await getUserInfo(email) : null);
|
||||
|
||||
const entry = authors[author] = (authors[author] || {
|
||||
insertions: 0, deletions: 0, ...user
|
||||
});
|
||||
|
||||
entry.github = entry.login ? `https://github.com/${encodeURIComponent(entry.login)}` : '';
|
||||
|
||||
entry.insertions += insertions;
|
||||
entry.deletions += deletions;
|
||||
entry.points = entry.insertions + entry.deletions;
|
||||
}
|
||||
|
||||
release.authors = Object.values(authors).sort((a, b) => b.points - a.points);
|
||||
release.allCommits = commits;
|
||||
}
|
||||
|
||||
return releases;
|
||||
}
|
||||
|
||||
const renderContributorsList = async (version, useGithub = false, template) => {
|
||||
const release = (await getReleaseInfo(version, useGithub))[0];
|
||||
|
||||
const compile = Handlebars.compile(String(await fs.readFile(template)))
|
||||
|
||||
const content = compile(release);
|
||||
|
||||
return removeExtraLineBreaks(cleanTemplate(content));
|
||||
}
|
||||
|
||||
export {
|
||||
renderContributorsList
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import fs from 'fs/promises';
|
||||
import path from 'path';
|
||||
import {renderContributorsList} from './contributors.js';
|
||||
import asyncReplace from 'string-replace-async';
|
||||
import {fileURLToPath} from "url";
|
||||
|
||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
|
||||
const injectContributors = async (infile, injector) => {
|
||||
console.log(`Checking contributors sections in ${infile}`);
|
||||
|
||||
infile = path.resolve(__dirname, infile);
|
||||
|
||||
const content = String(await fs.readFile(infile));
|
||||
const headerRE = /^##\s+\[([-_\d.\w]+)]\s+-.+/mig;
|
||||
const contributorsRE = /^\s*### Contributors/mi;
|
||||
|
||||
let tag;
|
||||
let index = 0;
|
||||
|
||||
const newContent = await asyncReplace(content, headerRE, async (match, nextTag, offset) => {
|
||||
const releaseContent = content.slice(index, offset);
|
||||
|
||||
const hasContributorsSection = contributorsRE.test(releaseContent);
|
||||
|
||||
const currentTag = tag;
|
||||
|
||||
tag = nextTag;
|
||||
index = offset + match.length;
|
||||
|
||||
if(currentTag && !hasContributorsSection) {
|
||||
console.log(`Adding contributors for ${currentTag}`);
|
||||
|
||||
return (await injector(currentTag)) + match;
|
||||
}
|
||||
|
||||
return match;
|
||||
});
|
||||
|
||||
await fs.writeFile(infile, newContent);
|
||||
}
|
||||
|
||||
|
||||
await injectContributors(
|
||||
'../CHANGELOG.md',
|
||||
(tag) => renderContributorsList(tag, true, path.resolve(__dirname, '../templates/contributors.hbs')
|
||||
));
|
||||
Reference in New Issue
Block a user