Skip to content

Commit faabffb

Browse files
committed
fix: log all core verification errors
1 parent 2f75dff commit faabffb

File tree

6 files changed

+50
-28
lines changed

6 files changed

+50
-28
lines changed

lib/get-config.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
const readPkgUp = require('read-pkg-up');
21
const {castArray, pickBy, isUndefined, isNull, isString, isPlainObject} = require('lodash');
2+
const readPkgUp = require('read-pkg-up');
33
const cosmiconfig = require('cosmiconfig');
44
const resolveFrom = require('resolve-from');
5-
const SemanticReleaseError = require('@semantic-release/error');
65
const debug = require('debug')('semantic-release:config');
76
const {repoUrl} = require('./git');
87
const PLUGINS_DEFINITION = require('./plugins/definitions');
@@ -61,11 +60,7 @@ module.exports = async (opts, logger) => {
6160
debug('verifyRelease: %O', options.verifyRelease);
6261
debug('publish: %O', options.publish);
6362

64-
if (!options.repositoryUrl) {
65-
throw new SemanticReleaseError('The repositoryUrl option is required', 'ENOREPOURL');
66-
}
67-
68-
options.repositoryUrl = getGitAuthUrl(options.repositoryUrl);
63+
options.repositoryUrl = options.repositoryUrl ? getGitAuthUrl(options.repositoryUrl) : options.repositoryUrl;
6964

7065
return {options, plugins: await plugins(options, pluginsPath, logger)};
7166
};

lib/plugins/index.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
const {isArray, isObject, omit} = require('lodash');
2+
const AggregateError = require('aggregate-error');
23
const SemanticReleaseError = require('@semantic-release/error');
34
const PLUGINS_DEFINITION = require('./definitions');
45
const pipeline = require('./pipeline');
56
const normalize = require('./normalize');
67

