1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-01-26 18:58:21 +02:00

Tools: Improved git-changelog so that it is less error prone

This commit is contained in:
Laurent Cozic 2019-09-08 17:54:41 +01:00
parent 05e0a2c29d
commit 772e39b710
2 changed files with 38 additions and 15 deletions

View File

@ -175,14 +175,47 @@ function capitalizeFirstLetter(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
}
function decreaseTagVersion(tag) {
const s = tag.split('.');
let num = Number(s.pop());
num--;
if (num < 0) throw new Error('Cannot decrease tag version: ' + tag);
s.push('' + num);
return s.join('.');
}
// This function finds the first relevant tag starting from the given tag.
// The first "relevant tag" is the one that exists, and from which there are changes.
async function findFirstRelevantTag(baseTag) {
let tag = decreaseTagVersion(baseTag);
while (true) {
try {
const logs = await gitLog(tag);
if (logs.length) return tag;
} catch (error) {
if (error.message.indexOf('unknown revision') >= 0) {
// We skip the error - it means this particular tag has never been created
} else {
throw error;
}
}
tag = decreaseTagVersion(tag);
}
}
async function main() {
const argv = require('yargs').argv;
if (!argv._.length) throw new Error('Tag name must be specified');
if (!argv._.length) throw new Error('Tag name must be specified. Provide the tag of the new version and git-changelog will walk backward to find the changes to the previous relevant tag.');
const sinceTagName = argv._[0];
const platform = platformFromTag(sinceTagName);
const fromTagName = argv._[0];
const platform = platformFromTag(fromTagName);
const toTagName = await findFirstRelevantTag(fromTagName);
const logsSinceTags = await gitLog(toTagName);
const logsSinceTags = await gitLog(sinceTagName);
const filteredLogs = filterLogs(logsSinceTags, platform);
let changelog = createChangeLog(filteredLogs);

View File

@ -50,18 +50,8 @@ async function insertChangelog(tag, changelog) {
// Start with node Tools/release-cli.js --changelog-from cli-v1.0.126
// to specify from where the changelog should be created
async function main() {
const argv = require('yargs').argv;
process.chdir(appDir);
const packageJson = await fs.readFile('package.json', 'UTF-8');
const packageConf = JSON.parse(packageJson);
const previousVersion = 'v' + packageConf.version;
let changelogFrom = 'cli-' + previousVersion;
if (argv.changelogFrom) changelogFrom = argv.changelogFrom;
const newVersion = await execCommand('npm version patch');
console.info('Building ' + newVersion + '...');
const newTag = 'cli-' + newVersion;
@ -75,7 +65,7 @@ async function main() {
await execCommand('npm publish');
const changelog = await execCommand('node ' + rootDir + '/Tools/git-changelog ' + changelogFrom);
const changelog = await execCommand('node ' + rootDir + '/Tools/git-changelog ' + newTag);
const newChangelog = await insertChangelog(newTag, changelog);