semantic-release 25.0.4 → 25.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -7
- package/index.js +265 -37
- package/lib/branches/expand.js +18 -0
- package/lib/branches/get-tags.js +39 -0
- package/lib/branches/index.js +71 -0
- package/lib/branches/normalize.js +104 -0
- package/lib/definitions/branches.js +22 -0
- package/lib/definitions/constants.js +8 -9
- package/lib/definitions/errors.js +298 -0
- package/lib/definitions/plugins.js +108 -0
- package/lib/get-commits.js +31 -0
- package/lib/get-config.js +98 -0
- package/lib/get-error.js +7 -0
- package/lib/get-git-auth-url.js +126 -0
- package/lib/get-last-release.js +48 -0
- package/lib/get-logger.js +19 -0
- package/lib/get-next-version.js +35 -0
- package/lib/get-release-to-add.js +59 -0
- package/lib/git.js +381 -0
- package/lib/plugins/index.js +103 -0
- package/lib/plugins/normalize.js +69 -0
- package/lib/plugins/pipeline.js +59 -0
- package/lib/plugins/utils.js +81 -0
- package/lib/utils.js +101 -0
- package/lib/verify.js +43 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,13 +30,6 @@
|
|
|
30
30
|
|
|
31
31
|
This removes the immediate connection between human emotions and version numbers, strictly following the [Semantic Versioning](http://semver.org) specification and communicating the **impact** of changes to consumers.
|
|
32
32
|
|
|
33
|
-
## Core Engine
|
|
34
|
-
|
|
35
|
-
`semantic-release` now uses [`@semantic-release/core`](https://github.com/semantic-release/core) as its release engine.
|
|
36
|
-
For existing users, behavior stays the same: the `semantic-release` CLI, default plugin profile, and current configuration model remain backward compatible.
|
|
37
|
-
|
|
38
|
-
If you want to build a custom CLI or compose your own plugin stack directly, use `@semantic-release/core`.
|
|
39
|
-
|
|
40
33
|
> Trust us, this will change your workflow for the better. – [egghead.io](https://egghead.io/lessons/javascript-how-to-write-a-javascript-library-automating-releases-with-semantic-release)
|
|
41
34
|
|
|
42
35
|
## Highlights
|
package/index.js
CHANGED
|
@@ -1,23 +1,50 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { pick } from "lodash-es";
|
|
3
|
+
import * as marked from "marked";
|
|
4
|
+
import envCi from "env-ci";
|
|
5
|
+
import { hookStd } from "hook-std";
|
|
6
|
+
import semver from "semver";
|
|
7
|
+
import AggregateError from "aggregate-error";
|
|
8
|
+
import hideSensitive from "./lib/hide-sensitive.js";
|
|
9
|
+
import getConfig from "./lib/get-config.js";
|
|
10
|
+
import verify from "./lib/verify.js";
|
|
11
|
+
import getNextVersion from "./lib/get-next-version.js";
|
|
12
|
+
import getCommits from "./lib/get-commits.js";
|
|
13
|
+
import getLastRelease from "./lib/get-last-release.js";
|
|
14
|
+
import getReleaseToAdd from "./lib/get-release-to-add.js";
|
|
15
|
+
import { extractErrors, makeTag } from "./lib/utils.js";
|
|
16
|
+
import getGitAuthUrl from "./lib/get-git-auth-url.js";
|
|
17
|
+
import getBranches from "./lib/branches/index.js";
|
|
18
|
+
import getLogger from "./lib/get-logger.js";
|
|
19
|
+
import { addNote, getGitHead, getTagHead, isBranchUpToDate, push, pushNotes, tag, verifyAuth } from "./lib/git.js";
|
|
20
|
+
import getError from "./lib/get-error.js";
|
|
21
|
+
import { COMMIT_EMAIL, COMMIT_NAME } from "./lib/definitions/constants.js";
|
|
3
22
|
|
|
4
|
-
|
|
23
|
+
const require = createRequire(import.meta.url);
|
|
24
|
+
const pkg = require("./package.json");
|
|
5
25
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
)
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const noCi = Boolean(cliOptions.noCi || cliOptions.ci === false);
|
|
26
|
+
let markedOptionsSet = false;
|
|
27
|
+
async function terminalOutput(text) {
|
|
28
|
+
if (!markedOptionsSet) {
|
|
29
|
+
const { default: TerminalRenderer } = await import("marked-terminal"); // eslint-disable-line node/no-unsupported-features/es-syntax
|
|
30
|
+
marked.setOptions({ renderer: new TerminalRenderer() });
|
|
31
|
+
markedOptionsSet = true;
|
|
32
|
+
}
|
|
14
33
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
34
|
+
return marked.parse(text);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/* eslint complexity: off */
|
|
38
|
+
async function run(context, plugins) {
|
|
39
|
+
const { cwd, env, options, logger, envCi } = context;
|
|
40
|
+
const { isCi, branch, prBranch, isPr } = envCi;
|
|
41
|
+
const ciBranch = isPr ? prBranch : branch;
|
|
18
42
|
|
|
19
|
-
if (!
|
|
20
|
-
|
|
43
|
+
if (!isCi && !options.dryRun && !options.noCi) {
|
|
44
|
+
logger.warn("This run was not triggered in a known CI environment, running in dry-run mode.");
|
|
45
|
+
options.dryRun = true;
|
|
46
|
+
} else {
|
|
47
|
+
// When running on CI, set the commits author and committer info and prevent the `git` CLI to prompt for username/password. See #703.
|
|
21
48
|
Object.assign(env, {
|
|
22
49
|
GIT_AUTHOR_NAME: COMMIT_NAME,
|
|
23
50
|
GIT_AUTHOR_EMAIL: COMMIT_EMAIL,
|
|
@@ -29,34 +56,235 @@ export default async (
|
|
|
29
56
|
});
|
|
30
57
|
}
|
|
31
58
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
59
|
+
if (isCi && isPr && !options.noCi) {
|
|
60
|
+
logger.log("This run was triggered by a pull request and therefore a new version won't be published.");
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Verify config
|
|
65
|
+
await verify(context);
|
|
66
|
+
|
|
67
|
+
options.repositoryUrl = await getGitAuthUrl({ ...context, branch: { name: ciBranch } });
|
|
68
|
+
context.branches = await getBranches(options.repositoryUrl, ciBranch, context);
|
|
69
|
+
context.branch = context.branches.find(({ name }) => name === ciBranch);
|
|
70
|
+
|
|
71
|
+
if (!context.branch) {
|
|
72
|
+
logger.log(
|
|
73
|
+
`This test run was triggered on the branch ${ciBranch}, while semantic-release is configured to only publish from ${context.branches
|
|
74
|
+
.map(({ name }) => name)
|
|
75
|
+
.join(", ")}, therefore a new version won’t be published.`
|
|
76
|
+
);
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
logger[options.dryRun ? "warn" : "success"](
|
|
81
|
+
`Run automated release from branch ${ciBranch} on repository ${options.originalRepositoryURL}${
|
|
82
|
+
options.dryRun ? " in dry-run mode" : ""
|
|
83
|
+
}`
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
try {
|
|
87
|
+
try {
|
|
88
|
+
await verifyAuth(options.repositoryUrl, context.branch.name, { cwd, env });
|
|
89
|
+
} catch (error) {
|
|
90
|
+
if (!(await isBranchUpToDate(options.repositoryUrl, context.branch.name, { cwd, env }))) {
|
|
91
|
+
logger.log(
|
|
92
|
+
`The local branch ${context.branch.name} is behind the remote one, therefore a new version won't be published.`
|
|
93
|
+
);
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
} catch (error) {
|
|
100
|
+
logger.error(`The command "${error.command}" failed with the error message ${error.stderr}.`);
|
|
101
|
+
throw getError("EGITNOPERMISSION", context);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
logger.success(`Allowed to push to the Git repository`);
|
|
105
|
+
|
|
106
|
+
await plugins.verifyConditions(context);
|
|
107
|
+
|
|
108
|
+
const errors = [];
|
|
109
|
+
context.releases = [];
|
|
110
|
+
const releaseToAdd = getReleaseToAdd(context);
|
|
111
|
+
|
|
112
|
+
if (releaseToAdd) {
|
|
113
|
+
const { lastRelease, currentRelease, nextRelease } = releaseToAdd;
|
|
114
|
+
|
|
115
|
+
nextRelease.gitHead = await getTagHead(nextRelease.gitHead, { cwd, env });
|
|
116
|
+
currentRelease.gitHead = await getTagHead(currentRelease.gitHead, { cwd, env });
|
|
117
|
+
if (context.branch.mergeRange && !semver.satisfies(nextRelease.version, context.branch.mergeRange)) {
|
|
118
|
+
errors.push(getError("EINVALIDMAINTENANCEMERGE", { ...context, nextRelease }));
|
|
119
|
+
} else {
|
|
120
|
+
const commits = await getCommits({ ...context, lastRelease, nextRelease });
|
|
121
|
+
nextRelease.notes = await plugins.generateNotes({ ...context, commits, lastRelease, nextRelease });
|
|
122
|
+
|
|
123
|
+
if (options.dryRun) {
|
|
124
|
+
logger.warn(`Skip ${nextRelease.gitTag} tag creation in dry-run mode`);
|
|
125
|
+
} else {
|
|
126
|
+
await addNote({ channels: [...currentRelease.channels, nextRelease.channel] }, nextRelease.gitTag, {
|
|
127
|
+
cwd,
|
|
128
|
+
env,
|
|
129
|
+
});
|
|
130
|
+
await push(options.repositoryUrl, { cwd, env });
|
|
131
|
+
await pushNotes(options.repositoryUrl, nextRelease.gitTag, {
|
|
132
|
+
cwd,
|
|
133
|
+
env,
|
|
134
|
+
});
|
|
135
|
+
logger.success(
|
|
136
|
+
`Add ${nextRelease.channel ? `channel ${nextRelease.channel}` : "default channel"} to tag ${
|
|
137
|
+
nextRelease.gitTag
|
|
138
|
+
}`
|
|
139
|
+
);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
context.branch.tags.push({
|
|
143
|
+
version: nextRelease.version,
|
|
144
|
+
channel: nextRelease.channel,
|
|
145
|
+
gitTag: nextRelease.gitTag,
|
|
146
|
+
gitHead: nextRelease.gitHead,
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
const releases = await plugins.addChannel({ ...context, commits, lastRelease, currentRelease, nextRelease });
|
|
150
|
+
context.releases.push(...releases);
|
|
151
|
+
await plugins.success({ ...context, lastRelease, commits, nextRelease, releases });
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (errors.length > 0) {
|
|
156
|
+
throw new AggregateError(errors);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
context.lastRelease = getLastRelease(context);
|
|
160
|
+
if (context.lastRelease.gitHead) {
|
|
161
|
+
context.lastRelease.gitHead = await getTagHead(context.lastRelease.gitHead, { cwd, env });
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (context.lastRelease.gitTag) {
|
|
165
|
+
logger.log(
|
|
166
|
+
`Found git tag ${context.lastRelease.gitTag} associated with version ${context.lastRelease.version} on branch ${context.branch.name}`
|
|
167
|
+
);
|
|
168
|
+
} else {
|
|
169
|
+
logger.log(`No git tag version found on branch ${context.branch.name}`);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
context.commits = await getCommits(context);
|
|
173
|
+
|
|
174
|
+
const nextRelease = {
|
|
175
|
+
type: await plugins.analyzeCommits(context),
|
|
176
|
+
channel: context.branch.channel || null,
|
|
177
|
+
gitHead: await getGitHead({ cwd, env }),
|
|
38
178
|
};
|
|
179
|
+
if (!nextRelease.type) {
|
|
180
|
+
logger.log("There are no relevant changes, so no new version is released.");
|
|
181
|
+
return context.releases.length > 0 ? { releases: context.releases } : false;
|
|
182
|
+
}
|
|
39
183
|
|
|
40
|
-
context.
|
|
184
|
+
context.nextRelease = nextRelease;
|
|
185
|
+
nextRelease.version = getNextVersion(context);
|
|
186
|
+
nextRelease.gitTag = makeTag(options.tagFormat, nextRelease.version);
|
|
187
|
+
nextRelease.name = nextRelease.gitTag;
|
|
41
188
|
|
|
42
|
-
context.
|
|
43
|
-
|
|
44
|
-
|
|
189
|
+
if (context.branch.type !== "prerelease" && !semver.satisfies(nextRelease.version, context.branch.range)) {
|
|
190
|
+
throw getError("EINVALIDNEXTVERSION", {
|
|
191
|
+
...context,
|
|
192
|
+
validBranches: context.branches.filter(
|
|
193
|
+
({ type, accept }) => type !== "prerelease" && accept.includes(nextRelease.type)
|
|
194
|
+
),
|
|
195
|
+
});
|
|
45
196
|
}
|
|
46
197
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
198
|
+
await plugins.verifyRelease(context);
|
|
199
|
+
|
|
200
|
+
nextRelease.notes = await plugins.generateNotes(context);
|
|
201
|
+
|
|
202
|
+
await plugins.prepare(context);
|
|
203
|
+
|
|
204
|
+
if (options.dryRun) {
|
|
205
|
+
logger.warn(`Skip ${nextRelease.gitTag} tag creation in dry-run mode`);
|
|
206
|
+
} else {
|
|
207
|
+
// Create the tag before calling the publish plugins as some require the tag to exists
|
|
208
|
+
await tag(nextRelease.gitTag, nextRelease.gitHead, { cwd, env });
|
|
209
|
+
await addNote({ channels: [nextRelease.channel] }, nextRelease.gitTag, { cwd, env });
|
|
210
|
+
await push(options.repositoryUrl, { cwd, env });
|
|
211
|
+
await pushNotes(options.repositoryUrl, nextRelease.gitTag, { cwd, env });
|
|
212
|
+
logger.success(`Created tag ${nextRelease.gitTag}`);
|
|
50
213
|
}
|
|
51
214
|
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
});
|
|
56
|
-
resolvedOptions.originalRepositoryURL = resolvedOptions.repositoryUrl;
|
|
57
|
-
context.options = resolvedOptions;
|
|
215
|
+
const releases = await plugins.publish(context);
|
|
216
|
+
context.releases.push(...releases);
|
|
217
|
+
|
|
218
|
+
await plugins.success({ ...context, releases });
|
|
58
219
|
|
|
59
|
-
|
|
220
|
+
logger.success(
|
|
221
|
+
`Published release ${nextRelease.version} on ${nextRelease.channel ? nextRelease.channel : "default"} channel`
|
|
222
|
+
);
|
|
60
223
|
|
|
61
|
-
|
|
224
|
+
if (options.dryRun) {
|
|
225
|
+
logger.log(`Release note for version ${nextRelease.version}:`);
|
|
226
|
+
if (nextRelease.notes) {
|
|
227
|
+
context.stdout.write(await terminalOutput(nextRelease.notes));
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return pick(context, ["lastRelease", "commits", "nextRelease", "releases"]);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async function logErrors({ logger, stderr }, err) {
|
|
235
|
+
const errors = extractErrors(err).sort((error) => (error.semanticRelease ? -1 : 0));
|
|
236
|
+
for (const error of errors) {
|
|
237
|
+
if (error.semanticRelease) {
|
|
238
|
+
logger.error(`${error.code} ${error.message}`);
|
|
239
|
+
if (error.details) {
|
|
240
|
+
stderr.write(await terminalOutput(error.details)); // eslint-disable-line no-await-in-loop
|
|
241
|
+
}
|
|
242
|
+
} else {
|
|
243
|
+
logger.error("An error occurred while running semantic-release: %O", error);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
async function callFail(context, plugins, err) {
|
|
249
|
+
const errors = extractErrors(err).filter((err) => err.semanticRelease);
|
|
250
|
+
if (errors.length > 0) {
|
|
251
|
+
try {
|
|
252
|
+
await plugins.fail({ ...context, errors });
|
|
253
|
+
} catch (error) {
|
|
254
|
+
await logErrors(context, error);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
export default async (cliOptions = {}, { cwd = process.cwd(), env = process.env, stdout, stderr } = {}) => {
|
|
260
|
+
const { unhook } = hookStd(
|
|
261
|
+
{ silent: false, streams: [process.stdout, process.stderr, stdout, stderr].filter(Boolean) },
|
|
262
|
+
hideSensitive(env)
|
|
263
|
+
);
|
|
264
|
+
const context = {
|
|
265
|
+
cwd,
|
|
266
|
+
env,
|
|
267
|
+
stdout: stdout || process.stdout,
|
|
268
|
+
stderr: stderr || process.stderr,
|
|
269
|
+
envCi: envCi({ env, cwd }),
|
|
270
|
+
};
|
|
271
|
+
context.logger = getLogger(context);
|
|
272
|
+
context.logger.log(`Running ${pkg.name} version ${pkg.version}`);
|
|
273
|
+
try {
|
|
274
|
+
const { plugins, options } = await getConfig(context, cliOptions);
|
|
275
|
+
options.originalRepositoryURL = options.repositoryUrl;
|
|
276
|
+
context.options = options;
|
|
277
|
+
try {
|
|
278
|
+
const result = await run(context, plugins);
|
|
279
|
+
unhook();
|
|
280
|
+
return result;
|
|
281
|
+
} catch (error) {
|
|
282
|
+
await callFail(context, plugins, error);
|
|
283
|
+
throw error;
|
|
284
|
+
}
|
|
285
|
+
} catch (error) {
|
|
286
|
+
await logErrors(context, error);
|
|
287
|
+
unhook();
|
|
288
|
+
throw error;
|
|
289
|
+
}
|
|
62
290
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isString, mapValues, omit, remove, template } from "lodash-es";
|
|
2
|
+
import micromatch from "micromatch";
|
|
3
|
+
import { getBranches } from "../git.js";
|
|
4
|
+
|
|
5
|
+
export default async (repositoryUrl, { cwd }, branches) => {
|
|
6
|
+
const gitBranches = await getBranches(repositoryUrl, { cwd });
|
|
7
|
+
|
|
8
|
+
return branches.reduce(
|
|
9
|
+
(branches, branch) => [
|
|
10
|
+
...branches,
|
|
11
|
+
...remove(gitBranches, (name) => micromatch(gitBranches, branch.name).includes(name)).map((name) => ({
|
|
12
|
+
name,
|
|
13
|
+
...mapValues(omit(branch, "name"), (value) => (isString(value) ? template(value)({ name }) : value)),
|
|
14
|
+
})),
|
|
15
|
+
],
|
|
16
|
+
[]
|
|
17
|
+
);
|
|
18
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { escapeRegExp, template } from "lodash-es";
|
|
2
|
+
import semver from "semver";
|
|
3
|
+
import pReduce from "p-reduce";
|
|
4
|
+
import debugTags from "debug";
|
|
5
|
+
import { getTags, getTagsNotes } from "../../lib/git.js";
|
|
6
|
+
|
|
7
|
+
const debug = debugTags("semantic-release:get-tags");
|
|
8
|
+
|
|
9
|
+
export default async ({ cwd, env, options: { tagFormat } }, branches) => {
|
|
10
|
+
// Generate a regex to parse tags formatted with `tagFormat`
|
|
11
|
+
// by replacing the `version` variable in the template by `(.+)`.
|
|
12
|
+
// The `tagFormat` is compiled with space as the `version` as it's an invalid tag character,
|
|
13
|
+
// so it's guaranteed to no be present in the `tagFormat`.
|
|
14
|
+
const tagRegexp = `^${escapeRegExp(template(tagFormat)({ version: " " })).replace(" ", "(.+)")}`;
|
|
15
|
+
|
|
16
|
+
// Get the tags notes for all the tags in the repository
|
|
17
|
+
const tagsNotesMap = await getTagsNotes({ cwd, env });
|
|
18
|
+
|
|
19
|
+
return pReduce(
|
|
20
|
+
branches,
|
|
21
|
+
async (branches, branch) => {
|
|
22
|
+
const branchTags = await pReduce(
|
|
23
|
+
await getTags(branch.name, { cwd, env }),
|
|
24
|
+
async (branchTags, tag) => {
|
|
25
|
+
const [, version] = tag.match(tagRegexp) || [];
|
|
26
|
+
const channels = tagsNotesMap.has(tag) ? tagsNotesMap.get(tag).channels : [null];
|
|
27
|
+
return version && semver.valid(semver.clean(version))
|
|
28
|
+
? [...branchTags, { gitTag: tag, version, channels }]
|
|
29
|
+
: branchTags;
|
|
30
|
+
},
|
|
31
|
+
[]
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
debug("found tags for branch %s: %o", branch.name, branchTags);
|
|
35
|
+
return [...branches, { ...branch, tags: branchTags }];
|
|
36
|
+
},
|
|
37
|
+
[]
|
|
38
|
+
);
|
|
39
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { isRegExp, isString } from "lodash-es";
|
|
2
|
+
import AggregateError from "aggregate-error";
|
|
3
|
+
import pEachSeries from "p-each-series";
|
|
4
|
+
import * as DEFINITIONS from "../definitions/branches.js";
|
|
5
|
+
import getError from "../get-error.js";
|
|
6
|
+
import { fetch, fetchNotes, verifyBranchName } from "../git.js";
|
|
7
|
+
import expand from "./expand.js";
|
|
8
|
+
import getTags from "./get-tags.js";
|
|
9
|
+
import * as normalize from "./normalize.js";
|
|
10
|
+
|
|
11
|
+
export default async (repositoryUrl, ciBranch, context) => {
|
|
12
|
+
const { cwd, env } = context;
|
|
13
|
+
|
|
14
|
+
const remoteBranches = await expand(
|
|
15
|
+
repositoryUrl,
|
|
16
|
+
context,
|
|
17
|
+
context.options.branches.map((branch) => (isString(branch) || isRegExp(branch) ? { name: branch } : branch))
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
await pEachSeries(remoteBranches, async ({ name }) => {
|
|
21
|
+
await fetch(repositoryUrl, name, ciBranch, { cwd, env });
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
await fetchNotes(repositoryUrl, { cwd, env });
|
|
25
|
+
|
|
26
|
+
const branches = await getTags(context, remoteBranches);
|
|
27
|
+
|
|
28
|
+
const errors = [];
|
|
29
|
+
const branchesByType = Object.entries(DEFINITIONS).reduce(
|
|
30
|
+
// eslint-disable-next-line unicorn/no-fn-reference-in-iterator
|
|
31
|
+
(branchesByType, [type, { filter }]) => ({ [type]: branches.filter(filter), ...branchesByType }),
|
|
32
|
+
{}
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const result = Object.entries(DEFINITIONS).reduce((result, [type, { branchesValidator, branchValidator }]) => {
|
|
36
|
+
branchesByType[type].forEach((branch) => {
|
|
37
|
+
if (branchValidator && !branchValidator(branch)) {
|
|
38
|
+
errors.push(getError(`E${type.toUpperCase()}BRANCH`, { branch }));
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const branchesOfType = normalize[type](branchesByType);
|
|
43
|
+
|
|
44
|
+
if (!branchesValidator(branchesOfType)) {
|
|
45
|
+
errors.push(getError(`E${type.toUpperCase()}BRANCHES`, { branches: branchesOfType }));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return { ...result, [type]: branchesOfType };
|
|
49
|
+
}, {});
|
|
50
|
+
|
|
51
|
+
const duplicates = [...branches]
|
|
52
|
+
.map((branch) => branch.name)
|
|
53
|
+
.sort()
|
|
54
|
+
.filter((_, idx, array) => array[idx] === array[idx + 1] && array[idx] !== array[idx - 1]);
|
|
55
|
+
|
|
56
|
+
if (duplicates.length > 0) {
|
|
57
|
+
errors.push(getError("EDUPLICATEBRANCHES", { duplicates }));
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
await pEachSeries(branches, async (branch) => {
|
|
61
|
+
if (!(await verifyBranchName(branch.name))) {
|
|
62
|
+
errors.push(getError("EINVALIDBRANCHNAME", branch));
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
if (errors.length > 0) {
|
|
67
|
+
throw new AggregateError(errors);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return [...result.maintenance, ...result.release, ...result.prerelease];
|
|
71
|
+
};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { isNil, sortBy } from "lodash-es";
|
|
2
|
+
import { FIRST_RELEASE, RELEASE_TYPE } from "../definitions/constants.js";
|
|
3
|
+
import {
|
|
4
|
+
getFirstVersion,
|
|
5
|
+
getLatestVersion,
|
|
6
|
+
getLowerBound,
|
|
7
|
+
getRange,
|
|
8
|
+
getUpperBound,
|
|
9
|
+
getVersionDiff,
|
|
10
|
+
highest,
|
|
11
|
+
isMajorRange,
|
|
12
|
+
lowest,
|
|
13
|
+
tagsToVersions,
|
|
14
|
+
} from "../utils.js";
|
|
15
|
+
|
|
16
|
+
export function maintenance({ maintenance, release }) {
|
|
17
|
+
return sortBy(
|
|
18
|
+
maintenance.map(({ name, range, channel, ...rest }) => ({
|
|
19
|
+
...rest,
|
|
20
|
+
name,
|
|
21
|
+
range: range || name,
|
|
22
|
+
channel: isNil(channel) ? name : channel,
|
|
23
|
+
})),
|
|
24
|
+
"range"
|
|
25
|
+
).map(({ name, range, tags, ...rest }, idx, branches) => {
|
|
26
|
+
const versions = tagsToVersions(tags);
|
|
27
|
+
// Find the lower bound based on Maintenance branches
|
|
28
|
+
const maintenanceMin =
|
|
29
|
+
// If the current branch has a major range (1.x or 1.x.x) and the previous doesn't
|
|
30
|
+
isMajorRange(range) && branches[idx - 1] && !isMajorRange(branches[idx - 1].range)
|
|
31
|
+
? // Then the lowest bound is the upper bound of the previous branch range
|
|
32
|
+
getUpperBound(branches[idx - 1].range)
|
|
33
|
+
: // Otherwise the lowest bound is the lowest bound of the current branch range
|
|
34
|
+
getLowerBound(range);
|
|
35
|
+
// The actual lower bound is the highest version between the current branch last release and `maintenanceMin`
|
|
36
|
+
const min = highest(getLatestVersion(versions) || FIRST_RELEASE, maintenanceMin);
|
|
37
|
+
// Determine the first release of the default branch not present in any maintenance branch
|
|
38
|
+
const base =
|
|
39
|
+
(release[0] &&
|
|
40
|
+
(getFirstVersion(tagsToVersions(release[0].tags), branches) ||
|
|
41
|
+
getLatestVersion(tagsToVersions(release[0].tags)))) ||
|
|
42
|
+
FIRST_RELEASE;
|
|
43
|
+
// The upper bound is the lowest version between the `base` version and the upper bound of the current branch range
|
|
44
|
+
const max = lowest(base, getUpperBound(range));
|
|
45
|
+
const diff = getVersionDiff(min, max);
|
|
46
|
+
return {
|
|
47
|
+
...rest,
|
|
48
|
+
type: "maintenance",
|
|
49
|
+
name,
|
|
50
|
+
tags,
|
|
51
|
+
range: getRange(min, max),
|
|
52
|
+
accept: diff ? RELEASE_TYPE.slice(0, RELEASE_TYPE.indexOf(diff)) : [],
|
|
53
|
+
mergeRange: getRange(maintenanceMin, getUpperBound(range)),
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function release({ release }) {
|
|
59
|
+
if (release.length === 0) {
|
|
60
|
+
return release;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// The initial lastVersion is the last release from the base branch of `FIRST_RELEASE` (1.0.0)
|
|
64
|
+
let lastVersion = getLatestVersion(tagsToVersions(release[0].tags)) || FIRST_RELEASE;
|
|
65
|
+
|
|
66
|
+
return release.map(({ name, tags, channel, ...rest }, idx) => {
|
|
67
|
+
const versions = tagsToVersions(tags);
|
|
68
|
+
// The new lastVersion is the highest version between the current branch last release and the previous branch lastVersion
|
|
69
|
+
lastVersion = highest(getLatestVersion(versions), lastVersion);
|
|
70
|
+
// The upper bound is:
|
|
71
|
+
// - None if the current branch is the last one of the release branches
|
|
72
|
+
// - Otherwise, The upper bound is the lowest version that is present on the current branch but none of the previous ones
|
|
73
|
+
const bound =
|
|
74
|
+
release.length - 1 === idx
|
|
75
|
+
? undefined
|
|
76
|
+
: getFirstVersion(tagsToVersions(release[idx + 1].tags), release.slice(0, idx + 1));
|
|
77
|
+
|
|
78
|
+
const diff = bound ? getVersionDiff(lastVersion, bound) : null;
|
|
79
|
+
return {
|
|
80
|
+
...rest,
|
|
81
|
+
channel: idx === 0 ? channel : isNil(channel) ? name : channel,
|
|
82
|
+
tags,
|
|
83
|
+
type: "release",
|
|
84
|
+
name,
|
|
85
|
+
range: getRange(lastVersion, bound),
|
|
86
|
+
accept: bound ? RELEASE_TYPE.slice(0, RELEASE_TYPE.indexOf(diff)) : RELEASE_TYPE,
|
|
87
|
+
main: idx === 0,
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function prerelease({ prerelease }) {
|
|
93
|
+
return prerelease.map(({ name, prerelease, channel, tags, ...rest }) => {
|
|
94
|
+
const preid = prerelease === true ? name : prerelease;
|
|
95
|
+
return {
|
|
96
|
+
...rest,
|
|
97
|
+
channel: isNil(channel) ? name : channel,
|
|
98
|
+
type: "prerelease",
|
|
99
|
+
name,
|
|
100
|
+
prerelease: preid,
|
|
101
|
+
tags,
|
|
102
|
+
};
|
|
103
|
+
});
|
|
104
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { isNil, uniqBy } from "lodash-es";
|
|
2
|
+
import semver from "semver";
|
|
3
|
+
import { isMaintenanceRange } from "../utils.js";
|
|
4
|
+
|
|
5
|
+
export const maintenance = {
|
|
6
|
+
filter: ({ name, range }) => (!isNil(range) && range !== false) || isMaintenanceRange(name),
|
|
7
|
+
branchValidator: ({ range }) => (isNil(range) ? true : isMaintenanceRange(range)),
|
|
8
|
+
branchesValidator: (branches) => uniqBy(branches, ({ range }) => semver.validRange(range)).length === branches.length,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const prerelease = {
|
|
12
|
+
filter: ({ prerelease }) => !isNil(prerelease) && prerelease !== false,
|
|
13
|
+
branchValidator: ({ name, prerelease }) =>
|
|
14
|
+
Boolean(prerelease) && Boolean(semver.valid(`1.0.0-${prerelease === true ? name : prerelease}.1`)),
|
|
15
|
+
branchesValidator: (branches) => uniqBy(branches, "prerelease").length === branches.length,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const release = {
|
|
19
|
+
// eslint-disable-next-line unicorn/no-fn-reference-in-iterator
|
|
20
|
+
filter: (branch) => !maintenance.filter(branch) && !prerelease.filter(branch),
|
|
21
|
+
branchesValidator: (branches) => branches.length <= 3 && branches.length > 0,
|
|
22
|
+
};
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
+
export const RELEASE_TYPE = ["patch", "minor", "major"];
|
|
2
|
+
|
|
3
|
+
export const FIRST_RELEASE = "1.0.0";
|
|
4
|
+
|
|
5
|
+
export const FIRSTPRERELEASE = "1";
|
|
6
|
+
|
|
1
7
|
export const COMMIT_NAME = "semantic-release-bot";
|
|
2
8
|
|
|
3
9
|
export const COMMIT_EMAIL = "semantic-release-bot@martynus.net";
|
|
4
10
|
|
|
11
|
+
export const RELEASE_NOTES_SEPARATOR = "\n\n";
|
|
12
|
+
|
|
5
13
|
export const SECRET_REPLACEMENT = "[secure]";
|
|
6
14
|
|
|
7
15
|
export const SECRET_MIN_SIZE = 5;
|
|
8
16
|
|
|
9
17
|
export const GIT_NOTE_REF = "semantic-release";
|
|
10
|
-
|
|
11
|
-
export const SEMANTIC_RELEASE_DEFAULT_CONFIG = {
|
|
12
|
-
plugins: [
|
|
13
|
-
"@semantic-release/commit-analyzer",
|
|
14
|
-
"@semantic-release/release-notes-generator",
|
|
15
|
-
"@semantic-release/npm",
|
|
16
|
-
"@semantic-release/github",
|
|
17
|
-
],
|
|
18
|
-
};
|