Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e4bb40990 | ||
|
|
4d581fc140 | ||
|
|
9948a74347 |
@@ -76,9 +76,7 @@ async function run(context, plugins) {
|
||||
} catch (error) {
|
||||
if (!(await isBranchUpToDate(options.repositoryUrl, context.branch.name, {cwd, env}))) {
|
||||
logger.log(
|
||||
`The local branch ${
|
||||
context.branch.name
|
||||
} is behind the remote one, therefore a new version won't be published.`
|
||||
`The local branch ${context.branch.name} is behind the remote one, therefore a new version won't be published.`
|
||||
);
|
||||
return false;
|
||||
}
|
||||
@@ -108,7 +106,7 @@ async function run(context, plugins) {
|
||||
nextRelease.notes = await plugins.generateNotes({...context, commits, lastRelease, nextRelease});
|
||||
|
||||
logger.log('Create tag %s', nextRelease.gitTag);
|
||||
await tag(nextRelease.gitTag, nextRelease.gitHead, {cwd, env});
|
||||
await tag(nextRelease, {cwd, env});
|
||||
await push(options.repositoryUrl, {cwd, env});
|
||||
context.branch.tags.push({
|
||||
version: nextRelease.version,
|
||||
@@ -130,9 +128,7 @@ async function run(context, plugins) {
|
||||
|
||||
if (context.lastRelease.gitTag) {
|
||||
logger.log(
|
||||
`Found git tag ${context.lastRelease.gitTag} associated with version ${context.lastRelease.version} on branch ${
|
||||
context.branch.name
|
||||
}`
|
||||
`Found git tag ${context.lastRelease.gitTag} associated with version ${context.lastRelease.version} on branch ${context.branch.name}`
|
||||
);
|
||||
} else {
|
||||
logger.log(`No git tag version found on branch ${context.branch.name}`);
|
||||
@@ -174,7 +170,7 @@ async function run(context, plugins) {
|
||||
logger.warn(`Skip ${nextRelease.gitTag} tag creation in dry-run mode`);
|
||||
} else {
|
||||
// Create the tag before calling the publish plugins as some require the tag to exists
|
||||
await tag(nextRelease.gitTag, nextRelease.gitHead, {cwd, env});
|
||||
await tag(nextRelease, {cwd, env});
|
||||
await push(options.repositoryUrl, {cwd, env});
|
||||
logger.success(`Created tag ${nextRelease.gitTag}`);
|
||||
}
|
||||
|
||||
@@ -14,6 +14,8 @@ const SECRET_REPLACEMENT = '[secure]';
|
||||
|
||||
const SECRET_MIN_SIZE = 5;
|
||||
|
||||
const TAG_MESSAGE_FORMAT = `release \${version}`;
|
||||
|
||||
module.exports = {
|
||||
RELEASE_TYPE,
|
||||
FIRST_RELEASE,
|
||||
@@ -23,4 +25,5 @@ module.exports = {
|
||||
RELEASE_NOTES_SEPARATOR,
|
||||
SECRET_REPLACEMENT,
|
||||
SECRET_MIN_SIZE,
|
||||
TAG_MESSAGE_FORMAT,
|
||||
};
|
||||
|
||||
+11
-7
@@ -1,8 +1,9 @@
|
||||
const {matches, pick, memoize} = require('lodash');
|
||||
const {matches, pick, memoize, template} = require('lodash');
|
||||
const gitLogParser = require('git-log-parser');
|
||||
const getStream = require('get-stream');
|
||||
const execa = require('execa');
|
||||
const debug = require('debug')('semantic-release:git');
|
||||
const {TAG_MESSAGE_FORMAT} = require('./definitions/constants');
|
||||
|
||||
Object.assign(gitLogParser.fields, {hash: 'H', message: 'B', gitTags: 'd', committerDate: {key: 'ci', type: Date}});
|
||||
|
||||
@@ -143,7 +144,7 @@ async function fetch(repositoryUrl, branch, execaOpts) {
|
||||
'fetch',
|
||||
'--unshallow',
|
||||
'--tags',
|
||||
...(isLocalExists ? [repositoryUrl] : [repositoryUrl, `+refs/heads/${branch}:refs/remotes/upstream/${branch}`]),
|
||||
...(isLocalExists ? [repositoryUrl] : [repositoryUrl, `+refs/heads/${branch}:refs/heads/${branch}`]),
|
||||
],
|
||||
execaOpts
|
||||
);
|
||||
@@ -153,7 +154,7 @@ async function fetch(repositoryUrl, branch, execaOpts) {
|
||||
[
|
||||
'fetch',
|
||||
'--tags',
|
||||
...(isLocalExists ? [repositoryUrl] : [repositoryUrl, `+refs/heads/${branch}:refs/remotes/upstream/${branch}`]),
|
||||
...(isLocalExists ? [repositoryUrl] : [repositoryUrl, `+refs/heads/${branch}:refs/heads/${branch}`]),
|
||||
],
|
||||
execaOpts
|
||||
);
|
||||
@@ -222,14 +223,17 @@ async function verifyAuth(repositoryUrl, branch, execaOpts) {
|
||||
/**
|
||||
* Tag the commit head on the local repository.
|
||||
*
|
||||
* @param {String} tagName The name of the tag.
|
||||
* @param {String} ref The Git reference to tag.
|
||||
* @param {Object} release The release associated with the tag.
|
||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||
*
|
||||
* @throws {Error} if the tag creation failed.
|
||||
*/
|
||||
async function tag(tagName, ref, execaOpts) {
|
||||
await execa('git', ['tag', tagName, ref], execaOpts);
|
||||
async function tag(release, execaOpts) {
|
||||
await execa(
|
||||
'git',
|
||||
['tag', release.gitTag, release.gitHead, '-a', '-m', template(TAG_MESSAGE_FORMAT)(release)],
|
||||
execaOpts
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+3
-3
@@ -183,7 +183,7 @@ test('Add tag on head commit', async t => {
|
||||
const {cwd} = await gitRepo();
|
||||
const commits = await gitCommits(['Test commit'], {cwd});
|
||||
|
||||
await tag('tag_name', 'HEAD', {cwd});
|
||||
await tag({gitTag: 'tag_name', gitHead: 'HEAD', version: '1.0.0'}, {cwd});
|
||||
|
||||
await t.is(await gitCommitTag(commits[0].hash, {cwd}), 'tag_name');
|
||||
});
|
||||
@@ -193,7 +193,7 @@ test('Push tag to remote repository', async t => {
|
||||
const {cwd, repositoryUrl} = await gitRepo(true);
|
||||
const commits = await gitCommits(['Test commit'], {cwd});
|
||||
|
||||
await tag('tag_name', 'HEAD', {cwd});
|
||||
await tag({gitTag: 'tag_name', gitHead: 'HEAD', version: '1.0.0'}, {cwd});
|
||||
await push(repositoryUrl, {cwd});
|
||||
|
||||
t.is(await gitRemoteTagHead(repositoryUrl, 'tag_name', {cwd}), commits[0].hash);
|
||||
@@ -207,7 +207,7 @@ test('Push tag to remote repository with remote branch ahead', async t => {
|
||||
await gitCommits(['Second'], {cwd: tmpRepo});
|
||||
await gitPush('origin', 'master', {cwd: tmpRepo});
|
||||
|
||||
await tag('tag_name', 'HEAD', {cwd});
|
||||
await tag({gitTag: 'tag_name', gitHead: 'HEAD', version: '1.0.0'}, {cwd});
|
||||
await push(repositoryUrl, {cwd});
|
||||
|
||||
t.is(await gitRemoteTagHead(repositoryUrl, 'tag_name', {cwd}), commits[0].hash);
|
||||
|
||||
@@ -195,7 +195,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.stdout('git', ['ls-remote', repositoryUrl, `${tagName}^{}`], execaOpts))
|
||||
.split('\n')
|
||||
.filter(tag => Boolean(tag))
|
||||
.map(tag => tag.match(/^(\S+)/)[1])[0];
|
||||
|
||||
Reference in New Issue
Block a user