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
|
@@ -0,0 +1,298 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { format, parse } from "node:url";
|
|
2
|
+
import { isNil } from "lodash-es";
|
|
3
|
+
import hostedGitInfo from "hosted-git-info";
|
|
4
|
+
import debugAuthUrl from "debug";
|
|
5
|
+
import { verifyAuth } from "./git.js";
|
|
6
|
+
|
|
7
|
+
const debug = debugAuthUrl("semantic-release:get-git-auth-url");
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Machinery to format a repository URL with the given credentials
|
|
11
|
+
*
|
|
12
|
+
* @param {String} protocol URL protocol (which should not be present in repositoryUrl)
|
|
13
|
+
* @param {String} repositoryUrl User-given repository URL
|
|
14
|
+
* @param {String} gitCredentials The basic auth part of the URL
|
|
15
|
+
*
|
|
16
|
+
* @return {String} The formatted Git repository URL.
|
|
17
|
+
*/
|
|
18
|
+
function formatAuthUrl(protocol, repositoryUrl, gitCredentials) {
|
|
19
|
+
const [match, auth, host, basePort, path] =
|
|
20
|
+
/^(?!.+:\/\/)(?:(?<auth>.*)@)?(?<host>.*?):(?<port>\d+)?:?\/?(?<path>.*)$/.exec(repositoryUrl) || [];
|
|
21
|
+
const { port, hostname, ...parsed } = parse(
|
|
22
|
+
match ? `ssh://${auth ? `${auth}@` : ""}${host}${basePort ? `:${basePort}` : ""}/${path}` : repositoryUrl
|
|
23
|
+
);
|
|
24
|
+
|
|
25
|
+
return format({
|
|
26
|
+
...parsed,
|
|
27
|
+
auth: gitCredentials,
|
|
28
|
+
host: `${hostname}${protocol === "ssh:" ? "" : port ? `:${port}` : ""}`,
|
|
29
|
+
protocol: protocol && /http[^s]/.test(protocol) ? "http" : "https",
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Verify authUrl by calling git.verifyAuth, but don't throw on failure
|
|
35
|
+
*
|
|
36
|
+
* @param {Object} context semantic-release context.
|
|
37
|
+
* @param {String} authUrl Repository URL to verify
|
|
38
|
+
*
|
|
39
|
+
* @return {String} The authUrl as is if the connection was successful, null otherwise
|
|
40
|
+
*/
|
|
41
|
+
async function ensureValidAuthUrl({ cwd, env, branch }, authUrl) {
|
|
42
|
+
try {
|
|
43
|
+
await verifyAuth(authUrl, branch.name, { cwd, env });
|
|
44
|
+
return authUrl;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
debug(error);
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Determine the git repository URL to use to push, either:
|
|
53
|
+
* - The `repositoryUrl` as is if allowed to push
|
|
54
|
+
* - The `repositoryUrl` converted to `https` or `http` with Basic Authentication
|
|
55
|
+
*
|
|
56
|
+
* In addition, expand shortcut URLs (`owner/repo` => `https://github.com/owner/repo.git`) and transform `git+https` / `git+http` URLs to `https` / `http`.
|
|
57
|
+
*
|
|
58
|
+
* @param {Object} context semantic-release context.
|
|
59
|
+
*
|
|
60
|
+
* @return {String} The formatted Git repository URL.
|
|
61
|
+
*/
|
|
62
|
+
export default async (context) => {
|
|
63
|
+
const { cwd, env, branch } = context;
|
|
64
|
+
const GIT_TOKENS = {
|
|
65
|
+
GIT_CREDENTIALS: undefined,
|
|
66
|
+
GH_TOKEN: undefined,
|
|
67
|
+
// GitHub Actions require the "x-access-token:" prefix for git access
|
|
68
|
+
// https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#http-based-git-access-by-an-installation
|
|
69
|
+
GITHUB_TOKEN: isNil(env.GITHUB_ACTION) ? undefined : "x-access-token:",
|
|
70
|
+
GL_TOKEN: "gitlab-ci-token:",
|
|
71
|
+
GITLAB_TOKEN: "gitlab-ci-token:",
|
|
72
|
+
BB_TOKEN: "x-token-auth:",
|
|
73
|
+
BITBUCKET_TOKEN: "x-token-auth:",
|
|
74
|
+
BB_TOKEN_BASIC_AUTH: "",
|
|
75
|
+
BITBUCKET_TOKEN_BASIC_AUTH: "",
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
let { repositoryUrl } = context.options;
|
|
79
|
+
const info = hostedGitInfo.fromUrl(repositoryUrl, { noGitPlus: true });
|
|
80
|
+
const { protocol, ...parsed } = parse(repositoryUrl);
|
|
81
|
+
|
|
82
|
+
if (info && info.getDefaultRepresentation() === "shortcut") {
|
|
83
|
+
// Expand shorthand URLs (such as `owner/repo` or `gitlab:owner/repo`)
|
|
84
|
+
repositoryUrl = info.https();
|
|
85
|
+
} else if (protocol && protocol.includes("http")) {
|
|
86
|
+
// Replace `git+https` and `git+http` with `https` or `http`
|
|
87
|
+
repositoryUrl = format({ ...parsed, protocol: protocol.includes("https") ? "https" : "http", href: null });
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// Test if push is allowed without transforming the URL (e.g. is ssh keys are set up)
|
|
91
|
+
try {
|
|
92
|
+
debug("Verifying ssh auth by attempting to push to %s", repositoryUrl);
|
|
93
|
+
await verifyAuth(repositoryUrl, branch.name, { cwd, env });
|
|
94
|
+
} catch {
|
|
95
|
+
debug("SSH key auth failed, falling back to https.");
|
|
96
|
+
const envVars = Object.keys(GIT_TOKENS).filter((envVar) => !isNil(env[envVar]));
|
|
97
|
+
|
|
98
|
+
// Skip verification if there is no ambiguity on which env var to use for authentication
|
|
99
|
+
if (envVars.length === 1) {
|
|
100
|
+
const gitCredentials = `${GIT_TOKENS[envVars[0]] || ""}${env[envVars[0]]}`;
|
|
101
|
+
return formatAuthUrl(protocol, repositoryUrl, gitCredentials);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
if (envVars.length > 1) {
|
|
105
|
+
debug(`Found ${envVars.length} credentials in environment, trying all of them`);
|
|
106
|
+
|
|
107
|
+
const candidateRepositoryUrls = [];
|
|
108
|
+
for (const envVar of envVars) {
|
|
109
|
+
const gitCredentials = `${GIT_TOKENS[envVar] || ""}${env[envVar]}`;
|
|
110
|
+
const authUrl = formatAuthUrl(protocol, repositoryUrl, gitCredentials);
|
|
111
|
+
candidateRepositoryUrls.push(ensureValidAuthUrl(context, authUrl));
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const validRepositoryUrls = await Promise.all(candidateRepositoryUrls);
|
|
115
|
+
const chosenAuthUrlIndex = validRepositoryUrls.findIndex((url) => url !== null);
|
|
116
|
+
if (chosenAuthUrlIndex > -1) {
|
|
117
|
+
debug(`Using "${envVars[chosenAuthUrlIndex]}" to authenticate`);
|
|
118
|
+
return validRepositoryUrls[chosenAuthUrlIndex];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Log completion of this process
|
|
124
|
+
debug("SSH key auth successful.");
|
|
125
|
+
return repositoryUrl;
|
|
126
|
+
};
|