Compare commits

...
Author SHA1 Message Date
Pierre Vanduynslager 6b3adf6bbe fix: revert to execa ^1.0.0 2019-06-26 12:33:59 -04:00
Rob CresswellandGregor Martynus 228fed7a0b docs: document that plugins config is an override (#1216)
This patch documents that the `plugin` config option is an override, not
a merge with the default. This is significant, for example, if you
customise the github plugin as it will then prevent npm publishing by
default unless the npm plugin is also defined manually.
2019-06-25 13:01:55 -07:00
Pierre Vanduynslager 01a0b2d08a test: use regexp to check missing module message 2019-06-25 11:30:37 -04:00
greenkeeper[bot]andPierre Vanduynslager 52c48be17b fix(package): update execa to version 2.0.0 2019-06-25 11:30:37 -04:00
Pierre Vanduynslager 4ed6213977 style: fix prettier style 2019-06-07 11:47:28 -04:00
greenkeeper[bot]andPierre Vanduynslager 8051294ffd fix(package): update env-ci to version 4.0.0 2019-06-07 11:21:44 -04:00
greenkeeper[bot]andPierre Vanduynslager 95a0456a85 chore(package): update ava to version 2.0.0 2019-06-05 14:43:18 -04:00
GregorandPierre Vanduynslager 038e640d5e fix: prefix git auth with "x-access-token:" when run in a GitHub Action 2019-06-05 12:17:21 -04:00
GregorandPierre Vanduynslager f3f9d1ef58 test: prefix git auth with "x-access-token:" when run in a GitHub Action 2019-06-05 12:17:21 -04:00
11 changed files with 77 additions and 53 deletions
+2 -3
View File
@@ -21,9 +21,8 @@ See https://github.com/semantic-release/semantic-release/blob/master/docs/suppor
process.exit(1);
}
execa
.stdout('git', ['--version'])
.then(stdout => {
execa('git', ['--version'])
.then(({stdout}) => {
var gitVersion = findVersions(stdout)[0];
if (semver.lt(gitVersion, MIN_GIT_VERSION)) {
console.error(`[semantic-release]: Git version ${MIN_GIT_VERSION} is required. Found ${gitVersion}.`);
+2
View File
@@ -44,6 +44,8 @@ Each plugin must be configured with the [`plugins` options](./configuration.md#p
}
```
**Note:** If the `plugins` option is defined, it overrides the default plugin list, rather than merging with it.
## Plugin ordering
For each [release step](../../README.md#release-steps) the plugins that implement that step will be executed in the order in which the are defined.
+1 -3
View File
@@ -46,9 +46,7 @@ async function run(context, plugins) {
if (ciBranch !== options.branch) {
logger.log(
`This test run was triggered on the branch ${ciBranch}, while semantic-release is configured to only publish from ${
options.branch
}, therefore a new version wont be published.`
`This test run was triggered on the branch ${ciBranch}, while semantic-release is configured to only publish from ${options.branch}, therefore a new version wont be published.`
);
return false;
}
+12 -10
View File
@@ -3,16 +3,6 @@ const {isNil} = require('lodash');
const hostedGitInfo = require('hosted-git-info');
const {verifyAuth} = require('./git');
const GIT_TOKENS = {
GIT_CREDENTIALS: undefined,
GH_TOKEN: undefined,
GITHUB_TOKEN: undefined,
GL_TOKEN: 'gitlab-ci-token:',
GITLAB_TOKEN: 'gitlab-ci-token:',
BB_TOKEN: 'x-token-auth:',
BITBUCKET_TOKEN: 'x-token-auth:',
};
/**
* Determine the the git repository URL to use to push, either:
* - The `repositoryUrl` as is if allowed to push
@@ -25,6 +15,18 @@ const GIT_TOKENS = {
* @return {String} The formatted Git repository URL.
*/
module.exports = async ({cwd, env, options: {repositoryUrl, branch}}) => {
const GIT_TOKENS = {
GIT_CREDENTIALS: undefined,
GH_TOKEN: undefined,
// GitHub Actions require the "x-access-token:" prefix for git access
// https://developer.github.com/apps/building-github-apps/authenticating-with-github-apps/#http-based-git-access-by-an-installation
GITHUB_TOKEN: isNil(env.GITHUB_ACTION) ? undefined : 'x-access-token:',
GL_TOKEN: 'gitlab-ci-token:',
GITLAB_TOKEN: 'gitlab-ci-token:',
BB_TOKEN: 'x-token-auth:',
BITBUCKET_TOKEN: 'x-token-auth:',
};
const info = hostedGitInfo.fromUrl(repositoryUrl, {noGitPlus: true});
const {protocol, ...parsed} = parse(repositoryUrl);
+6 -6
View File
@@ -11,7 +11,7 @@ const debug = require('debug')('semantic-release:git');
*/
async function getTagHead(tagName, execaOpts) {
try {
return await execa.stdout('git', ['rev-list', '-1', tagName], execaOpts);
return (await execa('git', ['rev-list', '-1', tagName], execaOpts)).stdout;
} catch (error) {
debug(error);
}
@@ -26,7 +26,7 @@ async function getTagHead(tagName, execaOpts) {
* @throws {Error} If the `git` command fails.
*/
async function getTags(execaOpts) {
return (await execa.stdout('git', ['tag'], execaOpts))
return (await execa('git', ['tag'], execaOpts)).stdout
.split('\n')
.map(tag => tag.trim())
.filter(Boolean);
@@ -75,8 +75,8 @@ async function fetch(repositoryUrl, execaOpts) {
*
* @return {String} the sha of the HEAD commit.
*/
function getGitHead(execaOpts) {
return execa.stdout('git', ['rev-parse', 'HEAD'], execaOpts);
async function getGitHead(execaOpts) {
return (await execa('git', ['rev-parse', 'HEAD'], execaOpts)).stdout;
}
/**
@@ -88,7 +88,7 @@ function getGitHead(execaOpts) {
*/
async function repoUrl(execaOpts) {
try {
return await execa.stdout('git', ['config', '--get', 'remote.origin.url'], execaOpts);
return (await execa('git', ['config', '--get', 'remote.origin.url'], execaOpts)).stdout;
} catch (error) {
debug(error);
}
@@ -176,7 +176,7 @@ async function verifyTagName(tagName, execaOpts) {
* @return {Boolean} `true` is the HEAD of the current local branch is the same as the HEAD of the remote branch, falsy otherwise.
*/
async function isBranchUpToDate(branch, execaOpts) {
const remoteHead = await execa.stdout('git', ['ls-remote', '--heads', 'origin', branch], execaOpts);
const {stdout: remoteHead} = await execa('git', ['ls-remote', '--heads', 'origin', branch], execaOpts);
try {
return await isRefInHistory(remoteHead.match(/^(\w+)?/)[1], execaOpts);
} catch (error) {
+10 -2
View File
@@ -3,6 +3,14 @@
"description": "Automated semver compliant package publishing",
"version": "0.0.0-development",
"author": "Stephan Bönnemann <stephan@boennemann.me> (http://boennemann.me)",
"ava": {
"files": [
"test/**/*.test.js"
],
"helpers": [
"test/helpers/**/*"
]
},
"bin": {
"semantic-release": "bin/semantic-release.js"
},
@@ -27,7 +35,7 @@
"aggregate-error": "^3.0.0",
"cosmiconfig": "^5.0.1",
"debug": "^4.0.0",
"env-ci": "^3.0.0",
"env-ci": "^4.0.0",
"execa": "^1.0.0",
"figures": "^3.0.0",
"find-versions": "^3.0.0",
@@ -47,7 +55,7 @@
"yargs": "^13.1.0"
},
"devDependencies": {
"ava": "^1.3.1",
"ava": "^2.0.0",
"clear-module": "^3.0.0",
"codecov": "^3.0.0",
"commitizen": "^3.0.0",
+18 -18
View File
@@ -66,7 +66,7 @@ test.serial('Pass options to semantic-release API', async t => {
];
const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}});
const exitCode = await cli();
const code = await cli();
t.is(run.args[0][0].branch, 'master');
t.is(run.args[0][0].repositoryUrl, 'https://github/com/owner/repo.git');
@@ -84,7 +84,7 @@ test.serial('Pass options to semantic-release API', async t => {
t.is(run.args[0][0].debug, true);
t.is(run.args[0][0].dryRun, true);
t.is(exitCode, 0);
t.is(code, 0);
});
test.serial('Pass options to semantic-release API with alias arguments', async t => {
@@ -108,7 +108,7 @@ test.serial('Pass options to semantic-release API with alias arguments', async t
];
const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}});
const exitCode = await cli();
const code = await cli();
t.is(run.args[0][0].branch, 'master');
t.is(run.args[0][0].repositoryUrl, 'https://github/com/owner/repo.git');
@@ -117,7 +117,7 @@ test.serial('Pass options to semantic-release API with alias arguments', async t
t.deepEqual(run.args[0][0].extends, ['config1', 'config2']);
t.is(run.args[0][0].dryRun, true);
t.is(exitCode, 0);
t.is(code, 0);
});
test.serial('Pass unknown options to semantic-release API', async t => {
@@ -125,13 +125,13 @@ test.serial('Pass unknown options to semantic-release API', async t => {
const argv = ['', '', '--bool', '--first-option', 'value1', '--second-option', 'value2', '--second-option', 'value3'];
const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}});
const exitCode = await cli();
const code = await cli();
t.is(run.args[0][0].bool, true);
t.is(run.args[0][0].firstOption, 'value1');
t.deepEqual(run.args[0][0].secondOption, ['value2', 'value3']);
t.is(exitCode, 0);
t.is(code, 0);
});
test.serial('Pass empty Array to semantic-release API for list option set to "false"', async t => {
@@ -139,11 +139,11 @@ test.serial('Pass empty Array to semantic-release API for list option set to "fa
const argv = ['', '', '--publish', 'false'];
const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}});
const exitCode = await cli();
const code = await cli();
t.deepEqual(run.args[0][0].publish, []);
t.is(exitCode, 0);
t.is(code, 0);
});
test.serial('Do not set properties in option for which arg is not in command line', async t => {
@@ -168,10 +168,10 @@ test.serial('Display help', async t => {
const argv = ['', '', '--help'];
const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}});
const exitCode = await cli();
const code = await cli();
t.regex(t.context.logs, /Run automated package publishing/);
t.is(exitCode, 0);
t.is(code, 0);
});
test.serial('Return error code and prints help if called with a command', async t => {
@@ -179,11 +179,11 @@ test.serial('Return error code and prints help if called with a command', async
const argv = ['', '', 'pre'];
const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}});
const exitCode = await cli();
const code = await cli();
t.regex(t.context.errors, /Run automated package publishing/);
t.regex(t.context.errors, /Too many non-option arguments/);
t.is(exitCode, 1);
t.is(code, 1);
});
test.serial('Return error code if multiple plugin are set for single plugin', async t => {
@@ -191,11 +191,11 @@ test.serial('Return error code if multiple plugin are set for single plugin', as
const argv = ['', '', '--analyze-commits', 'analyze1', 'analyze2'];
const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}});
const exitCode = await cli();
const code = await cli();
t.regex(t.context.errors, /Run automated package publishing/);
t.regex(t.context.errors, /Too many non-option arguments/);
t.is(exitCode, 1);
t.is(code, 1);
});
test.serial('Return error code if semantic-release throw error', async t => {
@@ -203,10 +203,10 @@ test.serial('Return error code if semantic-release throw error', async t => {
const argv = ['', ''];
const cli = requireNoCache('../cli', {'.': run, process: {...process, argv}});
const exitCode = await cli();
const code = await cli();
t.regex(t.context.errors, /semantic-release error/);
t.is(exitCode, 1);
t.is(code, 1);
});
test.serial('Hide sensitive environment variable values from the logs', async t => {
@@ -215,8 +215,8 @@ test.serial('Hide sensitive environment variable values from the logs', async t
const argv = ['', ''];
const cli = requireNoCache('../cli', {'.': run, process: {...process, argv, env: {...process.env, ...env}}});
const exitCode = await cli();
const code = await cli();
t.regex(t.context.errors, new RegExp(`Throw error: Exposing token ${escapeRegExp(SECRET_REPLACEMENT)}`));
t.is(exitCode, 1);
t.is(code, 1);
});
+1 -1
View File
@@ -482,6 +482,6 @@ test('Throw an Error if one of the shareable config cannot be found', async t =>
const error = await t.throwsAsync(t.context.getConfig({cwd}), Error);
t.is(error.message, "Cannot find module 'non-existing-path'");
t.regex(error.message, /Cannot find module 'non-existing-path'/);
t.is(error.code, 'MODULE_NOT_FOUND');
});
+13
View File
@@ -244,6 +244,19 @@ test('Return the "https" formatted URL if "gitCredentials" is defined with "BITB
);
});
test('Return the "https" formatted URL if "GITHUB_ACTION" is set', async t => {
const {cwd} = await gitRepo();
t.is(
await getAuthUrl({
cwd,
env: {...env, GITHUB_ACTION: 'foo', GITHUB_TOKEN: 'token'},
options: {branch: 'master', repositoryUrl: 'git@host.null:owner/repo.git'},
}),
'https://x-access-token:token@host.null/owner/repo.git'
);
});
test('Handle "https" URL with group and subgroup, with "GIT_CREDENTIALS"', async t => {
const {cwd} = await gitRepo();
+11 -9
View File
@@ -69,8 +69,10 @@ export async function initBareRepo(repositoryUrl, branch = 'master') {
* @returns {Array<Commit>} The created commits, in reverse order (to match `git log` order).
*/
export async function gitCommits(messages, execaOpts) {
await pReduce(messages, (_, message) =>
execa.stdout('git', ['commit', '-m', message, '--allow-empty', '--no-gpg-sign'], execaOpts)
await pReduce(
messages,
async (_, message) =>
(await execa('git', ['commit', '-m', message, '--allow-empty', '--no-gpg-sign'], execaOpts)).stdout
);
return (await gitGetCommits(undefined, execaOpts)).slice(0, messages.length);
}
@@ -112,8 +114,8 @@ export async function gitCheckout(branch, create = true, execaOpts) {
*
* @return {String} The sha of the head commit in the current git repository.
*/
export function gitHead(execaOpts) {
return execa.stdout('git', ['rev-parse', 'HEAD'], execaOpts);
export async function gitHead(execaOpts) {
return (await execa('git', ['rev-parse', 'HEAD'], execaOpts)).stdout;
}
/**
@@ -181,8 +183,8 @@ export async function gitAddConfig(name, value, execaOpts) {
*
* @return {String} The sha of the commit associated with `tagName` on the local repository.
*/
export function gitTagHead(tagName, execaOpts) {
return execa.stdout('git', ['rev-list', '-1', tagName], execaOpts);
export async function gitTagHead(tagName, execaOpts) {
return (await execa('git', ['rev-list', '-1', tagName], execaOpts)).stdout;
}
/**
@@ -195,7 +197,7 @@ export function gitTagHead(tagName, execaOpts) {
* @return {String} The sha of the commit associated with `tagName` on the remote repository.
*/
export async function gitRemoteTagHead(repositoryUrl, tagName, execaOpts) {
return (await execa.stdout('git', ['ls-remote', '--tags', repositoryUrl, tagName], execaOpts))
return (await execa('git', ['ls-remote', '--tags', repositoryUrl, tagName], execaOpts)).stdout
.split('\n')
.filter(tag => Boolean(tag))
.map(tag => tag.match(/^(\S+)/)[1])[0];
@@ -209,8 +211,8 @@ export async function gitRemoteTagHead(repositoryUrl, tagName, execaOpts) {
*
* @return {String} The tag associatedwith the sha in parameter or `null`.
*/
export function gitCommitTag(gitHead, execaOpts) {
return execa.stdout('git', ['describe', '--tags', '--exact-match', gitHead], execaOpts);
export async function gitCommitTag(gitHead, execaOpts) {
return (await execa('git', ['describe', '--tags', '--exact-match', gitHead], execaOpts)).stdout;
}
/**
+1 -1
View File
@@ -255,6 +255,6 @@ test('Throws an error if the plugin is not found', t => {
Error
);
t.is(error.message, "Cannot find module 'non-existing-path'");
t.regex(error.message, /Cannot find module 'non-existing-path'/);
t.is(error.code, 'MODULE_NOT_FOUND');
});