-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.releaserc.cjs
More file actions
187 lines (160 loc) · 5.08 KB
/
.releaserc.cjs
File metadata and controls
187 lines (160 loc) · 5.08 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/**
* semantic-release config (JS so we can use functions + comments)
*
* Notes strategy:
* - A single release-notes-generator produces notes used by both CHANGELOG.md and GitHub Release.
* - Using two generators would cause semantic-release to concatenate their outputs, duplicating entries.
*/
'use strict';
const fs = require('fs');
const yaml = require('js-yaml');
// Load valid scopes from the unified taxonomy in tags.yml.
// Both "both" and "scopes" entries are valid commit scopes.
const _tagDef = yaml.load(fs.readFileSync(new URL('.github/tags.yml', `file://${__dirname}/`), 'utf8'));
const validScopes = new Set([
...(_tagDef.tags.both || []),
...(_tagDef.tags.scopes || []),
]);
const OTHER_SECTION = '🧩 Other';
const SECTION_TITLES = {
feat: '✨ Features',
fix: '🐛 Fixes',
perf: '⚡ Performance',
test: '✅ Tests',
build: '📦 Build',
ci: '🤖 CI / CD',
chore: '🧹 Chores',
style: '💄 Style',
refactor: '♻️ Refactors',
docs: '📝 Docs',
post: '✉️ Posts',
};
// Order groups exactly as declared above, and always render "Other" last.
const GROUP_ORDER = Object.values(SECTION_TITLES);
const ALLOWED_TYPES_FOR_NOTES = new Set(Object.keys(SECTION_TITLES));
/**
* Notes transform policy
* - Skips merge commits entirely
* - Skips commits with no subject (prevents empty bullets)
* - Routes unknown/missing types into the "Other" group
* - Returns a NEW object (immutable-safe)
*/
function baseTransform(commit) {
// conventional-commits-parser sets commit.merge for merge commits
if (commit.merge || /^Merge\b/i.test(commit.subject || '')) return;
const subject = (commit.subject || '').trim();
if (!subject) return;
const scope = (commit.scope || '').trim();
const flaggedSubject =
scope && !validScopes.has(scope) ? `${subject} ⚠️ unknown-scope` : subject;
const rawType = (commit.type || '').trim();
const normalizedType =
rawType && ALLOWED_TYPES_FOR_NOTES.has(rawType) ? rawType : 'other';
return {
...commit,
subject: flaggedSubject,
type:
normalizedType === 'other'
? OTHER_SECTION
: SECTION_TITLES[normalizedType],
shortHash: commit.hash?.slice(0, 7),
};
}
function commitGroupsSort(a, b) {
// Always last
if (a.title === OTHER_SECTION && b.title !== OTHER_SECTION) return 1;
if (a.title !== OTHER_SECTION && b.title === OTHER_SECTION) return -1;
// Order by SECTION_TITLES placement
const ai = GROUP_ORDER.indexOf(a.title);
const bi = GROUP_ORDER.indexOf(b.title);
// Known groups first, in declared order
if (ai !== -1 && bi !== -1) return ai - bi;
// If one is known and the other isn't, known wins
if (ai !== -1 && bi === -1) return -1;
if (ai === -1 && bi !== -1) return 1;
// Fallback
return a.title.localeCompare(b.title);
}
/**
* We set mainTemplate explicitly because the preset defaults sometimes flatten output.
* This forces section headers and deterministic ordering.
*/
const changelogMainTemplate = [
'## 📦 Release {{version}}',
'',
'{{#each commitGroups}}',
'### {{title}}',
'',
'{{#each commits}}',
'{{> commit}}',
'{{/each}}',
'',
'{{/each}}',
].join('\n');
/** Writer opts shared by both CHANGELOG.md and GitHub Release */
const changelogWriterOpts = {
groupBy: 'type',
commitGroupsSort,
commitsSort: ['scope', 'subject'],
transform: baseTransform,
mainTemplate: changelogMainTemplate,
// IMPORTANT: include newline so bullets don't run together
commitPartial:
'- {{#if scope}}**{{scope}}:** {{/if}}{{subject}} ({{shortHash}})\n',
};
module.exports = {
branches: [
'main',
{ name: 'canary', channel: 'canary', prerelease: true },
],
tagFormat: 'v${version}',
plugins: [
// 1) Decide version bump based on commits
[
'@semantic-release/commit-analyzer',
{
preset: 'conventionalcommits',
releaseRules: [
{ breaking: true, release: 'major' },
{ type: 'feat', release: 'minor' },
{ type: 'fix', release: 'patch' },
{ type: 'perf', release: 'patch' },
// Everything else: no release bump
{ type: 'refactor', release: false },
{ type: 'docs', release: false },
{ type: 'chore', release: false },
{ type: 'test', release: false },
{ type: 'ci', release: false },
{ type: 'style', release: false },
{ type: 'build', release: false },
],
},
],
// 2) Generate release notes (used by both CHANGELOG.md and GitHub Release)
[
'@semantic-release/release-notes-generator',
{
preset: 'conventionalcommits',
writerOpts: changelogWriterOpts,
},
],
// 3) Update CHANGELOG.md
[
'@semantic-release/changelog',
{
changelogFile: 'CHANGELOG.md',
changelogTitle: '# 📦 Release History',
},
],
// 4) Publish GitHub Release
'@semantic-release/github',
// 5) Commit CHANGELOG.md back to the repo
[
'@semantic-release/git',
{
assets: ['CHANGELOG.md'],
message: 'chore(release): ${nextRelease.version}',
},
],
],
};