semantic-release 26.0.0-beta.6 → 26.0.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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
- };
@@ -1,143 +0,0 @@
1
- import { format } 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
- * Get the protocol of a repository URL, if it has one (`null` for scp-like and shorthand URLs)
11
- *
12
- * @param {String} repositoryUrl User-given repository URL
13
- *
14
- * @return {String|null} The protocol, including the trailing `:`
15
- */
16
- function getProtocol(repositoryUrl) {
17
- return URL.canParse(repositoryUrl) ? new URL(repositoryUrl).protocol : null;
18
- }
19
-
20
- /**
21
- * Machinery to format a repository URL with the given credentials
22
- *
23
- * @param {String} protocol URL protocol (which should not be present in repositoryUrl)
24
- * @param {String} repositoryUrl User-given repository URL
25
- * @param {String} gitCredentials The basic auth part of the URL
26
- *
27
- * @return {String} The formatted Git repository URL.
28
- */
29
- function formatAuthUrl(protocol, repositoryUrl, gitCredentials) {
30
- if (protocol === "file:") {
31
- return repositoryUrl;
32
- }
33
-
34
- const [match, auth, host, basePort, path] =
35
- /^(?!.+:\/\/)(?:(?<auth>.*)@)?(?<host>.*?):(?<port>\d+)?:?\/?(?<path>.*)$/.exec(repositoryUrl) || [];
36
- const { port, hostname, pathname, search, hash } = new URL(
37
- match ? `ssh://${auth ? `${auth}@` : ""}${host}${basePort ? `:${basePort}` : ""}/${path}` : repositoryUrl
38
- );
39
-
40
- return format({
41
- pathname,
42
- search,
43
- hash,
44
- auth: gitCredentials,
45
- host: `${hostname}${protocol === "ssh:" ? "" : port ? `:${port}` : ""}`,
46
- protocol: protocol && /http[^s]/.test(protocol) ? "http" : "https",
47
- });
48
- }
49
-
50
- /**
51
- * Verify authUrl by calling git.verifyAuth, but don't throw on failure
52
- *
53
- * @param {Object} context semantic-release context.
54
- * @param {String} authUrl Repository URL to verify
55
- *
56
- * @return {String} The authUrl as is if the connection was successful, null otherwise
57
- */
58
- async function ensureValidAuthUrl({ cwd, env, branch }, authUrl) {
59
- try {
60
- await verifyAuth(authUrl, { cwd, env });
61
- return authUrl;
62
- } catch (error) {
63
- debug(error);
64
- return null;
65
- }
66
- }
67
-
68
- /**
69
- * Determine the git repository URL to use to push, either:
70
- * - The `repositoryUrl` as is if allowed to push
71
- * - The `repositoryUrl` converted to `https` or `http` with Basic Authentication
72
- *
73
- * In addition, expand shortcut URLs (`owner/repo` => `https://github.com/owner/repo.git`) and transform `git+https` / `git+http` URLs to `https` / `http`.
74
- *
75
- * @param {Object} context semantic-release context.
76
- *
77
- * @return {String} The formatted Git repository URL.
78
- */
79
- export default async (context) => {
80
- const { cwd, env, branch } = context;
81
- const GIT_TOKENS = {
82
- GIT_CREDENTIALS: undefined,
83
- GH_TOKEN: undefined,
84
- // GitHub Actions require the "x-access-token:" prefix for git access
85
- // https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#http-based-git-access-by-an-installation
86
- GITHUB_TOKEN: isNil(env.GITHUB_ACTION) ? undefined : "x-access-token:",
87
- GL_TOKEN: "gitlab-ci-token:",
88
- GITLAB_TOKEN: "gitlab-ci-token:",
89
- BB_TOKEN: "x-token-auth:",
90
- BITBUCKET_TOKEN: "x-token-auth:",
91
- BB_TOKEN_BASIC_AUTH: "",
92
- BITBUCKET_TOKEN_BASIC_AUTH: "",
93
- };
94
-
95
- let { repositoryUrl } = context.options;
96
- const info = hostedGitInfo.fromUrl(repositoryUrl, { noGitPlus: true });
97
- const protocol = getProtocol(repositoryUrl);
98
-
99
- if (info && info.getDefaultRepresentation() === "shortcut") {
100
- // Expand shorthand URLs (such as `owner/repo` or `gitlab:owner/repo`)
101
- repositoryUrl = info.https();
102
- } else if (protocol && protocol.includes("http")) {
103
- // Replace `git+https` and `git+http` with `https` or `http`
104
- repositoryUrl = repositoryUrl.replace(/^[^:]+:/, protocol.includes("https") ? "https:" : "http:");
105
- }
106
-
107
- // Test if push is allowed without transforming the URL (e.g. is ssh keys are set up)
108
- try {
109
- debug("Verifying ssh auth by attempting to push to %s", repositoryUrl);
110
- await verifyAuth(repositoryUrl, { cwd, env });
111
- } catch {
112
- debug("SSH key auth failed, falling back to https.");
113
- const envVars = Object.keys(GIT_TOKENS).filter((envVar) => !isNil(env[envVar]));
114
-
115
- // Skip verification if there is no ambiguity on which env var to use for authentication
116
- if (envVars.length === 1) {
117
- const gitCredentials = `${GIT_TOKENS[envVars[0]] || ""}${env[envVars[0]]}`;
118
- return formatAuthUrl(protocol, repositoryUrl, gitCredentials);
119
- }
120
-
121
- if (envVars.length > 1) {
122
- debug(`Found ${envVars.length} credentials in environment, trying all of them`);
123
-
124
- const candidateRepositoryUrls = [];
125
- for (const envVar of envVars) {
126
- const gitCredentials = `${GIT_TOKENS[envVar] || ""}${env[envVar]}`;
127
- const authUrl = formatAuthUrl(protocol, repositoryUrl, gitCredentials);
128
- candidateRepositoryUrls.push(ensureValidAuthUrl(context, authUrl));
129
- }
130
-
131
- const validRepositoryUrls = await Promise.all(candidateRepositoryUrls);
132
- const chosenAuthUrlIndex = validRepositoryUrls.findIndex((url) => url !== null);
133
- if (chosenAuthUrlIndex > -1) {
134
- debug(`Using "${envVars[chosenAuthUrlIndex]}" to authenticate`);
135
- return validRepositoryUrls[chosenAuthUrlIndex];
136
- }
137
- }
138
- }
139
-
140
- // Log completion of this process
141
- debug("SSH key auth successful.");
142
- return repositoryUrl;
143
- };
@@ -1,48 +0,0 @@
1
- import { isUndefined } from "lodash-es";
2
- import semver from "semver";
3
- import { isSameChannel, makeTag } from "./utils.js";
4
-
5
- /**
6
- * Last release.
7
- *
8
- * @typedef {Object} LastRelease
9
- * @property {string} version The version number of the last release.
10
- * @property {string} gitHead The Git reference used to make the last release.
11
- * @property {string} gitTag The git tag associated with the last release.
12
- * @property {string} channel The channel on which of the last release was published.
13
- * @property {string} name The name of the last release.
14
- */
15
-
16
- /**
17
- * Determine the Git tag and version of the last tagged release.
18
- *
19
- * - Filter out the branch tags that are not valid semantic version
20
- * - Sort the versions
21
- * - Retrieve the highest version
22
- *
23
- * @param {Object} context semantic-release context.
24
- * @param {Object} params Function parameters.
25
- * @param {Object} params.before Find only releases with version number lower than this version.
26
- *
27
- * @return {LastRelease} The last tagged release or empty object if none is found.
28
- */
29
- export default ({ branch, options: { tagFormat } }, { before } = {}) => {
30
- const [{ version, gitTag, channels } = {}] = branch.tags
31
- .filter(
32
- (tag) =>
33
- ((branch.type === "prerelease" &&
34
- tag.channels.some((channel) => isSameChannel(branch.channel, channel)) &&
35
- semver
36
- .parse(tag.version)
37
- .prerelease.includes(branch.prerelease === true ? branch.name : branch.prerelease)) ||
38
- !semver.prerelease(tag.version)) &&
39
- (isUndefined(before) || semver.lt(tag.version, before))
40
- )
41
- .sort((a, b) => semver.rcompare(a.version, b.version));
42
-
43
- if (gitTag) {
44
- return { version, gitTag, channels, gitHead: gitTag, name: makeTag(tagFormat, version) };
45
- }
46
-
47
- return {};
48
- };
package/lib/get-logger.js DELETED
@@ -1,19 +0,0 @@
1
- import signale from "signale";
2
- import figures from "figures";
3
-
4
- const { Signale } = signale;
5
-
6
- export default ({ stdout, stderr }) =>
7
- new Signale({
8
- config: { displayTimestamp: true, underlineMessage: false, displayLabel: false },
9
- disabled: false,
10
- interactive: false,
11
- scope: "semantic-release",
12
- stream: [stdout],
13
- types: {
14
- error: { badge: figures.cross, color: "red", label: "", stream: [stderr] },
15
- log: { badge: figures.info, color: "magenta", label: "", stream: [stdout] },
16
- success: { badge: figures.tick, color: "green", label: "", stream: [stdout] },
17
- warn: { badge: figures.warning, color: "yellow", label: "", stream: [stderr] },
18
- },
19
- });
@@ -1,35 +0,0 @@
1
- import semver from "semver";
2
- import { FIRST_RELEASE, FIRSTPRERELEASE } from "./definitions/constants.js";
3
- import { getLatestVersion, highest, isSameChannel, tagsToVersions } from "./utils.js";
4
-
5
- export default ({ branch, nextRelease: { type, channel }, lastRelease, logger }) => {
6
- let version;
7
- if (lastRelease.version) {
8
- const { major, minor, patch } = semver.parse(lastRelease.version);
9
-
10
- if (branch.type === "prerelease") {
11
- if (
12
- semver.prerelease(lastRelease.version) &&
13
- lastRelease.channels.some((lastReleaseChannel) => isSameChannel(lastReleaseChannel, channel))
14
- ) {
15
- version = highest(
16
- semver.inc(lastRelease.version, "prerelease"),
17
- `${semver.inc(getLatestVersion(tagsToVersions(branch.tags), { withPrerelease: true }), type)}-${
18
- branch.prerelease
19
- }.${FIRSTPRERELEASE}`
20
- );
21
- } else {
22
- version = `${semver.inc(`${major}.${minor}.${patch}`, type)}-${branch.prerelease}.${FIRSTPRERELEASE}`;
23
- }
24
- } else {
25
- version = semver.inc(lastRelease.version, type);
26
- }
27
-
28
- logger.log("The next release version is %s", version);
29
- } else {
30
- version = branch.type === "prerelease" ? `${FIRST_RELEASE}-${branch.prerelease}.${FIRSTPRERELEASE}` : FIRST_RELEASE;
31
- logger.log(`There is no previous release, the next release version is ${version}`);
32
- }
33
-
34
- return version;
35
- };
@@ -1,59 +0,0 @@
1
- import { intersection, uniqBy } from "lodash-es";
2
- import semver from "semver";
3
- import getLastRelease from "./get-last-release.js";
4
- import { getLowerBound, getVersionDiff, makeTag } from "./utils.js";
5
-
6
- /**
7
- * Find releases that have been merged from a higher branch but not added on the channel of the current branch.
8
- *
9
- * @param {Object} context semantic-release context.
10
- *
11
- * @return {Array<Object>} Last release and next release to be added on the channel of the current branch.
12
- */
13
- export default (context) => {
14
- const {
15
- branch,
16
- branches,
17
- options: { tagFormat },
18
- } = context;
19
-
20
- const higherChannels = branches
21
- // Consider only releases of higher branches
22
- .slice(branches.findIndex(({ name }) => name === branch.name) + 1)
23
- // Exclude prerelease branches
24
- .filter(({ type }) => type !== "prerelease")
25
- .map(({ channel }) => channel || null);
26
-
27
- const versiontoAdd = uniqBy(
28
- branch.tags.filter(
29
- ({ channels, version }) =>
30
- !channels.includes(branch.channel || null) &&
31
- intersection(channels, higherChannels).length > 0 &&
32
- (branch.type !== "maintenance" || semver.gte(version, getLowerBound(branch.mergeRange)))
33
- ),
34
- "version"
35
- ).sort((a, b) => semver.compare(b.version, a.version))[0];
36
-
37
- if (versiontoAdd) {
38
- const { version, gitTag, channels } = versiontoAdd;
39
- const lastRelease = getLastRelease(context, { before: version });
40
- if (semver.gt(getLastRelease(context).version, version)) {
41
- return;
42
- }
43
-
44
- const type = lastRelease.version ? getVersionDiff(lastRelease.version, version) : "major";
45
- const name = makeTag(tagFormat, version);
46
- return {
47
- lastRelease,
48
- currentRelease: { type, version, channels, gitTag, name, gitHead: gitTag },
49
- nextRelease: {
50
- type,
51
- version,
52
- channel: branch.channel || null,
53
- gitTag: makeTag(tagFormat, version),
54
- name,
55
- gitHead: gitTag,
56
- },
57
- };
58
- }
59
- };