Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a07b2ee339 | ||
|
|
8f7456f6ed | ||
|
|
2569f0bd91 |
@@ -21,8 +21,9 @@ See https://github.com/semantic-release/semantic-release/blob/master/docs/suppor
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
execa('git', ['--version'])
|
||||
.then(({stdout}) => {
|
||||
execa
|
||||
.stdout('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}.`);
|
||||
|
||||
@@ -46,7 +46,9 @@ 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 won’t 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 won’t be published.`
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -45,6 +45,13 @@ module.exports = async ({cwd, env, options: {repositoryUrl, branch}}) => {
|
||||
const envVar = Object.keys(GIT_TOKENS).find(envVar => !isNil(env[envVar]));
|
||||
const gitCredentials = `${GIT_TOKENS[envVar] || ''}${env[envVar] || ''}`;
|
||||
|
||||
console.log(`-------- envVar -------- `);
|
||||
console.log(envVar);
|
||||
console.log(`-------- GIT_TOKENS[envVar] -------- `);
|
||||
console.log(GIT_TOKENS[envVar]);
|
||||
console.log(`-------- env[envVar].substr(5) -------- `);
|
||||
console.log((env[envVar] || '').substr(5));
|
||||
|
||||
if (gitCredentials) {
|
||||
// If credentials are set via environment variables, convert the URL to http/https and add basic auth, otherwise return `repositoryUrl` as is
|
||||
const [match, auth, host, path] = /^(?!.+:\/\/)(?:(.*)@)?(.*?):(.*)$/.exec(repositoryUrl) || [];
|
||||
|
||||
+9
-9
@@ -11,7 +11,7 @@ const debug = require('debug')('semantic-release:git');
|
||||
*/
|
||||
async function getTagHead(tagName, execaOpts) {
|
||||
try {
|
||||
return (await execa('git', ['rev-list', '-1', tagName], execaOpts)).stdout;
|
||||
return await execa.stdout('git', ['rev-list', '-1', tagName], execaOpts);
|
||||
} 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('git', ['tag'], execaOpts)).stdout
|
||||
return (await execa.stdout('git', ['tag'], execaOpts))
|
||||
.split('\n')
|
||||
.map(tag => tag.trim())
|
||||
.filter(Boolean);
|
||||
@@ -45,7 +45,7 @@ async function isRefInHistory(ref, execaOpts) {
|
||||
await execa('git', ['merge-base', '--is-ancestor', ref, 'HEAD'], execaOpts);
|
||||
return true;
|
||||
} catch (error) {
|
||||
if (error.exitCode === 1) {
|
||||
if (error.code === 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -75,8 +75,8 @@ async function fetch(repositoryUrl, execaOpts) {
|
||||
*
|
||||
* @return {String} the sha of the HEAD commit.
|
||||
*/
|
||||
async function getGitHead(execaOpts) {
|
||||
return (await execa('git', ['rev-parse', 'HEAD'], execaOpts)).stdout;
|
||||
function getGitHead(execaOpts) {
|
||||
return execa.stdout('git', ['rev-parse', 'HEAD'], execaOpts);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -88,7 +88,7 @@ async function getGitHead(execaOpts) {
|
||||
*/
|
||||
async function repoUrl(execaOpts) {
|
||||
try {
|
||||
return (await execa('git', ['config', '--get', 'remote.origin.url'], execaOpts)).stdout;
|
||||
return await execa.stdout('git', ['config', '--get', 'remote.origin.url'], execaOpts);
|
||||
} catch (error) {
|
||||
debug(error);
|
||||
}
|
||||
@@ -103,7 +103,7 @@ async function repoUrl(execaOpts) {
|
||||
*/
|
||||
async function isGitRepo(execaOpts) {
|
||||
try {
|
||||
return (await execa('git', ['rev-parse', '--git-dir'], execaOpts)).exitCode === 0;
|
||||
return (await execa('git', ['rev-parse', '--git-dir'], execaOpts)).code === 0;
|
||||
} catch (error) {
|
||||
debug(error);
|
||||
}
|
||||
@@ -161,7 +161,7 @@ async function push(repositoryUrl, execaOpts) {
|
||||
*/
|
||||
async function verifyTagName(tagName, execaOpts) {
|
||||
try {
|
||||
return (await execa('git', ['check-ref-format', `refs/tags/${tagName}`], execaOpts)).exitCode === 0;
|
||||
return (await execa('git', ['check-ref-format', `refs/tags/${tagName}`], execaOpts)).code === 0;
|
||||
} 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 {stdout: remoteHead} = await execa('git', ['ls-remote', '--heads', 'origin', branch], execaOpts);
|
||||
const remoteHead = await execa.stdout('git', ['ls-remote', '--heads', 'origin', branch], execaOpts);
|
||||
try {
|
||||
return await isRefInHistory(remoteHead.match(/^(\w+)?/)[1], execaOpts);
|
||||
} catch (error) {
|
||||
|
||||
+3
-11
@@ -3,14 +3,6 @@
|
||||
"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"
|
||||
},
|
||||
@@ -35,8 +27,8 @@
|
||||
"aggregate-error": "^3.0.0",
|
||||
"cosmiconfig": "^5.0.1",
|
||||
"debug": "^4.0.0",
|
||||
"env-ci": "^4.0.0",
|
||||
"execa": "^2.0.0",
|
||||
"env-ci": "^3.0.0",
|
||||
"execa": "^1.0.0",
|
||||
"figures": "^3.0.0",
|
||||
"find-versions": "^3.0.0",
|
||||
"get-stream": "^5.0.0",
|
||||
@@ -55,7 +47,7 @@
|
||||
"yargs": "^13.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"ava": "^2.0.0",
|
||||
"ava": "^1.3.1",
|
||||
"clear-module": "^3.0.0",
|
||||
"codecov": "^3.0.0",
|
||||
"commitizen": "^3.0.0",
|
||||
|
||||
@@ -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.regex(error.message, /Cannot find module 'non-existing-path'/);
|
||||
t.is(error.message, "Cannot find module 'non-existing-path'");
|
||||
t.is(error.code, 'MODULE_NOT_FOUND');
|
||||
});
|
||||
|
||||
@@ -69,10 +69,8 @@ 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,
|
||||
async (_, message) =>
|
||||
(await execa('git', ['commit', '-m', message, '--allow-empty', '--no-gpg-sign'], execaOpts)).stdout
|
||||
await pReduce(messages, (_, message) =>
|
||||
execa.stdout('git', ['commit', '-m', message, '--allow-empty', '--no-gpg-sign'], execaOpts)
|
||||
);
|
||||
return (await gitGetCommits(undefined, execaOpts)).slice(0, messages.length);
|
||||
}
|
||||
@@ -114,8 +112,8 @@ export async function gitCheckout(branch, create = true, execaOpts) {
|
||||
*
|
||||
* @return {String} The sha of the head commit in the current git repository.
|
||||
*/
|
||||
export async function gitHead(execaOpts) {
|
||||
return (await execa('git', ['rev-parse', 'HEAD'], execaOpts)).stdout;
|
||||
export function gitHead(execaOpts) {
|
||||
return execa.stdout('git', ['rev-parse', 'HEAD'], execaOpts);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -183,8 +181,8 @@ export async function gitAddConfig(name, value, execaOpts) {
|
||||
*
|
||||
* @return {String} The sha of the commit associated with `tagName` on the local repository.
|
||||
*/
|
||||
export async function gitTagHead(tagName, execaOpts) {
|
||||
return (await execa('git', ['rev-list', '-1', tagName], execaOpts)).stdout;
|
||||
export function gitTagHead(tagName, execaOpts) {
|
||||
return execa.stdout('git', ['rev-list', '-1', tagName], execaOpts);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -197,7 +195,7 @@ export async 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('git', ['ls-remote', '--tags', repositoryUrl, tagName], execaOpts)).stdout
|
||||
return (await execa.stdout('git', ['ls-remote', '--tags', repositoryUrl, tagName], execaOpts))
|
||||
.split('\n')
|
||||
.filter(tag => Boolean(tag))
|
||||
.map(tag => tag.match(/^(\S+)/)[1])[0];
|
||||
@@ -211,8 +209,8 @@ export async function gitRemoteTagHead(repositoryUrl, tagName, execaOpts) {
|
||||
*
|
||||
* @return {String} The tag associatedwith the sha in parameter or `null`.
|
||||
*/
|
||||
export async function gitCommitTag(gitHead, execaOpts) {
|
||||
return (await execa('git', ['describe', '--tags', '--exact-match', gitHead], execaOpts)).stdout;
|
||||
export function gitCommitTag(gitHead, execaOpts) {
|
||||
return execa.stdout('git', ['describe', '--tags', '--exact-match', gitHead], execaOpts);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+28
-28
@@ -72,9 +72,9 @@ test('Release patch, minor and major versions', async t => {
|
||||
t.log('Commit a chore');
|
||||
await gitCommits(['chore: Init repository'], {cwd});
|
||||
t.log('$ semantic-release');
|
||||
let {stdout, exitCode} = await execa(cli, [], {env, cwd});
|
||||
let {stdout, code} = await execa(cli, [], {env, cwd});
|
||||
t.regex(stdout, /There are no relevant changes, so no new version is released/);
|
||||
t.is(exitCode, 0);
|
||||
t.is(code, 0);
|
||||
|
||||
/* Initial release */
|
||||
let version = '1.0.0';
|
||||
@@ -95,10 +95,10 @@ test('Release patch, minor and major versions', async t => {
|
||||
t.log('Commit a feature');
|
||||
await gitCommits(['feat: Initial commit'], {cwd});
|
||||
t.log('$ semantic-release');
|
||||
({stdout, exitCode} = await execa(cli, [], {env, cwd}));
|
||||
({stdout, code} = await execa(cli, [], {env, cwd}));
|
||||
t.regex(stdout, new RegExp(`Published GitHub release: release-url/${version}`));
|
||||
t.regex(stdout, new RegExp(`Publishing version ${version} to npm registry`));
|
||||
t.is(exitCode, 0);
|
||||
t.is(code, 0);
|
||||
|
||||
// Verify package.json and npm-shrinkwrap.json have been updated
|
||||
t.is((await readJson(path.resolve(cwd, 'package.json'))).version, version);
|
||||
@@ -137,10 +137,10 @@ test('Release patch, minor and major versions', async t => {
|
||||
t.log('Commit a fix');
|
||||
await gitCommits(['fix: bar'], {cwd});
|
||||
t.log('$ semantic-release');
|
||||
({stdout, exitCode} = await execa(cli, [], {env, cwd}));
|
||||
({stdout, code} = await execa(cli, [], {env, cwd}));
|
||||
t.regex(stdout, new RegExp(`Published GitHub release: release-url/${version}`));
|
||||
t.regex(stdout, new RegExp(`Publishing version ${version} to npm registry`));
|
||||
t.is(exitCode, 0);
|
||||
t.is(code, 0);
|
||||
|
||||
// Verify package.json and npm-shrinkwrap.json have been updated
|
||||
t.is((await readJson(path.resolve(cwd, 'package.json'))).version, version);
|
||||
@@ -179,10 +179,10 @@ test('Release patch, minor and major versions', async t => {
|
||||
t.log('Commit a feature');
|
||||
await gitCommits(['feat: baz'], {cwd});
|
||||
t.log('$ semantic-release');
|
||||
({stdout, exitCode} = await execa(cli, [], {env, cwd}));
|
||||
({stdout, code} = await execa(cli, [], {env, cwd}));
|
||||
t.regex(stdout, new RegExp(`Published GitHub release: release-url/${version}`));
|
||||
t.regex(stdout, new RegExp(`Publishing version ${version} to npm registry`));
|
||||
t.is(exitCode, 0);
|
||||
t.is(code, 0);
|
||||
|
||||
// Verify package.json and npm-shrinkwrap.json have been updated
|
||||
t.is((await readJson(path.resolve(cwd, 'package.json'))).version, version);
|
||||
@@ -221,10 +221,10 @@ test('Release patch, minor and major versions', async t => {
|
||||
t.log('Commit a breaking change');
|
||||
await gitCommits(['feat: foo\n\n BREAKING CHANGE: bar'], {cwd});
|
||||
t.log('$ semantic-release');
|
||||
({stdout, exitCode} = await execa(cli, [], {env, cwd}));
|
||||
({stdout, code} = await execa(cli, [], {env, cwd}));
|
||||
t.regex(stdout, new RegExp(`Published GitHub release: release-url/${version}`));
|
||||
t.regex(stdout, new RegExp(`Publishing version ${version} to npm registry`));
|
||||
t.is(exitCode, 0);
|
||||
t.is(code, 0);
|
||||
|
||||
// Verify package.json and npm-shrinkwrap.json have been updated
|
||||
t.is((await readJson(path.resolve(cwd, 'package.json'))).version, version);
|
||||
@@ -258,8 +258,8 @@ test('Exit with 1 if a plugin is not found', async t => {
|
||||
release: {analyzeCommits: 'non-existing-path', success: false, fail: false},
|
||||
});
|
||||
|
||||
const {exitCode, stderr} = await t.throwsAsync(execa(cli, [], {env, cwd}));
|
||||
t.is(exitCode, 1);
|
||||
const {code, stderr} = await t.throwsAsync(execa(cli, [], {env, cwd}));
|
||||
t.is(code, 1);
|
||||
t.regex(stderr, /Cannot find module/);
|
||||
});
|
||||
|
||||
@@ -276,8 +276,8 @@ test('Exit with 1 if a shareable config is not found', async t => {
|
||||
release: {extends: 'non-existing-path', success: false, fail: false},
|
||||
});
|
||||
|
||||
const {exitCode, stderr} = await t.throwsAsync(execa(cli, [], {env, cwd}));
|
||||
t.is(exitCode, 1);
|
||||
const {code, stderr} = await t.throwsAsync(execa(cli, [], {env, cwd}));
|
||||
t.is(code, 1);
|
||||
t.regex(stderr, /Cannot find module/);
|
||||
});
|
||||
|
||||
@@ -297,8 +297,8 @@ test('Exit with 1 if a shareable config reference a not found plugin', async t =
|
||||
});
|
||||
await writeJson(path.resolve(cwd, 'shareable.json'), shareable);
|
||||
|
||||
const {exitCode, stderr} = await t.throwsAsync(execa(cli, [], {env, cwd}));
|
||||
t.is(exitCode, 1);
|
||||
const {code, stderr} = await t.throwsAsync(execa(cli, [], {env, cwd}));
|
||||
t.is(code, 1);
|
||||
t.regex(stderr, /Cannot find module/);
|
||||
});
|
||||
|
||||
@@ -327,11 +327,11 @@ test('Dry-run', async t => {
|
||||
t.log('Commit a feature');
|
||||
await gitCommits(['feat: Initial commit'], {cwd});
|
||||
t.log('$ semantic-release -d');
|
||||
const {stdout, exitCode} = await execa(cli, ['-d'], {env, cwd});
|
||||
const {stdout, code} = await execa(cli, ['-d'], {env, cwd});
|
||||
t.regex(stdout, new RegExp(`There is no previous release, the next release version is ${version}`));
|
||||
t.regex(stdout, new RegExp(`Release note for version ${version}`));
|
||||
t.regex(stdout, /Initial commit/);
|
||||
t.is(exitCode, 0);
|
||||
t.is(code, 0);
|
||||
|
||||
// Verify package.json and has not been modified
|
||||
t.is((await readJson(path.resolve(cwd, 'package.json'))).version, '0.0.0-dev');
|
||||
@@ -375,10 +375,10 @@ test('Allow local releases with "noCi" option', async t => {
|
||||
t.log('Commit a feature');
|
||||
await gitCommits(['feat: Initial commit'], {cwd});
|
||||
t.log('$ semantic-release --no-ci');
|
||||
const {stdout, exitCode} = await execa(cli, ['--no-ci'], {env: envNoCi, cwd});
|
||||
const {stdout, code} = await execa(cli, ['--no-ci'], {env: envNoCi, cwd});
|
||||
t.regex(stdout, new RegExp(`Published GitHub release: release-url/${version}`));
|
||||
t.regex(stdout, new RegExp(`Publishing version ${version} to npm registry`));
|
||||
t.is(exitCode, 0);
|
||||
t.is(code, 0);
|
||||
|
||||
// Verify package.json and has been updated
|
||||
t.is((await readJson(path.resolve(cwd, 'package.json'))).version, version);
|
||||
@@ -417,7 +417,7 @@ test('Pass options via CLI arguments', async t => {
|
||||
t.log('Commit a feature');
|
||||
await gitCommits(['feat: Initial commit'], {cwd});
|
||||
t.log('$ semantic-release');
|
||||
const {stdout, exitCode} = await execa(
|
||||
const {stdout, code} = await execa(
|
||||
cli,
|
||||
[
|
||||
'--verify-conditions',
|
||||
@@ -433,7 +433,7 @@ test('Pass options via CLI arguments', async t => {
|
||||
{env, cwd}
|
||||
);
|
||||
t.regex(stdout, new RegExp(`Publishing version ${version} to npm registry`));
|
||||
t.is(exitCode, 0);
|
||||
t.is(code, 0);
|
||||
|
||||
// Verify package.json and has been updated
|
||||
t.is((await readJson(path.resolve(cwd, 'package.json'))).version, version);
|
||||
@@ -528,14 +528,14 @@ test('Log unexpected errors from plugins and exit with 1', async t => {
|
||||
t.log('Commit a feature');
|
||||
await gitCommits(['feat: Initial commit'], {cwd});
|
||||
t.log('$ semantic-release');
|
||||
const {stderr, exitCode} = await execa(cli, [], {env, cwd, reject: false});
|
||||
const {stderr, code} = await execa(cli, [], {env, cwd, reject: false});
|
||||
// Verify the type and message are logged
|
||||
t.regex(stderr, /Error: a/);
|
||||
// Verify the the stacktrace is logged
|
||||
t.regex(stderr, new RegExp(pluginError));
|
||||
// Verify the Error properties are logged
|
||||
t.regex(stderr, /errorProperty: 'errorProperty'/);
|
||||
t.is(exitCode, 1);
|
||||
t.is(code, 1);
|
||||
});
|
||||
|
||||
test('Log errors inheriting SemanticReleaseError and exit with 1', async t => {
|
||||
@@ -555,10 +555,10 @@ test('Log errors inheriting SemanticReleaseError and exit with 1', async t => {
|
||||
t.log('Commit a feature');
|
||||
await gitCommits(['feat: Initial commit'], {cwd});
|
||||
t.log('$ semantic-release');
|
||||
const {stderr, exitCode} = await execa(cli, [], {env, cwd, reject: false});
|
||||
const {stderr, code} = await execa(cli, [], {env, cwd, reject: false});
|
||||
// Verify the type and message are logged
|
||||
t.regex(stderr, /EINHERITED Inherited error/);
|
||||
t.is(exitCode, 1);
|
||||
t.is(code, 1);
|
||||
});
|
||||
|
||||
test('Exit with 1 if missing permission to push to the remote repository', async t => {
|
||||
@@ -573,14 +573,14 @@ test('Exit with 1 if missing permission to push to the remote repository', async
|
||||
await gitCommits(['feat: Initial commit'], {cwd});
|
||||
await gitPush('origin', 'master', {cwd});
|
||||
t.log('$ semantic-release');
|
||||
const {stderr, exitCode} = await execa(
|
||||
const {stderr, code} = await execa(
|
||||
cli,
|
||||
['--repository-url', 'http://user:wrong_pass@localhost:2080/git/unauthorized.git'],
|
||||
{env: {...env, GH_TOKEN: 'user:wrong_pass'}, cwd, reject: false}
|
||||
);
|
||||
// Verify the type and message are logged
|
||||
t.regex(stderr, /EGITNOPERMISSION/);
|
||||
t.is(exitCode, 1);
|
||||
t.is(code, 1);
|
||||
});
|
||||
|
||||
test('Hide sensitive environment variable values from the logs', async t => {
|
||||
|
||||
@@ -255,6 +255,6 @@ test('Throws an error if the plugin is not found', t => {
|
||||
Error
|
||||
);
|
||||
|
||||
t.regex(error.message, /Cannot find module 'non-existing-path'/);
|
||||
t.is(error.message, "Cannot find module 'non-existing-path'");
|
||||
t.is(error.code, 'MODULE_NOT_FOUND');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user