-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy path.release-it.js
More file actions
78 lines (71 loc) · 2.43 KB
/
Copy path.release-it.js
File metadata and controls
78 lines (71 loc) · 2.43 KB
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
const debug = process.argv.includes('--debug');
const prefixes = {
feat: '🎉 Features',
fix: '🐛 Fixes',
docs: '🚀 Improvements',
ci: '🚀 Improvements',
test: '🚀 Improvements',
refactor: '🚀 Improvements',
chore: '🚀 Improvements',
revert: '🐛 Fixes'
};
function groupCommitsByCategory(logs) {
const grouped = {};
// Initialize categories from the values in the prefixes dictionary
Object.values(prefixes).forEach((category) => {
grouped[category] = [];
});
// Loop through each prefix to find conventional commit pattern ex. feat: , feat(card):, feat(card)! including some edge cases
Object.entries(prefixes).forEach(([prefix, category]) => {
const regex = new RegExp(
`^(${prefix}(\\([\\w\\-]+\\))?!?: [^\\r\\n]+((\\s)((\\s)[^\\r\\n]+)+)*)(\\s?)$`
);
const matches = logs.filter((l) => l.match(regex));
grouped[category] = [...matches, ...grouped[category]];
});
return grouped;
}
module.exports = {
hooks: {
...(!debug && {
"before:init": 'if [ "$(git log $(git describe --tags --abbrev=0)..HEAD)" = "" ]; then echo "NO_COMMIT=true" >> "$GITHUB_OUTPUT"; exit 1; fi;',
'after:release': 'echo "VERSION_NUMBER=v${version}" >> "$GITHUB_OUTPUT"'})
},
git: {
release: debug ? false : true,
commitMessage: 'chore(release): update to version v${version}',
tagName: 'v${version}',
tagAnnotation: 'Release v${version}',
pushArgs: ['--follow-tags'],
requireCleanWorkingDir: debug ? false : true,
requireUpstream: debug ? false : true,
requireCommits: true,
requireCommitsFail: false,
changelog: 'git log --pretty=format:%s ${latestTag}...HEAD' // The output will be passed to releaseNotes context.changelog
},
npm: {
publish: false
},
github: {
release: debug ? false : true,
releaseName: 'v${version}',
autoGenerate: false,
releaseNotes: function (context) {
const logs = context.changelog.split('\n');
const groupedCommits = groupCommitsByCategory(logs);
const title = `## What's changed \n`;
const changelog = Object.entries(groupedCommits)
.map(([prefix, commits]) => {
if (commits.length > 0) {
return `### ${prefix}\n ${commits.map((c) => '* ' + c).join('\n')}`;
}
})
.join('\n');
return title + changelog;
}
},
// Only to bump the version with conventional commits
plugins: {
'./recommended-bump/index.mjs': {}
}
};