Repository navigation
Expand file tree
/
Copy pathrelease.config.mjs
More file actions
109 lines (106 loc) · 3.35 KB
/
Copy pathrelease.config.mjs
File metadata and controls
109 lines (106 loc) · 3.35 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/**
* @typedef {{ action?: string | null, owner?: string | null, repository?: string | null, issue: string }} Reference
* @typedef {{ owner?: string, repository?: string, commitGroups?: { commits: { references?: Reference[] }[] }[] }} NotesContext
*/
/**
* Keeps only the issues a commit closes, each once.
*
* The parser collects every `#123` in a message, and the `conventionalcommits` template lists them
* all after ", closes". A squash merge's message holds every commit of the PR, so without this its
* note claims to close each issue those commits mention, often more than once. Only a reference
* the parser tied to a closing keyword (`Closes`, `Fixes`, `Resolves`, …) has an `action`.
*
* @param {Reference[]} references
* @param {{ owner?: string, repository?: string }} repo the repository the release is for
* @returns {Reference[]}
*/
export function closingReferences(references, { owner, repository }) {
const seen = new Set();
return references.filter((reference) => {
if (!reference.action) {
return false;
}
const key = `${reference.owner ?? owner}/${reference.repository ?? repository}#${reference.issue}`.toLowerCase();
if (seen.has(key)) {
return false;
}
seen.add(key);
return true;
});
}
/**
* conventional-changelog-writer hook: runs after the preset's own per-commit transform, which has
* already dropped references repeated in the subject (the squash's `(#123)`).
*
* @param {NotesContext} context
* @returns {NotesContext}
*/
function closingReferencesOnly(context) {
return {
...context,
commitGroups: context.commitGroups?.map((group) => ({
...group,
commits: group.commits.map((commit) => ({
...commit,
references: closingReferences(commit.references ?? [], context),
})),
})),
};
}
export default {
branches: ['stage'],
tagFormat: 'v${version}',
plugins: [
[
'@semantic-release/commit-analyzer',
{
preset: 'conventionalcommits',
releaseRules: [
{ type: 'feat', release: 'minor' },
{ type: 'fix', release: 'patch' },
{ type: 'perf', release: 'patch' },
{ type: 'refactor', release: 'patch' },
{ type: 'chore', release: 'patch' },
{ type: 'docs', release: 'patch' },
{ type: 'style', release: 'patch' },
{ type: 'test', release: 'patch' },
{ type: 'build', release: 'patch' },
{ type: 'ci', release: 'patch' },
{ type: 'revert', release: 'patch' },
{ type: '*', release: 'patch' },
],
},
],
[
'@semantic-release/release-notes-generator',
{
preset: 'conventionalcommits',
presetConfig: {
types: [
{ type: 'feat', section: 'Features' },
{ type: 'fix', section: 'Bug Fixes' },
{ type: 'perf', section: 'Performance Improvements' },
{ type: 'refactor', section: 'Refactoring' },
{ type: 'chore', scope: 'deps', section: 'Dependency Updates', hidden: false },
{ type: 'chore', section: 'Chores', hidden: false },
{ type: 'docs', section: 'Documentation' },
{ type: 'style', section: 'Styles' },
{ type: 'test', section: 'Tests' },
{ type: 'build', section: 'Build System' },
{ type: 'ci', section: 'Continuous Integration' },
{ type: 'revert', section: 'Reverts' },
],
},
writerOpts: {
finalizeContext: closingReferencesOnly,
},
},
],
[
'@semantic-release/github',
{
successCommentCondition: false,
},
],
],
};