semantic-release 25.0.4 → 25.0.6
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 +36 -37
- package/bin/semantic-release.js +1 -1
- 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 +303 -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/hide-sensitive.js +14 -1
- 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 +20 -15
- package/docs/README.md +0 -7
- package/docs/developer-guide/README.md +0 -5
- package/docs/developer-guide/js-api.md +0 -294
- package/docs/developer-guide/plugin.md +0 -284
- package/docs/developer-guide/shareable-configuration.md +0 -1
- package/docs/extending/README.md +0 -4
- package/docs/extending/plugins-list.md +0 -233
- package/docs/extending/shareable-configurations-list.md +0 -22
- package/docs/recipes/ci-configurations/README.md +0 -7
- package/docs/recipes/ci-configurations/circleci-workflows.md +0 -49
- package/docs/recipes/ci-configurations/github-actions.md +0 -136
- package/docs/recipes/ci-configurations/gitlab-ci.md +0 -98
- package/docs/recipes/ci-configurations/jenkins-ci.md +0 -61
- package/docs/recipes/ci-configurations/travis.md +0 -97
- package/docs/recipes/git-hosted-services/README.md +0 -3
- package/docs/recipes/git-hosted-services/git-auth-ssh-keys.md +0 -166
- package/docs/recipes/release-workflow/README.md +0 -5
- package/docs/recipes/release-workflow/distribution-channels.md +0 -117
- package/docs/recipes/release-workflow/maintenance-releases.md +0 -157
- package/docs/recipes/release-workflow/pre-releases.md +0 -197
- package/docs/support/FAQ.md +0 -253
- package/docs/support/README.md +0 -7
- package/docs/support/git-version.md +0 -4
- package/docs/support/node-support-policy.md +0 -21
- package/docs/support/node-version.md +0 -38
- package/docs/support/resources.md +0 -22
- package/docs/support/troubleshooting.md +0 -70
- package/docs/usage/README.md +0 -9
- package/docs/usage/ci-configuration.md +0 -50
- package/docs/usage/configuration.md +0 -206
- package/docs/usage/getting-started.md +0 -8
- package/docs/usage/installation.md +0 -51
- package/docs/usage/plugins.md +0 -105
- package/docs/usage/shareable-configurations.md +0 -7
- package/docs/usage/workflow-configuration.md +0 -199
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
|
|
@@ -47,10 +40,10 @@ If you want to build a custom CLI or compose your own plugin stack directly, use
|
|
|
47
40
|
- Notify maintainers and users of new releases
|
|
48
41
|
- Use formalized commit message convention to document changes in the codebase
|
|
49
42
|
- Publish on different distribution channels (such as [npm dist-tags](https://docs.npmjs.com/cli/dist-tag)) based on git merges
|
|
50
|
-
- Integrate with your [continuous integration workflow](
|
|
43
|
+
- Integrate with your [continuous integration workflow](https://semantic-release.org/recipes/ci-configurations/#ci-configurations)
|
|
51
44
|
- Avoid potential errors associated with manual releases
|
|
52
|
-
- Support any [package managers and languages](
|
|
53
|
-
- Simple and reusable configuration via [shareable configurations](
|
|
45
|
+
- Support any [package managers and languages](https://semantic-release.org/recipes/release-workflow/#package-managers-and-languages) via [plugins](https://semantic-release.org/foundation/plugins/)
|
|
46
|
+
- Simple and reusable configuration via [shareable configurations](https://semantic-release.org/foundation/shareable-configurations/)
|
|
54
47
|
- Support for [npm package provenance](https://github.com/semantic-release/npm#npm-provenance) that promotes increased supply-chain security via signed attestations on GitHub Actions
|
|
55
48
|
|
|
56
49
|
## How does it work?
|
|
@@ -61,7 +54,7 @@ If you want to build a custom CLI or compose your own plugin stack directly, use
|
|
|
61
54
|
Following formalized conventions for commit messages, **semantic-release** automatically determines the next [semantic version](https://semver.org) number, generates a changelog and publishes the release.
|
|
62
55
|
|
|
63
56
|
By default, **semantic-release** uses [Angular Commit Message Conventions](https://github.com/angular/angular/blob/main/contributing-docs/commit-message-guidelines.md).
|
|
64
|
-
The commit message format can be changed with the [`preset` or `config` options](
|
|
57
|
+
The commit message format can be changed with the [`preset` or `config` options](https://semantic-release.org/usage/configuration/#options) of the [@semantic-release/commit-analyzer](https://github.com/semantic-release/commit-analyzer#options) and [@semantic-release/release-notes-generator](https://github.com/semantic-release/release-notes-generator#options) plugins.
|
|
65
58
|
|
|
66
59
|
Tools such as [commitizen](https://github.com/commitizen/cz-cli) or [commitlint](https://github.com/conventional-changelog/commitlint) can be used to help contributors and enforce valid commit messages.
|
|
67
60
|
|
|
@@ -85,9 +78,9 @@ For each new commit added to one of the release branches (for example: `master`,
|
|
|
85
78
|
**semantic-release** offers various ways to control the timing, the content and the audience of published releases.
|
|
86
79
|
See example workflows in the following recipes:
|
|
87
80
|
|
|
88
|
-
- [Using distribution channels](
|
|
89
|
-
- [Maintenance releases](
|
|
90
|
-
- [Pre-releases](
|
|
81
|
+
- [Using distribution channels](https://semantic-release.org/recipes/release-workflow/distribution-channels/#publishing-on-distribution-channels)
|
|
82
|
+
- [Maintenance releases](https://semantic-release.org/recipes/release-workflow/maintenance-releases/#publishing-maintenance-releases)
|
|
83
|
+
- [Pre-releases](https://semantic-release.org/recipes/release-workflow/pre-releases/#publishing-pre-releases)
|
|
91
84
|
|
|
92
85
|
### Release steps
|
|
93
86
|
|
|
@@ -110,37 +103,43 @@ After running the tests, the command `semantic-release` will execute the followi
|
|
|
110
103
|
In order to use **semantic-release** you need:
|
|
111
104
|
|
|
112
105
|
- To host your code in a [Git repository](https://git-scm.com)
|
|
113
|
-
- Use a Continuous Integration service that allows you to [securely set up credentials](
|
|
114
|
-
- A Git CLI version that meets [our version requirement](
|
|
115
|
-
- A [Node.js](https://nodejs.org) version that meets [our version requirement](
|
|
106
|
+
- Use a Continuous Integration service that allows you to [securely set up credentials](https://semantic-release.org/usage/ci-configuration/#authentication)
|
|
107
|
+
- A Git CLI version that meets [our version requirement](https://semantic-release.org/support/git-version/) installed in your Continuous Integration environment
|
|
108
|
+
- A [Node.js](https://nodejs.org) version that meets [our version requirement](https://semantic-release.org/support/node-version/) installed in your Continuous Integration environment
|
|
116
109
|
|
|
117
110
|
## Documentation
|
|
118
111
|
|
|
119
112
|
- Usage
|
|
120
|
-
- [Getting started](
|
|
121
|
-
- [
|
|
122
|
-
- [CI Configuration](
|
|
123
|
-
- [
|
|
124
|
-
|
|
125
|
-
- [
|
|
126
|
-
- [
|
|
113
|
+
- [Getting started](https://semantic-release.org/usage/getting-started/)
|
|
114
|
+
- [Configuration](https://semantic-release.org/usage/configuration/)
|
|
115
|
+
- [CI Configuration](https://semantic-release.org/usage/ci-configuration/)
|
|
116
|
+
- [Running semantic-release](https://semantic-release.org/usage/running/)
|
|
117
|
+
- Foundations
|
|
118
|
+
- [How it works](https://semantic-release.org/foundation/how-it-works/)
|
|
119
|
+
- [Release Steps](https://semantic-release.org/foundation/release-steps/)
|
|
120
|
+
- [Considerations](https://semantic-release.org/foundation/considerations/)
|
|
121
|
+
- [Supported Branching Models](https://semantic-release.org/foundation/supported-branching/)
|
|
122
|
+
- [Release Workflow configuration](https://semantic-release.org/foundation/workflow-configuration/)
|
|
123
|
+
- [Plugins](https://semantic-release.org/foundation/plugins/)
|
|
124
|
+
- [Shareable configurations](https://semantic-release.org/foundation/shareable-configurations/)
|
|
127
125
|
- Extending
|
|
128
|
-
- [Plugins](
|
|
129
|
-
- [Shareable configuration](
|
|
126
|
+
- [Plugins](https://semantic-release.org/extending/plugins-list/)
|
|
127
|
+
- [Shareable configuration](https://semantic-release.org/extending/shareable-configurations-list/)
|
|
130
128
|
- Recipes
|
|
131
|
-
- [CI configurations](
|
|
132
|
-
- [Git hosted services](
|
|
133
|
-
- [Release workflow](
|
|
129
|
+
- [CI configurations](https://semantic-release.org/recipes/ci-configurations/)
|
|
130
|
+
- [Git hosted services](https://semantic-release.org/recipes/git-hosted-services/)
|
|
131
|
+
- [Release workflow](https://semantic-release.org/recipes/release-workflow/)
|
|
134
132
|
- Developer guide
|
|
135
|
-
- [JavaScript API](
|
|
136
|
-
- [Plugins development](
|
|
137
|
-
- [Shareable configuration development](
|
|
133
|
+
- [JavaScript API](https://semantic-release.org/developer-guide/js-api/)
|
|
134
|
+
- [Plugins development](https://semantic-release.org/developer-guide/plugin/)
|
|
135
|
+
- [Shareable configuration development](https://semantic-release.org/developer-guide/shareable-configuration/)
|
|
138
136
|
- Support
|
|
139
|
-
- [Resources](
|
|
140
|
-
- [Frequently Asked Questions](
|
|
141
|
-
- [Troubleshooting](
|
|
142
|
-
- [Node version requirement](
|
|
143
|
-
- [Node Support Policy](
|
|
137
|
+
- [Resources](https://semantic-release.org/support/resources/)
|
|
138
|
+
- [Frequently Asked Questions](https://semantic-release.org/support/faq/)
|
|
139
|
+
- [Troubleshooting](https://semantic-release.org/support/troubleshooting/)
|
|
140
|
+
- [Node version requirement](https://semantic-release.org/support/node-version/)
|
|
141
|
+
- [Node Support Policy](https://semantic-release.org/support/node-support-policy/)
|
|
142
|
+
- [Git Version requirement](https://semantic-release.org/support/git-version/)
|
|
144
143
|
|
|
145
144
|
## Get help
|
|
146
145
|
|
package/bin/semantic-release.js
CHANGED
|
@@ -18,7 +18,7 @@ if (!satisfies(process.version, engines.node)) {
|
|
|
18
18
|
console.error(
|
|
19
19
|
`[semantic-release]: node version ${engines.node} is required. Found ${process.version}.
|
|
20
20
|
|
|
21
|
-
See https://
|
|
21
|
+
See https://semantic-release.org/support/node-version/ for more details and solutions.`
|
|
22
22
|
);
|
|
23
23
|
process.exit(1);
|
|
24
24
|
}
|
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
|
+
};
|