feat: create annotated tags
This commit is contained in:
parent
9948a74347
commit
4d581fc140
4
index.js
4
index.js
@ -108,7 +108,7 @@ async function run(context, plugins) {
|
|||||||
nextRelease.notes = await plugins.generateNotes({...context, commits, lastRelease, nextRelease});
|
nextRelease.notes = await plugins.generateNotes({...context, commits, lastRelease, nextRelease});
|
||||||
|
|
||||||
logger.log('Create tag %s', nextRelease.gitTag);
|
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});
|
await push(options.repositoryUrl, {cwd, env});
|
||||||
context.branch.tags.push({
|
context.branch.tags.push({
|
||||||
version: nextRelease.version,
|
version: nextRelease.version,
|
||||||
@ -174,7 +174,7 @@ async function run(context, plugins) {
|
|||||||
logger.warn(`Skip ${nextRelease.gitTag} tag creation in dry-run mode`);
|
logger.warn(`Skip ${nextRelease.gitTag} tag creation in dry-run mode`);
|
||||||
} else {
|
} else {
|
||||||
// Create the tag before calling the publish plugins as some require the tag to exists
|
// 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});
|
await push(options.repositoryUrl, {cwd, env});
|
||||||
logger.success(`Created tag ${nextRelease.gitTag}`);
|
logger.success(`Created tag ${nextRelease.gitTag}`);
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,8 @@ const SECRET_REPLACEMENT = '[secure]';
|
|||||||
|
|
||||||
const SECRET_MIN_SIZE = 5;
|
const SECRET_MIN_SIZE = 5;
|
||||||
|
|
||||||
|
const TAG_MESSAGE_FORMAT = `release \${version}`;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
RELEASE_TYPE,
|
RELEASE_TYPE,
|
||||||
FIRST_RELEASE,
|
FIRST_RELEASE,
|
||||||
@ -23,4 +25,5 @@ module.exports = {
|
|||||||
RELEASE_NOTES_SEPARATOR,
|
RELEASE_NOTES_SEPARATOR,
|
||||||
SECRET_REPLACEMENT,
|
SECRET_REPLACEMENT,
|
||||||
SECRET_MIN_SIZE,
|
SECRET_MIN_SIZE,
|
||||||
|
TAG_MESSAGE_FORMAT,
|
||||||
};
|
};
|
||||||
|
14
lib/git.js
14
lib/git.js
@ -1,8 +1,9 @@
|
|||||||
const {matches, pick, memoize} = require('lodash');
|
const {matches, pick, memoize, template} = require('lodash');
|
||||||
const gitLogParser = require('git-log-parser');
|
const gitLogParser = require('git-log-parser');
|
||||||
const getStream = require('get-stream');
|
const getStream = require('get-stream');
|
||||||
const execa = require('execa');
|
const execa = require('execa');
|
||||||
const debug = require('debug')('semantic-release:git');
|
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}});
|
Object.assign(gitLogParser.fields, {hash: 'H', message: 'B', gitTags: 'd', committerDate: {key: 'ci', type: Date}});
|
||||||
|
|
||||||
@ -222,14 +223,17 @@ async function verifyAuth(repositoryUrl, branch, execaOpts) {
|
|||||||
/**
|
/**
|
||||||
* Tag the commit head on the local repository.
|
* Tag the commit head on the local repository.
|
||||||
*
|
*
|
||||||
* @param {String} tagName The name of the tag.
|
* @param {Object} release The release associated with the tag.
|
||||||
* @param {String} ref The Git reference to tag.
|
|
||||||
* @param {Object} [execaOpts] Options to pass to `execa`.
|
* @param {Object} [execaOpts] Options to pass to `execa`.
|
||||||
*
|
*
|
||||||
* @throws {Error} if the tag creation failed.
|
* @throws {Error} if the tag creation failed.
|
||||||
*/
|
*/
|
||||||
async function tag(tagName, ref, execaOpts) {
|
async function tag(release, execaOpts) {
|
||||||
await execa('git', ['tag', tagName, ref], execaOpts);
|
await execa(
|
||||||
|
'git',
|
||||||
|
['tag', release.gitTag, release.gitHead, '-a', '-m', template(TAG_MESSAGE_FORMAT)(release)],
|
||||||
|
execaOpts
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -183,7 +183,7 @@ test('Add tag on head commit', async t => {
|
|||||||
const {cwd} = await gitRepo();
|
const {cwd} = await gitRepo();
|
||||||
const commits = await gitCommits(['Test commit'], {cwd});
|
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');
|
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 {cwd, repositoryUrl} = await gitRepo(true);
|
||||||
const commits = await gitCommits(['Test commit'], {cwd});
|
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});
|
await push(repositoryUrl, {cwd});
|
||||||
|
|
||||||
t.is(await gitRemoteTagHead(repositoryUrl, 'tag_name', {cwd}), commits[0].hash);
|
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 gitCommits(['Second'], {cwd: tmpRepo});
|
||||||
await gitPush('origin', 'master', {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});
|
await push(repositoryUrl, {cwd});
|
||||||
|
|
||||||
t.is(await gitRemoteTagHead(repositoryUrl, 'tag_name', {cwd}), commits[0].hash);
|
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.
|
* @return {String} The sha of the commit associated with `tagName` on the remote repository.
|
||||||
*/
|
*/
|
||||||
export async function gitRemoteTagHead(repositoryUrl, tagName, execaOpts) {
|
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')
|
.split('\n')
|
||||||
.filter(tag => Boolean(tag))
|
.filter(tag => Boolean(tag))
|
||||||
.map(tag => tag.match(/^(\S+)/)[1])[0];
|
.map(tag => tag.match(/^(\S+)/)[1])[0];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user