Skip to content

Commit

Permalink
feat: add --sign flag to sign git commit and tag (conventional-change…
Browse files Browse the repository at this point in the history
…log#29)

* feat(cli): add tag signing option (--sign-tag and its alias -s)

By default, a tag is not signed (git tag -a).
The option `--sign-tag` enables tag signing (git tag -s).

* feat: add --sign flag to sign git commit and tag
  • Loading branch information
nexdrew authored and bcoe committed May 1, 2016
1 parent 3f51e94 commit de758bc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
17 changes: 15 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ var argv = require('yargs')
default: false,
global: true
})
.option('sign', {
alias: 's',
describe: 'Should the git commit and tag be signed?',
type: 'boolean',
default: false,
global: true
})
.help()
.alias('help', 'h')
.example('$0', 'Update changelog and tag release')
Expand Down Expand Up @@ -106,7 +113,7 @@ function commit (argv, newVersion, cb) {
args.unshift('package.json')
}
checkpoint(msg, args)
exec('git add package.json ' + argv.infile + ';git commit package.json ' + argv.infile + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', function (err, stdout, stderr) {
exec('git add package.json ' + argv.infile + ';git commit ' + (argv.sign ? '-S ' : '') + 'package.json ' + argv.infile + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', function (err, stdout, stderr) {
var errMessage = null
if (err) errMessage = err.message
if (stderr) errMessage = stderr
Expand All @@ -123,8 +130,14 @@ function formatCommitMessage (msg, newVersion) {
}

function tag (newVersion, argv) {
var tagOption
if (argv.sign) {
tagOption = '-s '
} else {
tagOption = '-a '
}
checkpoint('tagging release %s', [newVersion])
exec('git tag -a v' + newVersion + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', function (err, stdout, stderr) {
exec('git tag ' + tagOption + 'v' + newVersion + ' -m "' + formatCommitMessage(argv.message, newVersion) + '"', function (err, stdout, stderr) {
var errMessage = null
if (err) errMessage = err.message
if (stderr) errMessage = stderr
Expand Down
14 changes: 14 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ describe('cli', function () {
})
})

it('respects the --sign option', function () {
fs.writeFileSync('package.json', JSON.stringify({
version: '1.0.0'
}), 'utf-8')

commit('feat: first commit')

// this should fail without a GPG key
var result = shell.exec(cliPath + ' --sign')
result.code.should.equal(1)
result.stdout.should.match(/gpg\: signing failed\: secret key not available/)
result.stdout.should.match(/error\: gpg failed to sign the data/)
})

it('handles commit messages longer than 80 characters', function () {
fs.writeFileSync('package.json', JSON.stringify({
version: '1.0.0'
Expand Down

0 comments on commit de758bc

Please sign in to comment.