semantic-release 26.0.0-beta.6 → 26.0.0-beta.7
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 +7 -0
- package/index.js +33 -259
- package/lib/definitions/constants.js +11 -12
- package/package.json +2 -1
- package/lib/branches/expand.js +0 -20
- package/lib/branches/get-tags.js +0 -42
- package/lib/branches/index.js +0 -71
- package/lib/branches/normalize.js +0 -104
- package/lib/definitions/branches.js +0 -22
- package/lib/definitions/plugins.js +0 -108
- package/lib/get-commits.js +0 -31
- package/lib/get-config.js +0 -98
- package/lib/get-error.js +0 -7
- package/lib/get-git-auth-url.js +0 -143
- package/lib/get-last-release.js +0 -48
- package/lib/get-logger.js +0 -19
- package/lib/get-next-version.js +0 -35
- package/lib/get-release-to-add.js +0 -59
- package/lib/git.js +0 -417
- package/lib/plugins/index.js +0 -103
- package/lib/plugins/normalize.js +0 -69
- package/lib/plugins/pipeline.js +0 -59
- package/lib/plugins/utils.js +0 -81
- package/lib/utils.js +0 -101
- package/lib/verify.js +0 -47
package/README.md
CHANGED
|
@@ -27,6 +27,13 @@
|
|
|
27
27
|
|
|
28
28
|
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.
|
|
29
29
|
|
|
30
|
+
## Core Engine
|
|
31
|
+
|
|
32
|
+
`semantic-release` now uses [`@semantic-release/core`](https://github.com/semantic-release/core) as its release engine.
|
|
33
|
+
For existing users, behavior stays the same: the `semantic-release` CLI, default plugin profile, and current configuration model remain backward compatible.
|
|
34
|
+
|
|
35
|
+
If you want to build a custom CLI or compose your own plugin stack directly, use `@semantic-release/core`.
|
|
36
|
+
|
|
30
37
|
> 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)
|
|
31
38
|
|
|
32
39
|
## Highlights
|
package/index.js
CHANGED
|
@@ -1,27 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { pick } from "lodash-es";
|
|
1
|
+
import semanticReleaseCore, { resolveConfig, getLogger, resolveEnvCi } from "@semantic-release/core";
|
|
3
2
|
import * as marked from "marked";
|
|
4
|
-
import
|
|
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
|
+
import { SEMANTIC_RELEASE_DEFAULT_CONFIG } from "./lib/definitions/constants.js";
|
|
22
4
|
|
|
23
|
-
|
|
24
|
-
const pkg = require("./package.json");
|
|
5
|
+
import pkg from "./package.json" with { type: "json" };
|
|
25
6
|
|
|
26
7
|
let markedOptionsSet = false;
|
|
27
8
|
async function terminalOutput(text) {
|
|
@@ -34,253 +15,46 @@ async function terminalOutput(text) {
|
|
|
34
15
|
return marked.parse(text);
|
|
35
16
|
}
|
|
36
17
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
18
|
+
export default async (
|
|
19
|
+
cliOptions = {},
|
|
20
|
+
{ cwd = process.cwd(), env = process.env, stdout = process.stdout, stderr = process.stderr } = {}
|
|
21
|
+
) => {
|
|
22
|
+
const envCiResult = resolveEnvCi({ env, cwd });
|
|
23
|
+
const { isCi, branch, prBranch, isPr } = envCiResult;
|
|
41
24
|
const ciBranch = isPr ? prBranch : branch;
|
|
25
|
+
const noCi = Boolean(cliOptions.noCi || cliOptions.ci === false);
|
|
42
26
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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.
|
|
48
|
-
Object.assign(env, {
|
|
49
|
-
GIT_AUTHOR_NAME: COMMIT_NAME,
|
|
50
|
-
GIT_AUTHOR_EMAIL: COMMIT_EMAIL,
|
|
51
|
-
GIT_COMMITTER_NAME: COMMIT_NAME,
|
|
52
|
-
GIT_COMMITTER_EMAIL: COMMIT_EMAIL,
|
|
53
|
-
...env,
|
|
54
|
-
GIT_ASKPASS: "echo",
|
|
55
|
-
GIT_TERMINAL_PROMPT: 0,
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
|
|
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
|
-
if (!(await isBranchUpToDate(options.repositoryUrl, context.branch.name, { cwd, env }))) {
|
|
87
|
-
logger.log(
|
|
88
|
-
`The local branch ${context.branch.name} is behind the remote one, therefore a new version won't be published.`
|
|
89
|
-
);
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
try {
|
|
94
|
-
await verifyAuth(options.repositoryUrl, { cwd, env });
|
|
95
|
-
} catch (error) {
|
|
96
|
-
logger.error(`The command "${error.command}" failed with the error message ${error.stderr}.`);
|
|
97
|
-
throw getError("EGITNOPERMISSION", context);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
logger.success(`Allowed to push to the Git repository`);
|
|
101
|
-
|
|
102
|
-
await plugins.verifyConditions(context);
|
|
103
|
-
|
|
104
|
-
const errors = [];
|
|
105
|
-
context.releases = [];
|
|
106
|
-
const releaseToAdd = getReleaseToAdd(context);
|
|
107
|
-
|
|
108
|
-
if (releaseToAdd) {
|
|
109
|
-
const { lastRelease, currentRelease, nextRelease } = releaseToAdd;
|
|
110
|
-
|
|
111
|
-
nextRelease.gitHead = await getTagHead(nextRelease.gitHead, { cwd, env });
|
|
112
|
-
currentRelease.gitHead = await getTagHead(currentRelease.gitHead, { cwd, env });
|
|
113
|
-
if (context.branch.mergeRange && !semver.satisfies(nextRelease.version, context.branch.mergeRange)) {
|
|
114
|
-
errors.push(getError("EINVALIDMAINTENANCEMERGE", { ...context, nextRelease }));
|
|
115
|
-
} else {
|
|
116
|
-
const commits = await getCommits({ ...context, lastRelease, nextRelease });
|
|
117
|
-
nextRelease.notes = await plugins.generateNotes({ ...context, commits, lastRelease, nextRelease });
|
|
118
|
-
|
|
119
|
-
if (options.dryRun) {
|
|
120
|
-
logger.warn(`Skip ${nextRelease.gitTag} tag creation in dry-run mode`);
|
|
121
|
-
} else {
|
|
122
|
-
await addNote({ channels: [...currentRelease.channels, nextRelease.channel] }, nextRelease.gitTag, {
|
|
123
|
-
cwd,
|
|
124
|
-
env,
|
|
125
|
-
});
|
|
126
|
-
await push(options.repositoryUrl, { cwd, env });
|
|
127
|
-
await pushNotes(options.repositoryUrl, nextRelease.gitTag, {
|
|
128
|
-
cwd,
|
|
129
|
-
env,
|
|
130
|
-
});
|
|
131
|
-
logger.success(
|
|
132
|
-
`Add ${nextRelease.channel ? `channel ${nextRelease.channel}` : "default channel"} to tag ${
|
|
133
|
-
nextRelease.gitTag
|
|
134
|
-
}`
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
context.branch.tags.push({
|
|
139
|
-
version: nextRelease.version,
|
|
140
|
-
channel: nextRelease.channel,
|
|
141
|
-
gitTag: nextRelease.gitTag,
|
|
142
|
-
gitHead: nextRelease.gitHead,
|
|
143
|
-
});
|
|
144
|
-
|
|
145
|
-
const releases = await plugins.addChannel({ ...context, commits, lastRelease, currentRelease, nextRelease });
|
|
146
|
-
context.releases.push(...releases);
|
|
147
|
-
await plugins.success({ ...context, lastRelease, commits, nextRelease, releases });
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (errors.length > 0) {
|
|
152
|
-
throw new AggregateError(errors);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
context.lastRelease = getLastRelease(context);
|
|
156
|
-
if (context.lastRelease.gitHead) {
|
|
157
|
-
context.lastRelease.gitHead = await getTagHead(context.lastRelease.gitHead, { cwd, env });
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (context.lastRelease.gitTag) {
|
|
161
|
-
logger.log(
|
|
162
|
-
`Found git tag ${context.lastRelease.gitTag} associated with version ${context.lastRelease.version} on branch ${context.branch.name}`
|
|
163
|
-
);
|
|
164
|
-
} else {
|
|
165
|
-
logger.log(`No git tag version found on branch ${context.branch.name}`);
|
|
166
|
-
}
|
|
27
|
+
const shouldAutoDryRun = !isCi && !cliOptions.dryRun && !noCi;
|
|
28
|
+
const effectiveCliOptions = shouldAutoDryRun ? { ...cliOptions, dryRun: true } : cliOptions;
|
|
29
|
+
const shouldSkipRelease = isCi && isPr && !noCi;
|
|
167
30
|
|
|
168
|
-
context
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
31
|
+
const context = {
|
|
32
|
+
cwd,
|
|
33
|
+
env,
|
|
34
|
+
stdout,
|
|
35
|
+
stderr,
|
|
36
|
+
envCi: envCiResult,
|
|
174
37
|
};
|
|
175
|
-
if (!nextRelease.type) {
|
|
176
|
-
logger.log("There are no relevant changes, so no new version is released.");
|
|
177
|
-
return context.releases.length > 0 ? { releases: context.releases } : false;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
context.nextRelease = nextRelease;
|
|
181
|
-
nextRelease.version = getNextVersion(context);
|
|
182
|
-
nextRelease.gitTag = makeTag(options.tagFormat, nextRelease.version);
|
|
183
|
-
nextRelease.name = nextRelease.gitTag;
|
|
184
|
-
|
|
185
|
-
if (context.branch.type !== "prerelease" && !semver.satisfies(nextRelease.version, context.branch.range)) {
|
|
186
|
-
throw getError("EINVALIDNEXTVERSION", {
|
|
187
|
-
...context,
|
|
188
|
-
validBranches: context.branches.filter(
|
|
189
|
-
({ type, accept }) => type !== "prerelease" && accept.includes(nextRelease.type)
|
|
190
|
-
),
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
38
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
nextRelease.notes = await plugins.generateNotes(context);
|
|
197
|
-
|
|
198
|
-
await plugins.prepare(context);
|
|
39
|
+
context.logger = getLogger(context);
|
|
199
40
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
// Create the tag before calling the publish plugins as some require the tag to exists
|
|
204
|
-
await tag(nextRelease.gitTag, nextRelease.gitHead, { cwd, env });
|
|
205
|
-
await addNote({ channels: [nextRelease.channel] }, nextRelease.gitTag, { cwd, env });
|
|
206
|
-
await push(options.repositoryUrl, { cwd, env });
|
|
207
|
-
await pushNotes(options.repositoryUrl, nextRelease.gitTag, { cwd, env });
|
|
208
|
-
logger.success(`Created tag ${nextRelease.gitTag}`);
|
|
41
|
+
context.logger.log(`Running ${pkg.name} version ${pkg.version}`);
|
|
42
|
+
if (shouldAutoDryRun) {
|
|
43
|
+
context.logger.warn("This run was not triggered in a known CI environment, running in dry-run mode.");
|
|
209
44
|
}
|
|
210
45
|
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
await plugins.success({ ...context, releases });
|
|
215
|
-
|
|
216
|
-
logger.success(
|
|
217
|
-
`Published release ${nextRelease.version} on ${nextRelease.channel ? nextRelease.channel : "default"} channel`
|
|
218
|
-
);
|
|
219
|
-
|
|
220
|
-
if (options.dryRun) {
|
|
221
|
-
logger.log(`Release note for version ${nextRelease.version}:`);
|
|
222
|
-
if (nextRelease.notes) {
|
|
223
|
-
context.stdout.write(await terminalOutput(nextRelease.notes));
|
|
224
|
-
}
|
|
46
|
+
if (shouldSkipRelease) {
|
|
47
|
+
context.logger.log("This run was triggered by a pull request and therefore a new version won't be published.");
|
|
48
|
+
return false;
|
|
225
49
|
}
|
|
226
50
|
|
|
227
|
-
|
|
228
|
-
|
|
51
|
+
const { options: resolvedOptions, plugins } = await resolveConfig(context, effectiveCliOptions, {
|
|
52
|
+
baseConfig: SEMANTIC_RELEASE_DEFAULT_CONFIG,
|
|
53
|
+
buildPlugins: true,
|
|
54
|
+
});
|
|
55
|
+
context.options = resolvedOptions;
|
|
229
56
|
|
|
230
|
-
|
|
231
|
-
const errors = extractErrors(err).sort((error) => (error.semanticRelease ? -1 : 0));
|
|
232
|
-
for (const error of errors) {
|
|
233
|
-
if (error.semanticRelease) {
|
|
234
|
-
logger.error(`${error.code} ${error.message}`);
|
|
235
|
-
if (error.details) {
|
|
236
|
-
stderr.write(await terminalOutput(error.details)); // eslint-disable-line no-await-in-loop
|
|
237
|
-
}
|
|
238
|
-
} else {
|
|
239
|
-
logger.error("An error occurred while running semantic-release: %O", error);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
async function callFail(context, plugins, err) {
|
|
245
|
-
const errors = extractErrors(err).filter((err) => err.semanticRelease);
|
|
246
|
-
if (errors.length > 0) {
|
|
247
|
-
try {
|
|
248
|
-
await plugins.fail({ ...context, errors });
|
|
249
|
-
} catch (error) {
|
|
250
|
-
await logErrors(context, error);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
}
|
|
57
|
+
const result = await semanticReleaseCore({ context, plugins, formatOutput: terminalOutput });
|
|
254
58
|
|
|
255
|
-
|
|
256
|
-
const { unhook } = hookStd(
|
|
257
|
-
{ silent: false, streams: [process.stdout, process.stderr, stdout, stderr].filter(Boolean) },
|
|
258
|
-
hideSensitive(env)
|
|
259
|
-
);
|
|
260
|
-
const context = {
|
|
261
|
-
cwd,
|
|
262
|
-
env,
|
|
263
|
-
stdout: stdout || process.stdout,
|
|
264
|
-
stderr: stderr || process.stderr,
|
|
265
|
-
envCi: envCi({ env, cwd }),
|
|
266
|
-
};
|
|
267
|
-
context.logger = getLogger(context);
|
|
268
|
-
context.logger.log(`Running ${pkg.name} version ${pkg.version}`);
|
|
269
|
-
try {
|
|
270
|
-
const { plugins, options } = await getConfig(context, cliOptions);
|
|
271
|
-
options.originalRepositoryURL = options.repositoryUrl;
|
|
272
|
-
context.options = options;
|
|
273
|
-
try {
|
|
274
|
-
const result = await run(context, plugins);
|
|
275
|
-
unhook();
|
|
276
|
-
return result;
|
|
277
|
-
} catch (error) {
|
|
278
|
-
await callFail(context, plugins, error);
|
|
279
|
-
throw error;
|
|
280
|
-
}
|
|
281
|
-
} catch (error) {
|
|
282
|
-
await logErrors(context, error);
|
|
283
|
-
unhook();
|
|
284
|
-
throw error;
|
|
285
|
-
}
|
|
59
|
+
return result;
|
|
286
60
|
};
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
export const RELEASE_TYPE = ["patch", "minor", "major"];
|
|
2
|
-
|
|
3
|
-
export const FIRST_RELEASE = "1.0.0";
|
|
4
|
-
|
|
5
|
-
export const FIRSTPRERELEASE = "1";
|
|
6
|
-
|
|
7
|
-
export const COMMIT_NAME = "semantic-release-bot";
|
|
8
|
-
|
|
9
|
-
export const COMMIT_EMAIL = "semantic-release-bot@martynus.net";
|
|
10
|
-
|
|
11
|
-
export const RELEASE_NOTES_SEPARATOR = "\n\n";
|
|
12
|
-
|
|
13
1
|
export const SECRET_REPLACEMENT = "[secure]";
|
|
14
2
|
|
|
15
3
|
export const SECRET_MIN_SIZE = 5;
|
|
16
4
|
|
|
17
5
|
export const GIT_NOTE_REF = "semantic-release";
|
|
6
|
+
|
|
7
|
+
export const RELEASE_TYPE = ["patch", "minor", "major"];
|
|
8
|
+
|
|
9
|
+
export const SEMANTIC_RELEASE_DEFAULT_CONFIG = {
|
|
10
|
+
plugins: [
|
|
11
|
+
"@semantic-release/commit-analyzer",
|
|
12
|
+
"@semantic-release/release-notes-generator",
|
|
13
|
+
"@semantic-release/npm",
|
|
14
|
+
"@semantic-release/github",
|
|
15
|
+
],
|
|
16
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "semantic-release",
|
|
3
3
|
"description": "Automated semver compliant package publishing",
|
|
4
|
-
"version": "26.0.0-beta.
|
|
4
|
+
"version": "26.0.0-beta.7",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "Stephan Bönnemann <stephan@boennemann.me> (http://boennemann.me)",
|
|
7
7
|
"ava": {
|
|
@@ -28,6 +28,7 @@
|
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@semantic-release/commit-analyzer": "^14.0.0-beta.4",
|
|
31
|
+
"@semantic-release/core": "^1.0.0-beta.7",
|
|
31
32
|
"@semantic-release/error": "^4.0.0",
|
|
32
33
|
"@semantic-release/github": "^12.0.0",
|
|
33
34
|
"@semantic-release/npm": "^14.0.0-beta.2",
|
package/lib/branches/expand.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
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) =>
|
|
14
|
-
isString(value) ? template(value, { evaluate: false, escape: false })({ name }) : value
|
|
15
|
-
),
|
|
16
|
-
})),
|
|
17
|
-
],
|
|
18
|
-
[]
|
|
19
|
-
);
|
|
20
|
-
};
|
package/lib/branches/get-tags.js
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
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, { evaluate: false, escape: false })({ version: " " })).replace(
|
|
15
|
-
" ",
|
|
16
|
-
"(.+)"
|
|
17
|
-
)}`;
|
|
18
|
-
|
|
19
|
-
// Get the tags notes for all the tags in the repository
|
|
20
|
-
const tagsNotesMap = await getTagsNotes({ cwd, env });
|
|
21
|
-
|
|
22
|
-
return pReduce(
|
|
23
|
-
branches,
|
|
24
|
-
async (branches, branch) => {
|
|
25
|
-
const branchTags = await pReduce(
|
|
26
|
-
await getTags(branch.name, { cwd, env }),
|
|
27
|
-
async (branchTags, tag) => {
|
|
28
|
-
const [, version] = tag.match(tagRegexp) || [];
|
|
29
|
-
const channels = tagsNotesMap.has(tag) ? tagsNotesMap.get(tag).channels : [null];
|
|
30
|
-
return version && semver.valid(semver.clean(version))
|
|
31
|
-
? [...branchTags, { gitTag: tag, version, channels }]
|
|
32
|
-
: branchTags;
|
|
33
|
-
},
|
|
34
|
-
[]
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
debug("found tags for branch %s: %o", branch.name, branchTags);
|
|
38
|
-
return [...branches, { ...branch, tags: branchTags }];
|
|
39
|
-
},
|
|
40
|
-
[]
|
|
41
|
-
);
|
|
42
|
-
};
|
package/lib/branches/index.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,104 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
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
|
-
};
|