Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
version: Add new sign-git-commit config (#12697)
PR-URL: #12697
Credit: @tribou
Reviewed-By: @zkat
  • Loading branch information
tribou authored and zkat committed Jul 10, 2018
1 parent 244b183 commit 7984206e2f41b8d8361229cde88d68f0c96ed0b8
@@ -1034,6 +1034,17 @@ will also prevent _writing_ `npm-shrinkwrap.json` if `save` is true.

This option is an alias for `--package-lock`.

### sign-git-commit

* Default: false
* Type: Boolean

If set to true, then the `npm version` command will commit the new package
version using `-S` to add a signature.

Note that git requires you to have set up GPG keys in your git configs
for this to work properly.

### sign-git-tag

* Default: false
@@ -220,6 +220,7 @@ Object.defineProperty(exports, 'defaults', {get: function () {
'send-metrics': false,
shell: osenv.shell(),
shrinkwrap: true,
'sign-git-commit': false,
'sign-git-tag': false,
'sso-poll-frequency': 500,
'sso-type': 'oauth',
@@ -352,6 +353,7 @@ exports.types = {
'send-metrics': Boolean,
shell: String,
shrinkwrap: Boolean,
'sign-git-commit': Boolean,
'sign-git-tag': Boolean,
'sso-poll-frequency': Number,
'sso-type': [null, 'oauth', 'saml'],
@@ -294,9 +294,10 @@ function buildCommitArgs (args) {
function _commit (version, localData, cb) {
const options = { env: process.env }
const message = npm.config.get('message').replace(/%s/g, version)
const sign = npm.config.get('sign-git-tag')
const commitArgs = buildCommitArgs([ 'commit', '-m', message ])
const flagForTag = sign ? '-sm' : '-am'
const signTag = npm.config.get('sign-git-tag')
const signCommit = npm.config.get('sign-git-commit')
const commitArgs = buildCommitArgs([ 'commit', signCommit ? '-S -m' : '-m', message ])
const flagForTag = signTag ? '-sm' : '-am'

stagePackageFiles(localData, options).then(() => {
return git.exec(commitArgs, options)
@@ -16,7 +16,7 @@ var packagePath = path.resolve(pkg, 'package.json')

var json = { name: 'blah', version: '0.1.2' }

var configContents = 'sign-git-tag=false\nmessage=":bookmark: %s"\n'
var configContents = 'sign-git-commit=false\nsign-git-tag=false\nmessage=":bookmark: %s"\n'

test('npm version <semver> with message config', function (t) {
setup()
@@ -22,6 +22,7 @@ test('npm version from-git with a valid tag creates a new commit', function (t)

function runVersion (er) {
t.ifError(er, 'git tag ran without error')
npm.config.set('sign-git-commit', false)
npm.config.set('sign-git-tag', false)
npm.commands.version(['from-git'], checkVersion)
}
@@ -51,6 +52,7 @@ test('npm version from-git with a valid tag updates the package.json version', f

function runVersion (er) {
t.ifError(er, 'git tag ran without error')
npm.config.set('sign-git-commit', false)
npm.config.set('sign-git-tag', false)
npm.commands.version(['from-git'], checkManifest)
}
@@ -75,6 +77,7 @@ test('npm version from-git strips tag-version-prefix', function (t) {

function runVersion (er) {
t.ifError(er, 'git tag ran without error')
npm.config.set('sign-git-commit', false)
npm.config.set('sign-git-tag', false)
npm.config.set('tag-version-prefix', prefix)
npm.commands.version(['from-git'], checkVersion)
@@ -107,6 +110,7 @@ test('npm version from-git only strips tag-version-prefix if it is a prefix', fu

function runVersion (er) {
t.ifError(er, 'git tag ran without error')
npm.config.set('sign-git-commit', false)
npm.config.set('sign-git-tag', false)
npm.config.set('tag-version-prefix', prefix)
npm.commands.version(['from-git'], checkVersion)
@@ -137,6 +141,7 @@ test('npm version from-git with an existing version', function (t) {

function runVersion (er) {
t.ifError(er, 'git tag ran without error')
npm.config.set('sign-git-commit', false)
npm.config.set('sign-git-tag', false)
npm.commands.version(['from-git'], checkVersion)
}
@@ -154,6 +159,7 @@ test('npm version from-git with an invalid version tag', function (t) {

function runVersion (er) {
t.ifError(er, 'git tag ran without error')
npm.config.set('sign-git-commit', false)
npm.config.set('sign-git-tag', false)
npm.commands.version(['from-git'], checkVersion)
}
@@ -170,6 +176,7 @@ test('npm version from-git without any versions', function (t) {

function runVersion (er) {
t.ifError(er, 'created git repo without errors')
npm.config.set('sign-git-commit', false)
npm.config.set('sign-git-tag', false)
npm.commands.version(['from-git'], checkVersion)
}
@@ -59,6 +59,7 @@ test('npm version <semver> --force with working directory not clean', function (
common.npm(
[
'--force',
'--no-sign-git-commit',
'--no-sign-git-tag',
'--registry', common.registry,
'--prefix', pkg,
@@ -11,7 +11,7 @@ var npm = require('../../')
var pkg = path.resolve(__dirname, 'version-lifecycle')
var cache = path.resolve(pkg, 'cache')
var npmrc = path.resolve(pkg, './.npmrc')
var configContents = 'sign-git-tag=false\n'
var configContents = 'sign-git-commit=false\nsign-git-tag=false\n'

test('npm version <semver> with failing preversion lifecycle script', function (t) {
setup()
@@ -25,7 +25,12 @@ test('npm version <semver> with failing preversion lifecycle script', function (
}
}), 'utf8')
fs.writeFileSync(path.resolve(pkg, 'fail.js'), 'process.exit(50)', 'utf8')
npm.load({cache: cache, 'sign-git-tag': false, registry: common.registry}, function () {
npm.load({
cache: cache,
'sign-git-commit': false,
'sign-git-tag': false,
registry: common.registry
}, function () {
var version = require('../../lib/version')
version(['patch'], function (err) {
t.ok(err)
@@ -47,7 +52,12 @@ test('npm version <semver> with failing version lifecycle script', function (t)
}
}), 'utf8')
fs.writeFileSync(path.resolve(pkg, 'fail.js'), 'process.exit(50)', 'utf8')
npm.load({cache: cache, 'sign-git-tag': false, registry: common.registry}, function () {
npm.load({
cache: cache,
'sign-git-commit': false,
'sign-git-tag': false,
registry: common.registry
}, function () {
var version = require('../../lib/version')
version(['patch'], function (err) {
t.ok(err)
@@ -69,7 +79,12 @@ test('npm version <semver> with failing postversion lifecycle script', function
}
}), 'utf8')
fs.writeFileSync(path.resolve(pkg, 'fail.js'), 'process.exit(50)', 'utf8')
npm.load({cache: cache, 'sign-git-tag': false, registry: common.registry}, function () {
npm.load({
cache: cache,
'sign-git-commit': false,
'sign-git-tag': false,
registry: common.registry
}, function () {
var version = require('../../lib/version')
version(['patch'], function (err) {
t.ok(err)
@@ -95,7 +110,12 @@ test('npm version <semver> execution order', function (t) {
makeScript('preversion')
makeScript('version')
makeScript('postversion')
npm.load({cache: cache, 'sign-git-tag': false, registry: common.registry}, function () {
npm.load({
cache: cache,
'sign-git-commit': false,
'sign-git-tag': false,
registry: common.registry
}, function () {
common.makeGitRepo({path: pkg}, function (err, git) {
t.ifError(err, 'git bootstrap ran without error')

@@ -16,7 +16,7 @@ var packagePath = path.resolve(pkg, 'package.json')

var json = { name: 'blah', version: '0.1.2' }

var configContents = 'sign-git-tag=false\nmessage=":bookmark: %s"\n'
var configContents = 'sign-git-commit=false\nsign-git-tag=false\nmessage=":bookmark: %s"\n'

test('npm version <semver> with message config', function (t) {
setup()
@@ -32,6 +32,7 @@ test('npm version <semver> from a subdirectory', function (t) {
function version (er, stdout, stderr) {
t.ifError(er, 'git repo initialized without issue')
t.notOk(stderr, 'no error output')
npm.config.set('sign-git-commit', false)
npm.config.set('sign-git-tag', false)
npm.commands.version(['patch'], checkVersion)
}
@@ -28,6 +28,7 @@ test('npm version <semver> updates git works with no shrinkwrap', function (t) {
setup()
rimraf.sync(path.resolve(pkg, 'npm-shrinkwrap.json'))

npm.config.set('sign-git-commit', false)
npm.config.set('sign-git-tag', false)

common.makeGitRepo({
@@ -70,6 +71,7 @@ test('npm version <semver> updates git works with no shrinkwrap', function (t) {
test('npm version <semver> updates shrinkwrap and updates git', function (t) {
setup()

npm.config.set('sign-git-commit', false)
npm.config.set('sign-git-tag', false)

common.makeGitRepo({

0 comments on commit 7984206

Please sign in to comment.