7-
module.exports = (options, pluginsPath, logger) =>
8-
Object.keys(PLUGINS_DEFINITION).reduce((plugins, pluginType) => {
8+
module.exports = (options, pluginsPath, logger) => {
9+
const errors = [];
10+
const plugins = Object.keys(PLUGINS_DEFINITION).reduce((plugins, pluginType) => {
911
const {config, output, default: def} = PLUGINS_DEFINITION[pluginType];
1012
let pluginConfs;
1113
if (options[pluginType]) {
@@ -14,7 +16,8 @@ module.exports = (options, pluginsPath, logger) =>
1416
options[pluginType].path = def;
1517
}
1618
if (config && !config.validator(options[pluginType])) {
17-
throw new SemanticReleaseError(config.message, 'EPLUGINCONF');
19+
errors.push(new SemanticReleaseError(config.message, 'EPLUGINCONF'));
20+
return plugins;
1821
}
1922
pluginConfs = options[pluginType];
2023
} else {
@@ -29,3 +32,8 @@ module.exports = (options, pluginsPath, logger) =>
2932

3033
return plugins;
3134
}, {});
35+
if (errors.length > 0) {
36+
throw new AggregateError(errors);
37+
}
38+
return plugins;
39+
};

lib/verify.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11
const SemanticReleaseError = require('@semantic-release/error');
2+
const AggregateError = require('aggregate-error');
23
const {isGitRepo, verifyAuth} = require('./git');
34

45
module.exports = async (options, branch, logger) => {
6+
const errors = [];
7+
58
if (!await isGitRepo()) {
69
logger.error('Semantic-release must run from a git repository.');
710
return false;
811
}
912

10-
if (!await verifyAuth(options.repositoryUrl, options.branch)) {
11-
throw new SemanticReleaseError(
12-
`The git credentials doesn't allow to push on the branch ${options.branch}.`,
13-
'EGITNOPERMISSION'
13+
if (!options.repositoryUrl) {
14+
errors.push(new SemanticReleaseError('The repositoryUrl option is required', 'ENOREPOURL'));
15+
} else if (!await verifyAuth(options.repositoryUrl, options.branch)) {
16+
errors.push(
17+
new SemanticReleaseError(
18+
`The git credentials doesn't allow to push on the branch ${options.branch}.`,
19+
'EGITNOPERMISSION'
20+
)
1421
);
1522
}
1623

24+
if (errors.length > 0) {
25+
throw new AggregateError(errors);
26+
}
27+
1728
if (branch !== options.branch) {
1829
logger.log(
1930
`This test run was triggered on the branch ${branch}, while semantic-release is configured to only publish from ${

test/get-config.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ const envBackup = Object.assign({}, process.env);
1313
const cwd = process.cwd();
1414

1515
test.beforeEach(t => {
16-
// Delete environment variables that could have been set on the machine running the tests
1716
delete process.env.GIT_CREDENTIALS;
1817
delete process.env.GH_TOKEN;
1918
delete process.env.GITHUB_TOKEN;
2019
delete process.env.GL_TOKEN;
2120
delete process.env.GITLAB_TOKEN;
21+
// Delete environment variables that could have been set on the machine running the tests
2222
t.context.plugins = stub().returns({});
2323
t.context.getConfig = proxyquire('../lib/get-config', {'./plugins': t.context.plugins});
2424
});

test/index.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,11 +601,11 @@ test.serial('Throw SemanticReleaseError if repositoryUrl is not set and cannot b
601601
'./lib/logger': t.context.logger,
602602
'env-ci': () => ({isCi: true, branch: 'master', isPr: false}),
603603
});
604-
const error = await t.throws(semanticRelease());
604+
const errors = Array.from(await t.throws(semanticRelease()));
605605

606606
// Verify error code and type
607-
t.is(error.code, 'ENOREPOURL');
608-
t.is(error.name, 'SemanticReleaseError');
607+
t.is(errors[0].code, 'ENOREPOURL');
608+
t.is(errors[0].name, 'SemanticReleaseError');
609609
});
610610

611611
test.serial('Throw an Error if plugin returns an unexpected value', async t => {

test/plugins/plugins.test.js

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,26 +127,34 @@ test('Merge global options with plugin options', async t => {
127127
t.deepEqual(result.pluginConfig, {localOpt: 'local', globalOpt: 'global', otherOpt: 'locally-defined'});
128128
});
129129

130-
test('Throw an error if plugin configuration is missing a path for plugin pipeline', t => {
131-
const error = t.throws(() => getPlugins({verifyConditions: {}}, {}, t.context.logger));
130+
test('Throw an error if plugins configuration are missing a path for plugin pipeline', t => {
131+
const errors = Array.from(
132+
t.throws(() => getPlugins({verifyConditions: {}, verifyRelease: {}}, {}, t.context.logger))
133+
);
132134

133-
t.is(error.name, 'SemanticReleaseError');
134-
t.is(error.code, 'EPLUGINCONF');
135+
t.is(errors[0].name, 'SemanticReleaseError');
136+
t.is(errors[0].code, 'EPLUGINCONF');
135137
t.is(
136-
error.message,
138+
errors[0].message,
137139
'The "verifyConditions" plugin, if defined, must be a single or an array of plugins definition. A plugin definition is either a string or an object with a path property.'
138140
);
141+
t.is(errors[1].name, 'SemanticReleaseError');
142+
t.is(errors[1].code, 'EPLUGINCONF');
143+
t.is(
144+
errors[1].message,
145+
'The "verifyRelease" plugin, if defined, must be a single or an array of plugins definition. A plugin definition is either a string or an object with a path property.'
146+
);
139147
});
140148

141149
test('Throw an error if an array of plugin configuration is missing a path for plugin pipeline', t => {
142-
const error = t.throws(() =>
143-
getPlugins({verifyConditions: [{path: '@semantic-release/npm'}, {}]}, {}, t.context.logger)
150+
const errors = Array.from(
151+
t.throws(() => getPlugins({verifyConditions: [{path: '@semantic-release/npm'}, {}]}, {}, t.context.logger))
144152
);
145153

146-
t.is(error.name, 'SemanticReleaseError');
147-
t.is(error.code, 'EPLUGINCONF');
154+
t.is(errors[0].name, 'SemanticReleaseError');
155+
t.is(errors[0].code, 'EPLUGINCONF');
148156
t.is(
149-
error.message,
157+
errors[0].message,
150158
'The "verifyConditions" plugin, if defined, must be a single or an array of plugins definition. A plugin definition is either a string or an object with a path property.'
151159
);
152160
});

0 commit comments

Comments
 (0)