feat: set tag author and committer name/email
Use [Git Environment Variables](https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables#Committing). Set default values if environement variables are not set.
This commit is contained in:
parent
4352144a98
commit
61d7d38ec2
@ -29,6 +29,15 @@ $ semantic-release
|
|||||||
|
|
||||||
**Note**: Plugin options cannot be defined via CLI arguments and must be defined in the configuration file.
|
**Note**: Plugin options cannot be defined via CLI arguments and must be defined in the configuration file.
|
||||||
|
|
||||||
|
## Environment variables
|
||||||
|
|
||||||
|
| Variable | Description | Default |
|
||||||
|
|-----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------|
|
||||||
|
| `GIT_AUTHOR_NAME` | The author name associated with the [Git release tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging). See [Git environment variables](https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables#_committing). | @semantic-release-bot. |
|
||||||
|
| `GIT_AUTHOR_EMAIL` | The author email associated with the [Git release tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging). See [Git environment variables](https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables#_committing). | @semantic-release-bot email address. |
|
||||||
|
| `GIT_COMMITTER_NAME` | The committer name associated with the [Git release tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging). See [Git environment variables](https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables#_committing). | @semantic-release-bot. |
|
||||||
|
| `GIT_COMMITTER_EMAIL` | The committer email associated with the [Git release tag](https://git-scm.com/book/en/v2/Git-Basics-Tagging). See [Git environment variables](https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables#_committing). | @semantic-release-bot email address. |
|
||||||
|
|
||||||
## Options
|
## Options
|
||||||
|
|
||||||
### extends
|
### extends
|
||||||
|
14
index.js
14
index.js
@ -15,6 +15,7 @@ const getGitAuthUrl = require('./lib/get-git-auth-url');
|
|||||||
const logger = require('./lib/logger');
|
const logger = require('./lib/logger');
|
||||||
const {unshallow, verifyAuth, isBranchUpToDate, gitHead: getGitHead, tag, push} = require('./lib/git');
|
const {unshallow, verifyAuth, isBranchUpToDate, gitHead: getGitHead, tag, push} = require('./lib/git');
|
||||||
const getError = require('./lib/get-error');
|
const getError = require('./lib/get-error');
|
||||||
|
const {COMMIT_NAME, COMMIT_EMAIL} = require('./lib/definitions/constants');
|
||||||
|
|
||||||
marked.setOptions({renderer: new TerminalRenderer()});
|
marked.setOptions({renderer: new TerminalRenderer()});
|
||||||
|
|
||||||
@ -25,9 +26,16 @@ async function run(options, plugins) {
|
|||||||
logger.log('This run was not triggered in a known CI environment, running in dry-run mode.');
|
logger.log('This run was not triggered in a known CI environment, running in dry-run mode.');
|
||||||
options.dryRun = true;
|
options.dryRun = true;
|
||||||
} else {
|
} else {
|
||||||
// When running on CI, prevent the `git` CLI to prompt for username/password. See #703.
|
// When running on CI, set the commits author and commiter info and prevent the `git` CLI to prompt for username/password. See #703.
|
||||||
process.env.GIT_ASKPASS = 'echo';
|
process.env = {
|
||||||
process.env.GIT_TERMINAL_PROMPT = 0;
|
GIT_AUTHOR_NAME: COMMIT_NAME,
|
||||||
|
GIT_AUTHOR_EMAIL: COMMIT_EMAIL,
|
||||||
|
GIT_COMMITTER_NAME: COMMIT_NAME,
|
||||||
|
GIT_COMMITTER_EMAIL: COMMIT_EMAIL,
|
||||||
|
...process.env,
|
||||||
|
GIT_ASKPASS: 'echo',
|
||||||
|
GIT_TERMINAL_PROMPT: 0,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isCi && isPr && !options.noCi) {
|
if (isCi && isPr && !options.noCi) {
|
||||||
|
9
lib/definitions/constants.js
Normal file
9
lib/definitions/constants.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
const RELEASE_TYPE = ['major', 'premajor', 'minor', 'preminor', 'patch', 'prepatch', 'prerelease'];
|
||||||
|
|
||||||
|
const FIRST_RELEASE = '1.0.0';
|
||||||
|
|
||||||
|
const COMMIT_NAME = 'semantic-release-bot';
|
||||||
|
|
||||||
|
const COMMIT_EMAIL = 'semantic-release-bot@martynus.net';
|
||||||
|
|
||||||
|
module.exports = {RELEASE_TYPE, FIRST_RELEASE, COMMIT_NAME, COMMIT_EMAIL};
|
@ -2,7 +2,7 @@ const url = require('url');
|
|||||||
const {inspect} = require('util');
|
const {inspect} = require('util');
|
||||||
const {toLower, isString} = require('lodash');
|
const {toLower, isString} = require('lodash');
|
||||||
const pkg = require('../../package.json');
|
const pkg = require('../../package.json');
|
||||||
const RELEASE_TYPE = require('./release-types');
|
const {RELEASE_TYPE} = require('./constants');
|
||||||
|
|
||||||
const homepage = url.format({...url.parse(pkg.homepage), ...{hash: null}});
|
const homepage = url.format({...url.parse(pkg.homepage), ...{hash: null}});
|
||||||
const stringify = obj => (isString(obj) ? obj : inspect(obj, {breakLength: Infinity, depth: 2, maxArrayLength: 5}));
|
const stringify = obj => (isString(obj) ? obj : inspect(obj, {breakLength: Infinity, depth: 2, maxArrayLength: 5}));
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
const {isString, isFunction, isArray, isPlainObject} = require('lodash');
|
const {isString, isFunction, isArray, isPlainObject} = require('lodash');
|
||||||
const RELEASE_TYPE = require('./release-types');
|
const {RELEASE_TYPE} = require('./constants');
|
||||||
|
|
||||||
const validatePluginConfig = conf => isString(conf) || isString(conf.path) || isFunction(conf);
|
const validatePluginConfig = conf => isString(conf) || isString(conf.path) || isFunction(conf);
|
||||||
|
|
||||||
|
@ -1 +0,0 @@
|
|||||||
module.exports = ['major', 'premajor', 'minor', 'preminor', 'patch', 'prepatch', 'prerelease'];
|
|
@ -1,4 +1,5 @@
|
|||||||
const semver = require('semver');
|
const semver = require('semver');
|
||||||
|
const {FIRST_RELEASE} = require('./definitions/constants');
|
||||||
|
|
||||||
module.exports = (type, lastRelease, logger) => {
|
module.exports = (type, lastRelease, logger) => {
|
||||||
let version;
|
let version;
|
||||||
@ -6,7 +7,7 @@ module.exports = (type, lastRelease, logger) => {
|
|||||||
version = semver.inc(lastRelease.version, type);
|
version = semver.inc(lastRelease.version, type);
|
||||||
logger.log('The next release version is %s', version);
|
logger.log('The next release version is %s', version);
|
||||||
} else {
|
} else {
|
||||||
version = '1.0.0';
|
version = FIRST_RELEASE;
|
||||||
logger.log('There is no previous release, the next release version is %s', version);
|
logger.log('There is no previous release, the next release version is %s', version);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import clearModule from 'clear-module';
|
|||||||
import AggregateError from 'aggregate-error';
|
import AggregateError from 'aggregate-error';
|
||||||
import SemanticReleaseError from '@semantic-release/error';
|
import SemanticReleaseError from '@semantic-release/error';
|
||||||
import DEFINITIONS from '../lib/definitions/plugins';
|
import DEFINITIONS from '../lib/definitions/plugins';
|
||||||
|
import {COMMIT_NAME, COMMIT_EMAIL} from '../lib/definitions/constants';
|
||||||
import {
|
import {
|
||||||
gitHead as getGitHead,
|
gitHead as getGitHead,
|
||||||
gitTagHead,
|
gitTagHead,
|
||||||
@ -157,6 +158,12 @@ test.serial('Plugins are called with expected values', async t => {
|
|||||||
// Verify the tag has been created on the local and remote repo and reference the gitHead
|
// Verify the tag has been created on the local and remote repo and reference the gitHead
|
||||||
t.is(await gitTagHead(nextRelease.gitTag), nextRelease.gitHead);
|
t.is(await gitTagHead(nextRelease.gitTag), nextRelease.gitHead);
|
||||||
t.is(await gitRemoteTagHead(repositoryUrl, nextRelease.gitTag), nextRelease.gitHead);
|
t.is(await gitRemoteTagHead(repositoryUrl, nextRelease.gitTag), nextRelease.gitHead);
|
||||||
|
|
||||||
|
// Verify the author/commiter name and email hve been set
|
||||||
|
t.is(process.env.GIT_AUTHOR_NAME, COMMIT_NAME);
|
||||||
|
t.is(process.env.GIT_AUTHOR_EMAIL, COMMIT_EMAIL);
|
||||||
|
t.is(process.env.GIT_COMMITTER_NAME, COMMIT_NAME);
|
||||||
|
t.is(process.env.GIT_COMMITTER_EMAIL, COMMIT_EMAIL);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.serial('Use custom tag format', async t => {
|
test.serial('Use custom tag format', async t => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user