semantic-release 25.0.3 → 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.
- package/README.md +7 -0
- package/docs/extending/plugins-list.md +6 -0
- package/docs/recipes/ci-configurations/github-actions.md +0 -7
- package/index.js +37 -265
- package/lib/definitions/constants.js +9 -8
- package/package.json +17 -17
- package/lib/branches/expand.js +0 -18
- package/lib/branches/get-tags.js +0 -39
- package/lib/branches/index.js +0 -71
- package/lib/branches/normalize.js +0 -104
- package/lib/definitions/branches.js +0 -22
- package/lib/definitions/errors.js +0 -298
- package/lib/definitions/plugins.js +0 -108
- package/lib/get-commits.js +0 -31
- package/lib/get-config.js +0 -98
- package/lib/get-error.js +0 -7
- package/lib/get-git-auth-url.js +0 -126
- package/lib/get-last-release.js +0 -48
- package/lib/get-logger.js +0 -19
- package/lib/get-next-version.js +0 -35
- package/lib/get-release-to-add.js +0 -59
- package/lib/git.js +0 -381
- package/lib/plugins/index.js +0 -103
- package/lib/plugins/normalize.js +0 -69
- package/lib/plugins/pipeline.js +0 -59
- package/lib/plugins/utils.js +0 -81
- package/lib/utils.js +0 -101
- package/lib/verify.js +0 -43
package/lib/plugins/index.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { castArray, identity, isNil, isPlainObject, isString, omit } from "lodash-es";
|
|
2
|
-
import AggregateError from "aggregate-error";
|
|
3
|
-
import getError from "../get-error.js";
|
|
4
|
-
import PLUGINS_DEFINITIONS from "../definitions/plugins.js";
|
|
5
|
-
import { loadPlugin, parseConfig, validatePlugin, validateStep } from "./utils.js";
|
|
6
|
-
import pipeline from "./pipeline.js";
|
|
7
|
-
import normalize from "./normalize.js";
|
|
8
|
-
|
|
9
|
-
export default async (context, pluginsPath) => {
|
|
10
|
-
let { options, logger } = context;
|
|
11
|
-
const errors = [];
|
|
12
|
-
|
|
13
|
-
const plugins = options.plugins
|
|
14
|
-
? await castArray(options.plugins).reduce(async (eventualPluginsList, plugin) => {
|
|
15
|
-
const pluginsList = await eventualPluginsList;
|
|
16
|
-
if (validatePlugin(plugin)) {
|
|
17
|
-
const [name, config] = parseConfig(plugin);
|
|
18
|
-
plugin = isString(name) ? await loadPlugin(context, name, pluginsPath) : name;
|
|
19
|
-
|
|
20
|
-
if (isPlainObject(plugin)) {
|
|
21
|
-
Object.entries(plugin).forEach(([type, func]) => {
|
|
22
|
-
if (PLUGINS_DEFINITIONS[type]) {
|
|
23
|
-
Reflect.defineProperty(func, "pluginName", {
|
|
24
|
-
value: isPlainObject(name) ? "Inline plugin" : name,
|
|
25
|
-
writable: false,
|
|
26
|
-
enumerable: true,
|
|
27
|
-
});
|
|
28
|
-
pluginsList[type] = [...(pluginsList[type] || []), [func, config]];
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
} else {
|
|
32
|
-
errors.push(getError("EPLUGINSCONF", { plugin }));
|
|
33
|
-
}
|
|
34
|
-
} else {
|
|
35
|
-
errors.push(getError("EPLUGINSCONF", { plugin }));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return pluginsList;
|
|
39
|
-
}, {})
|
|
40
|
-
: [];
|
|
41
|
-
|
|
42
|
-
if (errors.length > 0) {
|
|
43
|
-
throw new AggregateError(errors);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
options = { ...plugins, ...options };
|
|
47
|
-
|
|
48
|
-
const pluginsConfig = await Object.entries(PLUGINS_DEFINITIONS).reduce(
|
|
49
|
-
async (
|
|
50
|
-
eventualPluginsConfigAccumulator,
|
|
51
|
-
[type, { required, default: def, pipelineConfig, postprocess = identity, preprocess = identity }]
|
|
52
|
-
) => {
|
|
53
|
-
let pluginOptions;
|
|
54
|
-
const pluginsConfigAccumulator = await eventualPluginsConfigAccumulator;
|
|
55
|
-
|
|
56
|
-
if (isNil(options[type]) && def) {
|
|
57
|
-
pluginOptions = def;
|
|
58
|
-
} else {
|
|
59
|
-
// If an object is passed and the path is missing, merge it with step options
|
|
60
|
-
if (isPlainObject(options[type]) && !options[type].path) {
|
|
61
|
-
options[type] = castArray(plugins[type]).map((plugin) =>
|
|
62
|
-
plugin ? [plugin[0], Object.assign(plugin[1], options[type])] : plugin
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (!validateStep({ required }, options[type])) {
|
|
67
|
-
errors.push(getError("EPLUGINCONF", { type, required, pluginConf: options[type] }));
|
|
68
|
-
return pluginsConfigAccumulator;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
pluginOptions = options[type];
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const steps = await Promise.all(
|
|
75
|
-
castArray(pluginOptions).map(async (pluginOpt) =>
|
|
76
|
-
normalize(
|
|
77
|
-
{ ...context, options: omit(options, Object.keys(PLUGINS_DEFINITIONS), "plugins") },
|
|
78
|
-
type,
|
|
79
|
-
pluginOpt,
|
|
80
|
-
pluginsPath
|
|
81
|
-
)
|
|
82
|
-
)
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
pluginsConfigAccumulator[type] = async (input) =>
|
|
86
|
-
postprocess(
|
|
87
|
-
await pipeline(
|
|
88
|
-
steps,
|
|
89
|
-
pipelineConfig && pipelineConfig(pluginsConfigAccumulator, logger)
|
|
90
|
-
)(await preprocess(input)),
|
|
91
|
-
input
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
return pluginsConfigAccumulator;
|
|
95
|
-
},
|
|
96
|
-
plugins
|
|
97
|
-
);
|
|
98
|
-
if (errors.length > 0) {
|
|
99
|
-
throw new AggregateError(errors);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return pluginsConfig;
|
|
103
|
-
};
|
package/lib/plugins/normalize.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { cloneDeep, isFunction, isPlainObject, noop, omit } from "lodash-es";
|
|
2
|
-
import debugPlugins from "debug";
|
|
3
|
-
import getError from "../get-error.js";
|
|
4
|
-
import { extractErrors } from "../utils.js";
|
|
5
|
-
import PLUGINS_DEFINITIONS from "../definitions/plugins.js";
|
|
6
|
-
import { loadPlugin, parseConfig } from "./utils.js";
|
|
7
|
-
|
|
8
|
-
const debug = debugPlugins("semantic-release:plugins");
|
|
9
|
-
|
|
10
|
-
export default async (context, type, pluginOpt, pluginsPath) => {
|
|
11
|
-
const { stdout, stderr, options, logger } = context;
|
|
12
|
-
if (!pluginOpt) {
|
|
13
|
-
return noop;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const [name, config] = parseConfig(pluginOpt);
|
|
17
|
-
const pluginName = name.pluginName ? name.pluginName : isFunction(name) ? `[Function: ${name.name}]` : name;
|
|
18
|
-
const plugin = await loadPlugin(context, name, pluginsPath);
|
|
19
|
-
|
|
20
|
-
debug(`options for ${pluginName}/${type}: %O`, config);
|
|
21
|
-
|
|
22
|
-
let func;
|
|
23
|
-
if (isFunction(plugin)) {
|
|
24
|
-
func = plugin.bind(null, cloneDeep({ ...options, ...config }));
|
|
25
|
-
} else if (isPlainObject(plugin) && plugin[type] && isFunction(plugin[type])) {
|
|
26
|
-
func = plugin[type].bind(null, cloneDeep({ ...options, ...config }));
|
|
27
|
-
} else {
|
|
28
|
-
throw getError("EPLUGIN", { type, pluginName });
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const validator = async (input) => {
|
|
32
|
-
const { dryRun, outputValidator } = PLUGINS_DEFINITIONS[type] || {};
|
|
33
|
-
try {
|
|
34
|
-
if (!input.options.dryRun || dryRun) {
|
|
35
|
-
logger.log(`Start step "${type}" of plugin "${pluginName}"`);
|
|
36
|
-
const result = await func({
|
|
37
|
-
...cloneDeep(omit(input, ["stdout", "stderr", "logger"])),
|
|
38
|
-
stdout,
|
|
39
|
-
stderr,
|
|
40
|
-
logger: logger.scope(logger.scopeName, pluginName),
|
|
41
|
-
});
|
|
42
|
-
if (outputValidator && !outputValidator(result)) {
|
|
43
|
-
throw getError(`E${type.toUpperCase()}OUTPUT`, { result, pluginName });
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
logger.success(`Completed step "${type}" of plugin "${pluginName}"`);
|
|
47
|
-
return result;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
logger.warn(`Skip step "${type}" of plugin "${pluginName}" in dry-run mode`);
|
|
51
|
-
} catch (error) {
|
|
52
|
-
logger.error(`Failed step "${type}" of plugin "${pluginName}"`);
|
|
53
|
-
extractErrors(error).forEach((err) => Object.assign(err, { pluginName }));
|
|
54
|
-
throw error;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
Reflect.defineProperty(validator, "pluginName", { value: pluginName, writable: false, enumerable: true });
|
|
59
|
-
|
|
60
|
-
if (!isFunction(pluginOpt)) {
|
|
61
|
-
if (pluginsPath[name]) {
|
|
62
|
-
logger.success(`Loaded plugin "${type}" from "${pluginName}" in shareable config "${pluginsPath[name]}"`);
|
|
63
|
-
} else {
|
|
64
|
-
logger.success(`Loaded plugin "${type}" from "${pluginName}"`);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
return validator;
|
|
69
|
-
};
|
package/lib/plugins/pipeline.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { identity } from "lodash-es";
|
|
2
|
-
import pReduce from "p-reduce";
|
|
3
|
-
import AggregateError from "aggregate-error";
|
|
4
|
-
import { extractErrors } from "../utils.js";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* A Function that execute a list of function sequencially. If at least one Function ins the pipeline throws an Error or rejects, the pipeline function rejects as well.
|
|
8
|
-
*
|
|
9
|
-
* @typedef {Function} Pipeline
|
|
10
|
-
* @param {Any} input Argument to pass to the first step in the pipeline.
|
|
11
|
-
*
|
|
12
|
-
* @return {Array<*>|*} An Array with the result of each step in the pipeline; if there is only 1 step in the pipeline, the result of this step is returned directly.
|
|
13
|
-
*
|
|
14
|
-
* @throws {AggregateError|Error} An AggregateError with the errors of each step in the pipeline that rejected; if there is only 1 step in the pipeline, the error of this step is thrown directly.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Create a Pipeline with a list of Functions.
|
|
19
|
-
*
|
|
20
|
-
* @param {Array<Function>} steps The list of Function to execute.
|
|
21
|
-
* @param {Object} options Pipeline options.
|
|
22
|
-
* @param {Boolean} [options.settleAll=false] If `true` all the steps in the pipeline are executed, even if one rejects, if `false` the execution stops after a steps rejects.
|
|
23
|
-
* @param {Function} [options.getNextInput=identity] Function called after each step is executed, with the last step input and the current current step result; the returned value will be used as the input of the next step.
|
|
24
|
-
* @param {Function} [options.transform=identity] Function called after each step is executed, with the current step result, the step function and the last step input; the returned value will be saved in the pipeline results.
|
|
25
|
-
*
|
|
26
|
-
* @return {Pipeline} A Function that execute the `steps` sequentially
|
|
27
|
-
*/
|
|
28
|
-
export default (steps, { settleAll = false, getNextInput = identity, transform = identity } = {}) =>
|
|
29
|
-
async (input) => {
|
|
30
|
-
const results = [];
|
|
31
|
-
const errors = [];
|
|
32
|
-
await pReduce(
|
|
33
|
-
steps,
|
|
34
|
-
async (lastInput, step) => {
|
|
35
|
-
let result;
|
|
36
|
-
try {
|
|
37
|
-
// Call the step with the input computed at the end of the previous iteration and save intermediary result
|
|
38
|
-
result = await transform(await step(lastInput), step, lastInput);
|
|
39
|
-
results.push(result);
|
|
40
|
-
} catch (error) {
|
|
41
|
-
if (settleAll) {
|
|
42
|
-
errors.push(...extractErrors(error));
|
|
43
|
-
result = error;
|
|
44
|
-
} else {
|
|
45
|
-
throw error;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// Prepare input for the next step, passing the input of the last iteration (or initial parameter for the first iteration) and the result of the current one
|
|
50
|
-
return getNextInput(lastInput, result);
|
|
51
|
-
},
|
|
52
|
-
input
|
|
53
|
-
);
|
|
54
|
-
if (errors.length > 0) {
|
|
55
|
-
throw new AggregateError(errors);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return results;
|
|
59
|
-
};
|
package/lib/plugins/utils.js
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { dirname } from "node:path";
|
|
2
|
-
import { fileURLToPath } from "node:url";
|
|
3
|
-
import { castArray, isArray, isFunction, isNil, isPlainObject, isString } from "lodash-es";
|
|
4
|
-
import resolveFrom from "resolve-from";
|
|
5
|
-
|
|
6
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
7
|
-
|
|
8
|
-
const validateSteps = (conf) => {
|
|
9
|
-
return conf.every((conf) => {
|
|
10
|
-
if (
|
|
11
|
-
isArray(conf) &&
|
|
12
|
-
(conf.length === 1 || conf.length === 2) &&
|
|
13
|
-
(isString(conf[0]) || isFunction(conf[0])) &&
|
|
14
|
-
(isNil(conf[1]) || isPlainObject(conf[1]))
|
|
15
|
-
) {
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
conf = castArray(conf);
|
|
20
|
-
|
|
21
|
-
if (conf.length !== 1) {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const [name, config] = parseConfig(conf[0]);
|
|
26
|
-
return (isString(name) || isFunction(name)) && isPlainObject(config);
|
|
27
|
-
});
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export function validatePlugin(conf) {
|
|
31
|
-
return (
|
|
32
|
-
isString(conf) ||
|
|
33
|
-
(isArray(conf) &&
|
|
34
|
-
(conf.length === 1 || conf.length === 2) &&
|
|
35
|
-
(isString(conf[0]) || isPlainObject(conf[0])) &&
|
|
36
|
-
(isNil(conf[1]) || isPlainObject(conf[1]))) ||
|
|
37
|
-
(isPlainObject(conf) && (isNil(conf.path) || isString(conf.path) || isPlainObject(conf.path)))
|
|
38
|
-
);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function validateStep({ required }, conf) {
|
|
42
|
-
conf = castArray(conf).filter(Boolean);
|
|
43
|
-
if (required) {
|
|
44
|
-
return conf.length >= 1 && validateSteps(conf);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return conf.length === 0 || validateSteps(conf);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export async function loadPlugin({ cwd }, name, pluginsPath) {
|
|
51
|
-
const basePath = pluginsPath[name]
|
|
52
|
-
? dirname(resolveFrom.silent(__dirname, pluginsPath[name]) || resolveFrom(cwd, pluginsPath[name]))
|
|
53
|
-
: __dirname;
|
|
54
|
-
|
|
55
|
-
if (isFunction(name)) {
|
|
56
|
-
return name;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const file = resolveFrom.silent(basePath, name) || resolveFrom(cwd, name);
|
|
60
|
-
const { default: cjsExport, ...esmNamedExports } = await import(`file://${file}`);
|
|
61
|
-
|
|
62
|
-
if (cjsExport) {
|
|
63
|
-
return cjsExport;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return esmNamedExports;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export function parseConfig(plugin) {
|
|
70
|
-
let path;
|
|
71
|
-
let config;
|
|
72
|
-
if (isArray(plugin)) {
|
|
73
|
-
[path, config] = plugin;
|
|
74
|
-
} else if (isPlainObject(plugin) && !isNil(plugin.path)) {
|
|
75
|
-
({ path, ...config } = plugin);
|
|
76
|
-
} else {
|
|
77
|
-
path = plugin;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return [path, config || {}];
|
|
81
|
-
}
|
package/lib/utils.js
DELETED
|
@@ -1,101 +0,0 @@
|
|
|
1
|
-
import { template, union } from "lodash-es";
|
|
2
|
-
import semver from "semver";
|
|
3
|
-
import hideSensitive from "./hide-sensitive.js";
|
|
4
|
-
|
|
5
|
-
export function extractErrors(err) {
|
|
6
|
-
return err && err.errors ? [...err.errors] : [err];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function hideSensitiveValues(env, objs) {
|
|
10
|
-
const hideFunction = hideSensitive(env);
|
|
11
|
-
return objs.map((object) => {
|
|
12
|
-
Object.getOwnPropertyNames(object).forEach((prop) => {
|
|
13
|
-
if (object[prop]) {
|
|
14
|
-
object[prop] = hideFunction(object[prop]);
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
return object;
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function tagsToVersions(tags) {
|
|
22
|
-
return tags.map(({ version }) => version);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export function isMajorRange(range) {
|
|
26
|
-
return /^\d+\.x(?:\.x)?$/i.test(range);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function isMaintenanceRange(range) {
|
|
30
|
-
return /^\d+(?:\.(?:\d+|x))?\.x$/i.test(range);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export function getUpperBound(range) {
|
|
34
|
-
const result = semver.valid(range)
|
|
35
|
-
? range
|
|
36
|
-
: ((semver.validRange(range) || "").match(/<(?<upperBound>\d+\.\d+\.\d+(-\d+)?)$/) || [])[1];
|
|
37
|
-
|
|
38
|
-
return result
|
|
39
|
-
? // https://github.com/npm/node-semver/issues/322
|
|
40
|
-
result.replace(/-\d+$/, "")
|
|
41
|
-
: result;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
export function getLowerBound(range) {
|
|
45
|
-
return ((semver.validRange(range) || "").match(/(?<lowerBound>\d+\.\d+\.\d+)/) || [])[1];
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export function highest(version1, version2) {
|
|
49
|
-
return version1 && version2 ? (semver.gt(version1, version2) ? version1 : version2) : version1 || version2;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export function lowest(version1, version2) {
|
|
53
|
-
return version1 && version2 ? (semver.lt(version1, version2) ? version1 : version2) : version1 || version2;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function getLatestVersion(versions, { withPrerelease } = {}) {
|
|
57
|
-
return versions.filter((version) => withPrerelease || !semver.prerelease(version)).sort(semver.rcompare)[0];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export function getEarliestVersion(versions, { withPrerelease } = {}) {
|
|
61
|
-
return versions.filter((version) => withPrerelease || !semver.prerelease(version)).sort(semver.compare)[0];
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export function getFirstVersion(versions, lowerBranches) {
|
|
65
|
-
const lowerVersion = union(...lowerBranches.map(({ tags }) => tagsToVersions(tags))).sort(semver.rcompare);
|
|
66
|
-
if (lowerVersion[0]) {
|
|
67
|
-
return versions.sort(semver.compare).find((version) => semver.gt(version, lowerVersion[0]));
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return getEarliestVersion(versions);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
export function getRange(min, max) {
|
|
74
|
-
return `>=${min}${max ? ` <${max}` : ""}`;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export function makeTag(tagFormat, version) {
|
|
78
|
-
return template(tagFormat)({ version });
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export function isSameChannel(channel, otherChannel) {
|
|
82
|
-
return channel === otherChannel || (!channel && !otherChannel);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export function getVersionDiff(version1, version2) {
|
|
86
|
-
if (semver.gte(version1, version2)) {
|
|
87
|
-
return undefined;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
return semver.diff(version1, version2);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function extractGitLogTags(tagsString) {
|
|
94
|
-
const regex = /tag: ([^,)]+)/g;
|
|
95
|
-
let match;
|
|
96
|
-
const tags = [];
|
|
97
|
-
while ((match = regex.exec(tagsString)) !== null) {
|
|
98
|
-
tags.push(match[1]);
|
|
99
|
-
}
|
|
100
|
-
return tags;
|
|
101
|
-
}
|
package/lib/verify.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { isPlainObject, isString, template } from "lodash-es";
|
|
2
|
-
import AggregateError from "aggregate-error";
|
|
3
|
-
import { isGitRepo, verifyTagName } from "./git.js";
|
|
4
|
-
import getError from "./get-error.js";
|
|
5
|
-
|
|
6
|
-
export default async (context) => {
|
|
7
|
-
const {
|
|
8
|
-
cwd,
|
|
9
|
-
env,
|
|
10
|
-
options: { repositoryUrl, tagFormat, branches },
|
|
11
|
-
} = context;
|
|
12
|
-
const errors = [];
|
|
13
|
-
|
|
14
|
-
if (!(await isGitRepo({ cwd, env }))) {
|
|
15
|
-
errors.push(getError("ENOGITREPO", { cwd }));
|
|
16
|
-
} else if (!repositoryUrl) {
|
|
17
|
-
errors.push(getError("ENOREPOURL"));
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// Verify that compiling the `tagFormat` produce a valid Git tag
|
|
21
|
-
if (!(await verifyTagName(template(tagFormat)({ version: "0.0.0" })))) {
|
|
22
|
-
errors.push(getError("EINVALIDTAGFORMAT", context));
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// Verify the `tagFormat` contains the variable `version` by compiling the `tagFormat` template
|
|
26
|
-
// with a space as the `version` value and verify the result contains the space.
|
|
27
|
-
// The space is used as it's an invalid tag character, so it's guaranteed to no be present in the `tagFormat`.
|
|
28
|
-
if ((template(tagFormat)({ version: " " }).match(/ /g) || []).length !== 1) {
|
|
29
|
-
errors.push(getError("ETAGNOVERSION", context));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
branches.forEach((branch) => {
|
|
33
|
-
if (
|
|
34
|
-
!((isString(branch) && branch.trim()) || (isPlainObject(branch) && isString(branch.name) && branch.name.trim()))
|
|
35
|
-
) {
|
|
36
|
-
errors.push(getError("EINVALIDBRANCH", { branch }));
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
if (errors.length > 0) {
|
|
41
|
-
throw new AggregateError(errors);
|
|
42
|
-
}
|
|
43
|
-
};
|