semantic-release 25.0.2 → 25.0.4

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.
@@ -1,104 +0,0 @@
1
- import { isNil, sortBy } from "lodash-es";
2
- import semverDiff from "semver-diff";
3
- import { FIRST_RELEASE, RELEASE_TYPE } from "../definitions/constants.js";
4
- import {
5
- getFirstVersion,
6
- getLatestVersion,
7
- getLowerBound,
8
- getRange,
9
- getUpperBound,
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 = semverDiff(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 ? semverDiff(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
- };
@@ -1,298 +0,0 @@
1
- import { inspect } from "node:util";
2
- import { createRequire } from "node:module";
3
- import { isString, toLower, trim } from "lodash-es";
4
- import { RELEASE_TYPE } from "./constants.js";
5
-
6
- const require = createRequire(import.meta.url);
7
- const pkg = require("../../package.json");
8
-
9
- const [homepage] = pkg.homepage.split("#");
10
- const stringify = (object) =>
11
- isString(object) ? object : inspect(object, { breakLength: Infinity, depth: 2, maxArrayLength: 5 });
12
- const linkify = (file) => `${homepage}/blob/master/${file}`;
13
- const wordsList = (words) =>
14
- `${words.slice(0, -1).join(", ")}${words.length > 1 ? ` or ${words[words.length - 1]}` : trim(words[0])}`;
15
-
16
- export function ENOGITREPO({ cwd }) {
17
- return {
18
- message: "Not running from a git repository.",
19
- details: `The \`semantic-release\` command must be executed from a Git repository.
20
-
21
- The current working directory is \`${cwd}\`.
22
-
23
- Please verify your CI configuration to make sure the \`semantic-release\` command is executed from the root of the cloned repository.`,
24
- };
25
- }
26
-
27
- export function ENOREPOURL() {
28
- return {
29
- message: "The `repositoryUrl` option is required.",
30
- details: `The [repositoryUrl option](${linkify(
31
- "docs/usage/configuration.md#repositoryurl"
32
- )}) cannot be determined from the semantic-release configuration, the \`package.json\` nor the [git origin url](https://git-scm.com/book/en/v2/Git-Basics-Working-with-Remotes).
33
-
34
- Please make sure to add the \`repositoryUrl\` to the [semantic-release configuration] (${linkify(
35
- "docs/usage/configuration.md"
36
- )}).`,
37
- };
38
- }
39
-
40
- export function EGITNOPERMISSION({ options: { repositoryUrl }, branch: { name } }) {
41
- return {
42
- message: "Cannot push to the Git repository.",
43
- details: `**semantic-release** cannot push the version tag to the branch \`${name}\` on the remote Git repository with URL \`${repositoryUrl}\`.
44
-
45
- This can be caused by:
46
- - a misconfiguration of the [repositoryUrl](${linkify("docs/usage/configuration.md#repositoryurl")}) option
47
- - the repository being unavailable
48
- - or missing push permission for the user configured via the [Git credentials on your CI environment](${linkify(
49
- "docs/usage/ci-configuration.md#authentication"
50
- )})`,
51
- };
52
- }
53
-
54
- export function EINVALIDTAGFORMAT({ options: { tagFormat } }) {
55
- return {
56
- message: "Invalid `tagFormat` option.",
57
- details: `The [tagFormat](${linkify(
58
- "docs/usage/configuration.md#tagformat"
59
- )}) must compile to a [valid Git reference](https://git-scm.com/docs/git-check-ref-format#_description).
60
-
61
- Your configuration for the \`tagFormat\` option is \`${stringify(tagFormat)}\`.`,
62
- };
63
- }
64
-
65
- export function ETAGNOVERSION({ options: { tagFormat } }) {
66
- return {
67
- message: "Invalid `tagFormat` option.",
68
- details: `The [tagFormat](${linkify(
69
- "docs/usage/configuration.md#tagformat"
70
- )}) option must contain the variable \`version\` exactly once.
71
-
72
- Your configuration for the \`tagFormat\` option is \`${stringify(tagFormat)}\`.`,
73
- };
74
- }
75
-
76
- export function EPLUGINCONF({ type, required, pluginConf }) {
77
- return {
78
- message: `The \`${type}\` plugin configuration is invalid.`,
79
- details: `The [${type} plugin configuration](${linkify(`docs/usage/plugins.md#${toLower(type)}-plugin`)}) ${
80
- required ? "is required and " : ""
81
- } must be a single or an array of plugins definition. A plugin definition is an npm module name, optionally wrapped in an array with an object.
82
-
83
- Your configuration for the \`${type}\` plugin is \`${stringify(pluginConf)}\`.`,
84
- };
85
- }
86
-
87
- export function EPLUGINSCONF({ plugin }) {
88
- return {
89
- message: "The `plugins` configuration is invalid.",
90
- details: `The [plugins](${linkify(
91
- "docs/usage/configuration.md#plugins"
92
- )}) option must be an array of plugin definitions. A plugin definition is an npm module name, optionally wrapped in an array with an object.
93
-
94
- The invalid configuration is \`${stringify(plugin)}\`.`,
95
- };
96
- }
97
-
98
- export function EPLUGIN({ pluginName, type }) {
99
- return {
100
- message: `A plugin configured in the step ${type} is not a valid semantic-release plugin.`,
101
- details: `A valid \`${type}\` **semantic-release** plugin must be a function or an object with a function in the property \`${type}\`.
102
-
103
- The plugin \`${pluginName}\` doesn't have the property \`${type}\` and cannot be used for the \`${type}\` step.
104
-
105
- Please refer to the \`${pluginName}\` and [semantic-release plugins configuration](${linkify(
106
- "docs/usage/plugins.md"
107
- )}) documentation for more details.`,
108
- };
109
- }
110
-
111
- export function EANALYZECOMMITSOUTPUT({ result, pluginName }) {
112
- return {
113
- message: "The `analyzeCommits` plugin returned an invalid value. It must return a valid semver release type.",
114
- details: `The \`analyzeCommits\` plugin must return a valid [semver](https://semver.org) release type. The valid values are: ${RELEASE_TYPE.map(
115
- (type) => `\`${type}\``
116
- ).join(", ")}.
117
-
118
- The \`analyzeCommits\` function of the \`${pluginName}\` returned \`${stringify(result)}\` instead.
119
-
120
- We recommend to report the issue to the \`${pluginName}\` authors, providing the following informations:
121
- - The **semantic-release** version: \`${pkg.version}\`
122
- - The **semantic-release** logs from your CI job
123
- - The value returned by the plugin: \`${stringify(result)}\`
124
- - A link to the **semantic-release** plugin developer guide: [${linkify("docs/developer-guide/plugin.md")}](${linkify(
125
- "docs/developer-guide/plugin.md"
126
- )})`,
127
- };
128
- }
129
-
130
- export function EGENERATENOTESOUTPUT({ result, pluginName }) {
131
- return {
132
- message: "The `generateNotes` plugin returned an invalid value. It must return a `String`.",
133
- details: `The \`generateNotes\` plugin must return a \`String\`.
134
-
135
- The \`generateNotes\` function of the \`${pluginName}\` returned \`${stringify(result)}\` instead.
136
-
137
- We recommend to report the issue to the \`${pluginName}\` authors, providing the following informations:
138
- - The **semantic-release** version: \`${pkg.version}\`
139
- - The **semantic-release** logs from your CI job
140
- - The value returned by the plugin: \`${stringify(result)}\`
141
- - A link to the **semantic-release** plugin developer guide: [${linkify("docs/developer-guide/plugin.md")}](${linkify(
142
- "docs/developer-guide/plugin.md"
143
- )})`,
144
- };
145
- }
146
-
147
- export function EPUBLISHOUTPUT({ result, pluginName }) {
148
- return {
149
- message: "A `publish` plugin returned an invalid value. It must return an `Object`.",
150
- details: `The \`publish\` plugins must return an \`Object\`.
151
-
152
- The \`publish\` function of the \`${pluginName}\` returned \`${stringify(result)}\` instead.
153
-
154
- We recommend to report the issue to the \`${pluginName}\` authors, providing the following informations:
155
- - The **semantic-release** version: \`${pkg.version}\`
156
- - The **semantic-release** logs from your CI job
157
- - The value returned by the plugin: \`${stringify(result)}\`
158
- - A link to the **semantic-release** plugin developer guide: [${linkify("docs/developer-guide/plugin.md")}](${linkify(
159
- "docs/developer-guide/plugin.md"
160
- )})`,
161
- };
162
- }
163
-
164
- export function EADDCHANNELOUTPUT({ result, pluginName }) {
165
- return {
166
- message: "A `addChannel` plugin returned an invalid value. It must return an `Object`.",
167
- details: `The \`addChannel\` plugins must return an \`Object\`.
168
-
169
- The \`addChannel\` function of the \`${pluginName}\` returned \`${stringify(result)}\` instead.
170
-
171
- We recommend to report the issue to the \`${pluginName}\` authors, providing the following informations:
172
- - The **semantic-release** version: \`${pkg.version}\`
173
- - The **semantic-release** logs from your CI job
174
- - The value returned by the plugin: \`${stringify(result)}\`
175
- - A link to the **semantic-release** plugin developer guide: [${linkify("docs/developer-guide/plugin.md")}](${linkify(
176
- "docs/developer-guide/plugin.md"
177
- )})`,
178
- };
179
- }
180
-
181
- export function EINVALIDBRANCH({ branch }) {
182
- return {
183
- message: "A branch is invalid in the `branches` configuration.",
184
- details: `Each branch in the [branches configuration](${linkify(
185
- "docs/usage/configuration.md#branches"
186
- )}) must be either a string, a regexp or an object with a \`name\` property.
187
-
188
- Your configuration for the problematic branch is \`${stringify(branch)}\`.`,
189
- };
190
- }
191
-
192
- export function EINVALIDBRANCHNAME({ branch }) {
193
- return {
194
- message: "A branch name is invalid in the `branches` configuration.",
195
- details: `Each branch in the [branches configuration](${linkify(
196
- "docs/usage/configuration.md#branches"
197
- )}) must be a [valid Git reference](https://git-scm.com/docs/git-check-ref-format#_description).
198
-
199
- Your configuration for the problematic branch is \`${stringify(branch)}\`.`,
200
- };
201
- }
202
-
203
- export function EDUPLICATEBRANCHES({ duplicates }) {
204
- return {
205
- message: "The `branches` configuration has duplicate branches.",
206
- details: `Each branch in the [branches configuration](${linkify(
207
- "docs/usage/configuration.md#branches"
208
- )}) must havea unique name.
209
-
210
- Your configuration contains duplicates for the following branch names: \`${stringify(duplicates)}\`.`,
211
- };
212
- }
213
-
214
- export function EMAINTENANCEBRANCH({ branch }) {
215
- return {
216
- message: "A maintenance branch is invalid in the `branches` configuration.",
217
- details: `Each maintenance branch in the [branches configuration](${linkify(
218
- "docs/usage/configuration.md#branches"
219
- )}) must have a \`range\` property formatted like \`N.x\`, \`N.x.x\` or \`N.N.x\` (\`N\` is a number).
220
-
221
- Your configuration for the problematic branch is \`${stringify(branch)}\`.`,
222
- };
223
- }
224
-
225
- export function EMAINTENANCEBRANCHES({ branches }) {
226
- return {
227
- message: "The maintenance branches are invalid in the `branches` configuration.",
228
- details: `Each maintenance branch in the [branches configuration](${linkify(
229
- "docs/usage/configuration.md#branches"
230
- )}) must have a unique \`range\` property and must exist on the remote repository.
231
-
232
- Your configuration for the problematic branches is \`${stringify(branches)}\`.`,
233
- };
234
- }
235
-
236
- export function ERELEASEBRANCHES({ branches }) {
237
- return {
238
- message: "The release branches are invalid in the `branches` configuration.",
239
- details: `A minimum of 1 and a maximum of 3 release branches are required in the [branches configuration](${linkify(
240
- "docs/usage/configuration.md#branches"
241
- )}). These branches must exist on the remote repository.
242
-
243
- This may occur if your repository does not have a release branch, such as \`master\` or \`main\`.
244
-
245
- Your configuration for the problematic branches is \`${stringify(branches)}\`.`,
246
- };
247
- }
248
-
249
- export function EPRERELEASEBRANCH({ branch }) {
250
- return {
251
- message: "A pre-release branch configuration is invalid in the `branches` configuration.",
252
- details: `Each pre-release branch in the [branches configuration](${linkify(
253
- "docs/usage/configuration.md#branches"
254
- )}) must have a \`prerelease\` property valid per the [Semantic Versioning Specification](https://semver.org/#spec-item-9). If the \`prerelease\` property is set to \`true\`, then the \`name\` property is used instead. Additionally, each pre-release branch must exist on the remote repository.
255
-
256
- Your configuration for the problematic branch is \`${stringify(branch)}\`.`,
257
- };
258
- }
259
-
260
- export function EPRERELEASEBRANCHES({ branches }) {
261
- return {
262
- message: "The pre-release branches are invalid in the `branches` configuration.",
263
- details: `Each pre-release branch in the [branches configuration](${linkify(
264
- "docs/usage/configuration.md#branches"
265
- )}) must have a unique \`prerelease\` property. If the \`prerelease\` property is set to \`true\`, then the \`name\` property is used instead.
266
-
267
- Your configuration for the problematic branches is \`${stringify(branches)}\`.`,
268
- };
269
- }
270
-
271
- export function EINVALIDNEXTVERSION({ nextRelease: { version }, branch: { name, range }, commits, validBranches }) {
272
- return {
273
- message: `The release \`${version}\` on branch \`${name}\` cannot be published as it is out of range.`,
274
- details: `Based on the releases published on other branches, only versions within the range \`${range}\` can be published from branch \`${name}\`.
275
-
276
- The following commit${commits.length > 1 ? "s are" : " is"} responsible for the invalid release:
277
- ${commits.map(({ commit: { short }, subject }) => `- ${subject} (${short})`).join("\n")}
278
-
279
- ${
280
- commits.length > 1 ? "Those commits" : "This commit"
281
- } should be moved to a valid branch with [git merge](https://git-scm.com/docs/git-merge) or [git cherry-pick](https://git-scm.com/docs/git-cherry-pick) and removed from branch \`${name}\` with [git revert](https://git-scm.com/docs/git-revert) or [git reset](https://git-scm.com/docs/git-reset).
282
-
283
- A valid branch could be ${wordsList(validBranches.map(({ name }) => `\`${name}\``))}.
284
-
285
- See the [workflow configuration documentation](${linkify("docs/usage/workflow-configuration.md")}) for more details.`,
286
- };
287
- }
288
-
289
- export function EINVALIDMAINTENANCEMERGE({ nextRelease: { channel, gitTag, version }, branch: { mergeRange, name } }) {
290
- return {
291
- message: `The release \`${version}\` on branch \`${name}\` cannot be published as it is out of range.`,
292
- details: `Only releases within the range \`${mergeRange}\` can be merged into the maintenance branch \`${name}\` and published to the \`${channel}\` distribution channel.
293
-
294
- The branch \`${name}\` head should be [reset](https://git-scm.com/docs/git-reset) to a previous commit so the commit with tag \`${gitTag}\` is removed from the branch history.
295
-
296
- See the [workflow configuration documentation](${linkify("docs/usage/workflow-configuration.md")}) for more details.`,
297
- };
298
- }
@@ -1,108 +0,0 @@
1
- /* eslint require-atomic-updates: off */
2
-
3
- import { isPlainObject, isString } from "lodash-es";
4
- import { getGitHead } from "../git.js";
5
- import hideSensitive from "../hide-sensitive.js";
6
- import { hideSensitiveValues } from "../utils.js";
7
- import { RELEASE_NOTES_SEPARATOR, RELEASE_TYPE } from "./constants.js";
8
-
9
- export default {
10
- verifyConditions: {
11
- required: false,
12
- dryRun: true,
13
- pipelineConfig: () => ({ settleAll: true }),
14
- },
15
- analyzeCommits: {
16
- default: ["@semantic-release/commit-analyzer"],
17
- required: true,
18
- dryRun: true,
19
- outputValidator: (output) => !output || RELEASE_TYPE.includes(output),
20
- preprocess: ({ commits, ...inputs }) => ({
21
- ...inputs,
22
- commits: commits.filter((commit) => !/\[skip\s+release]|\[release\s+skip]/i.test(commit.message)),
23
- }),
24
- postprocess: (results) =>
25
- RELEASE_TYPE[
26
- results.reduce((highest, result) => {
27
- const typeIndex = RELEASE_TYPE.indexOf(result);
28
- return typeIndex > highest ? typeIndex : highest;
29
- }, -1)
30
- ],
31
- },
32
- verifyRelease: {
33
- required: false,
34
- dryRun: true,
35
- pipelineConfig: () => ({ settleAll: true }),
36
- },
37
- generateNotes: {
38
- required: false,
39
- dryRun: true,
40
- outputValidator: (output) => !output || isString(output),
41
- pipelineConfig: () => ({
42
- getNextInput: ({ nextRelease, ...context }, notes) => ({
43
- ...context,
44
- nextRelease: {
45
- ...nextRelease,
46
- notes: `${nextRelease.notes ? `${nextRelease.notes}${RELEASE_NOTES_SEPARATOR}` : ""}${notes}`,
47
- },
48
- }),
49
- }),
50
- postprocess: (results, { env }) => hideSensitive(env)(results.filter(Boolean).join(RELEASE_NOTES_SEPARATOR)),
51
- },
52
- prepare: {
53
- required: false,
54
- dryRun: false,
55
- pipelineConfig: ({ generateNotes }) => ({
56
- getNextInput: async (context) => {
57
- const newGitHead = await getGitHead({ cwd: context.cwd });
58
- // If previous prepare plugin has created a commit (gitHead changed)
59
- if (context.nextRelease.gitHead !== newGitHead) {
60
- context.nextRelease.gitHead = newGitHead;
61
- // Regenerate the release notes
62
- context.nextRelease.notes = await generateNotes(context);
63
- }
64
-
65
- // Call the next prepare plugin with the updated `nextRelease`
66
- return context;
67
- },
68
- }),
69
- },
70
- publish: {
71
- required: false,
72
- dryRun: false,
73
- outputValidator: (output) => !output || isPlainObject(output),
74
- pipelineConfig: () => ({
75
- // Add `nextRelease` and plugin properties to published release
76
- transform: (release, step, { nextRelease }) => ({
77
- ...(release === false ? {} : nextRelease),
78
- ...release,
79
- ...step,
80
- }),
81
- }),
82
- },
83
- addChannel: {
84
- required: false,
85
- dryRun: false,
86
- outputValidator: (output) => !output || isPlainObject(output),
87
- pipelineConfig: () => ({
88
- // Add `nextRelease` and plugin properties to published release
89
- transform: (release, step, { nextRelease }) => ({
90
- ...(release === false ? {} : nextRelease),
91
- ...release,
92
- ...step,
93
- }),
94
- }),
95
- },
96
- success: {
97
- required: false,
98
- dryRun: false,
99
- pipelineConfig: () => ({ settleAll: true }),
100
- preprocess: ({ releases, env, ...inputs }) => ({ ...inputs, env, releases: hideSensitiveValues(env, releases) }),
101
- },
102
- fail: {
103
- required: false,
104
- dryRun: false,
105
- pipelineConfig: () => ({ settleAll: true }),
106
- preprocess: ({ errors, env, ...inputs }) => ({ ...inputs, env, errors: hideSensitiveValues(env, errors) }),
107
- },
108
- };
@@ -1,31 +0,0 @@
1
- import debugCommits from "debug";
2
- import { getCommits } from "./git.js";
3
-
4
- const debug = debugCommits("semantic-release:get-commits");
5
-
6
- /**
7
- * Retrieve the list of commits on the current branch since the commit sha associated with the last release, or all the commits of the current branch if there is no last released version.
8
- *
9
- * @param {Object} context semantic-release context.
10
- *
11
- * @return {Promise<Array<Object>>} The list of commits on the branch `branch` since the last release.
12
- */
13
- export default async ({
14
- cwd,
15
- env,
16
- lastRelease: { gitHead: from },
17
- nextRelease: { gitHead: to = "HEAD" } = {},
18
- logger,
19
- }) => {
20
- if (from) {
21
- debug("Use from: %s", from);
22
- } else {
23
- logger.log("No previous release found, retrieving all commits");
24
- }
25
-
26
- const commits = await getCommits(from, to, { cwd, env });
27
-
28
- logger.log(`Found ${commits.length} commits since last release`);
29
- debug("Parsed commits: %o", commits);
30
- return commits;
31
- };
package/lib/get-config.js DELETED
@@ -1,98 +0,0 @@
1
- import { dirname } from "node:path";
2
- import { fileURLToPath } from "node:url";
3
-
4
- import { castArray, isNil, isPlainObject, isString, pickBy } from "lodash-es";
5
- import { readPackageUp } from "read-package-up";
6
- import { cosmiconfig } from "cosmiconfig";
7
- import importFrom from "import-from-esm";
8
- import debugConfig from "debug";
9
- import { repoUrl } from "./git.js";
10
- import PLUGINS_DEFINITIONS from "./definitions/plugins.js";
11
- import plugins from "./plugins/index.js";
12
- import { parseConfig, validatePlugin } from "./plugins/utils.js";
13
-
14
- const debug = debugConfig("semantic-release:config");
15
- const __dirname = dirname(fileURLToPath(import.meta.url));
16
-
17
- const CONFIG_NAME = "release";
18
-
19
- export default async (context, cliOptions) => {
20
- const { cwd, env } = context;
21
- const { config, filepath } = (await cosmiconfig(CONFIG_NAME).search(cwd)) || {};
22
-
23
- debug("load config from: %s", filepath);
24
-
25
- // Merge config file options and CLI/API options
26
- let options = { ...config, ...cliOptions };
27
-
28
- const pluginsPath = {};
29
- let extendPaths;
30
- ({ extends: extendPaths, ...options } = options);
31
- if (extendPaths) {
32
- // If `extends` is defined, load and merge each shareable config with `options`
33
- options = {
34
- ...(await castArray(extendPaths).reduce(async (eventualResult, extendPath) => {
35
- const result = await eventualResult;
36
- const extendsOptions = (await importFrom.silent(__dirname, extendPath)) || (await importFrom(cwd, extendPath));
37
-
38
- // For each plugin defined in a shareable config, save in `pluginsPath` the extendable config path,
39
- // so those plugin will be loaded relative to the config file
40
- Object.entries(extendsOptions)
41
- .filter(([, value]) => Boolean(value))
42
- .reduce((pluginsPath, [option, value]) => {
43
- castArray(value).forEach((plugin) => {
44
- if (option === "plugins" && validatePlugin(plugin)) {
45
- pluginsPath[parseConfig(plugin)[0]] = extendPath;
46
- } else if (
47
- PLUGINS_DEFINITIONS[option] &&
48
- (isString(plugin) || (isPlainObject(plugin) && isString(plugin.path)))
49
- ) {
50
- pluginsPath[isString(plugin) ? plugin : plugin.path] = extendPath;
51
- }
52
- });
53
- return pluginsPath;
54
- }, pluginsPath);
55
-
56
- return { ...result, ...extendsOptions };
57
- }, {})),
58
- ...options,
59
- };
60
- }
61
-
62
- // Set default options values if not defined yet
63
- options = {
64
- branches: [
65
- "+([0-9])?(.{+([0-9]),x}).x",
66
- "master",
67
- "main",
68
- "next",
69
- "next-major",
70
- { name: "beta", prerelease: true },
71
- { name: "alpha", prerelease: true },
72
- ],
73
- repositoryUrl: (await pkgRepoUrl({ normalize: false, cwd })) || (await repoUrl({ cwd, env })),
74
- tagFormat: `v\${version}`,
75
- plugins: [
76
- "@semantic-release/commit-analyzer",
77
- "@semantic-release/release-notes-generator",
78
- "@semantic-release/npm",
79
- "@semantic-release/github",
80
- ],
81
- // Remove `null` and `undefined` options, so they can be replaced with default ones
82
- ...pickBy(options, (option) => !isNil(option)),
83
- ...(options.branches ? { branches: castArray(options.branches) } : {}),
84
- };
85
-
86
- if (options.ci === false) {
87
- options.noCi = true;
88
- }
89
-
90
- debug("options values: %O", options);
91
-
92
- return { options, plugins: await plugins({ ...context, options }, pluginsPath) };
93
- };
94
-
95
- async function pkgRepoUrl(options) {
96
- const { packageJson } = (await readPackageUp(options)) || {};
97
- return packageJson && (isPlainObject(packageJson.repository) ? packageJson.repository.url : packageJson.repository);
98
- }
package/lib/get-error.js DELETED
@@ -1,7 +0,0 @@
1
- import SemanticReleaseError from "@semantic-release/error";
2
- import * as ERROR_DEFINITIONS from "./definitions/errors.js";
3
-
4
- export default (code, ctx = {}) => {
5
- const { message, details } = ERROR_DEFINITIONS[code](ctx);
6
- return new SemanticReleaseError(message, code, details);
7
- };