You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-13 00:10:37 +02:00
Tools: Improved git-changelog so that it is less error prone
This commit is contained in:
@ -175,14 +175,47 @@ function capitalizeFirstLetter(string) {
|
|||||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
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() {
|
async function main() {
|
||||||
const argv = require('yargs').argv;
|
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 fromTagName = argv._[0];
|
||||||
const platform = platformFromTag(sinceTagName);
|
|
||||||
|
const platform = platformFromTag(fromTagName);
|
||||||
|
|
||||||
|
const toTagName = await findFirstRelevantTag(fromTagName);
|
||||||
|
|
||||||
|
const logsSinceTags = await gitLog(toTagName);
|
||||||
|
|
||||||
const logsSinceTags = await gitLog(sinceTagName);
|
|
||||||
const filteredLogs = filterLogs(logsSinceTags, platform);
|
const filteredLogs = filterLogs(logsSinceTags, platform);
|
||||||
|
|
||||||
let changelog = createChangeLog(filteredLogs);
|
let changelog = createChangeLog(filteredLogs);
|
||||||
|
@ -50,18 +50,8 @@ async function insertChangelog(tag, changelog) {
|
|||||||
// Start with node Tools/release-cli.js --changelog-from cli-v1.0.126
|
// Start with node Tools/release-cli.js --changelog-from cli-v1.0.126
|
||||||
// to specify from where the changelog should be created
|
// to specify from where the changelog should be created
|
||||||
async function main() {
|
async function main() {
|
||||||
const argv = require('yargs').argv;
|
|
||||||
|
|
||||||
process.chdir(appDir);
|
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');
|
const newVersion = await execCommand('npm version patch');
|
||||||
console.info('Building ' + newVersion + '...');
|
console.info('Building ' + newVersion + '...');
|
||||||
const newTag = 'cli-' + newVersion;
|
const newTag = 'cli-' + newVersion;
|
||||||
@ -75,7 +65,7 @@ async function main() {
|
|||||||
|
|
||||||
await execCommand('npm publish');
|
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);
|
const newChangelog = await insertChangelog(newTag, changelog);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user