-
Notifications
You must be signed in to change notification settings - Fork 45
/
versionist.conf.js
83 lines (70 loc) · 2.69 KB
/
versionist.conf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
'use strict';
const execSync = require('child_process').execSync;
const exec = require('child_process').exec;
const path = require('path');
const getAuthor = (commitHash) => {
return execSync(`git show --quiet --format="%an" ${commitHash}`, {
encoding: 'utf8'
}).replace('\n', '');
};
const isIncrementalCommit = (changeType) => {
return Boolean(changeType) && changeType.trim().toLowerCase() !== 'none';
};
module.exports = {
// This setup allows the editing and parsing of footer tags to get version and type information,
// as well as ensuring tags of the type 'v<major>.<minor>.<patch>' are used.
// It increments in a semver compatible fashion and allows the updating of NPM package info.
editChangelog: true,
parseFooterTags: true,
getGitReferenceFromVersion: 'v-prefix',
incrementVersion: 'semver',
updateVersion: (cwd, version, callback) => {
execSync(`sed -i '/^__version__ = ".*"/ s/^__version__ = ".*"/__version__ = "${version}"/g' balena/__init__.py`, {encoding: 'utf8'});
const pyprojectToml = path.join(cwd, 'pyproject.toml');
return exec(`sed -i '/\[tool\.poetry\]/,/^version = ".*"/ s/^version = ".*"/version = "${version}"/g' ${pyprojectToml}`,
{
encoding: 'utf8',
}, callback);
},
// Always add the entry to the top of the Changelog, below the header.
addEntryToChangelog: {
preset: 'prepend',
fromLine: 6
},
// Only include a commit when there is a footer tag of 'change-type'.
// Ensures commits which do not up versions are not included.
includeCommitWhen: (commit) => {
return isIncrementalCommit(commit.footer['change-type']);
},
// Determine the type from 'change-type:' tag.
// Should no explicit change type be made, then no changes are assumed.
getIncrementLevelFromCommit: (commit) => {
const match = commit.subject.match(/^(patch|minor|major):/i);
if (Array.isArray(match) && isIncrementalCommit(match[1])) {
return match[1].trim().toLowerCase();
}
if (isIncrementalCommit(commit.footer['change-type'])) {
return commit.footer['change-type'].trim().toLowerCase();
}
},
// If a 'changelog-entry' tag is found, use this as the subject rather than the
// first line of the commit.
transformTemplateData: (data) => {
data.commits.forEach((commit) => {
commit.subject = commit.footer['changelog-entry'] || commit.subject;
commit.author = getAuthor(commit.hash);
});
return data;
},
template: [
'## v{{version}} - {{moment date "Y-MM-DD"}}',
'',
'{{#each commits}}',
'{{#if this.author}}',
'* {{capitalize this.subject}} [{{this.author}}]',
'{{else}}',
'* {{capitalize this.subject}}',
'{{/if}}',
'{{/each}}'
].join('\n')
};