Skip to content

Commit

Permalink
fix: Read the commit sha from the right directory
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Krems committed Dec 21, 2015
1 parent 0f1cb0a commit 05d9171
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 6 deletions.
56 changes: 56 additions & 0 deletions lib/run.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (c) 2015, Groupon, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of GROUPON nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
'use strict';

var childProcess = require('child_process');

var Bluebird = require('bluebird');
var debug = require('debug')('nlm:run');
var _ = require('lodash');

module.exports = function run(command, args, options) {
debug(command, args, _.omit(options, 'env'));
return new Bluebird(function resolveExec(resolve, reject) {
function onExecDone(error, stdout) {
if (error) return reject(error);
resolve(stdout);
}

var child = childProcess.execFile(command, args, options, onExecDone);
child.stdout.on('data', function forwardStdOut(chunk) {
debug('stdout', chunk.toString().trim());
});
child.stderr.on('data', function forwardStdErr(chunk) {
debug('stderr', chunk.toString().trim());
});
});
};
14 changes: 8 additions & 6 deletions lib/steps/version-commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,23 @@
*/
'use strict';

var childProcess = require('child_process');
var fs = require('fs');
var path = require('path');

var Bluebird = require('bluebird');
var _ = require('lodash');

var execFileAsync = Bluebird.promisify(childProcess.execFile);
var run = require('../run');

function addFiles(cwd) {
return execFileAsync('git', ['add', 'CHANGELOG.md', 'package.json'], { cwd: cwd });
return run('git', ['add', 'CHANGELOG.md', 'package.json'], { cwd: cwd });
}

function commit(cwd, message) {
return execFileAsync('git', ['commit', '-m', message], { cwd: cwd });
return run('git', ['commit', '-m', message], { cwd: cwd });
}

function getHEAD(cwd) {
return run('git', ['rev-parse', 'HEAD'], { cwd: cwd });
}

function createVersionCommit(cwd, pkg, options) {
Expand All @@ -68,7 +70,7 @@ function createVersionCommit(cwd, pkg, options) {

return addFiles(cwd)
.then(_.partial(commit, cwd, 'v' + pkg.version))
.then(_.partial(execFileAsync, 'git', ['rev-parse', 'HEAD']))
.then(_.partial(getHEAD, cwd))
.then(function setVersionCommitSha(output) {
options.versionCommitSha = output.trim();
return options.versionCommitSha;
Expand Down
61 changes: 61 additions & 0 deletions test/steps/version-commit.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2015, Groupon, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of GROUPON nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
'use strict';

var fs = require('fs');

var assert = require('assertive');

var createVersionCommit = require('../../lib/steps/version-commit');

var withFixture = require('../fixture');

describe('createVersionCommit', function () {
var dirname = withFixture('multiple-commits');
var pkg = {
name: 'some-package',
version: '0.0.0',
};
var options = {
nextVersion: '1.0.0',
changelog: '* New stuff\n* Interesting features',
};

before('create version commit', function () {
return createVersionCommit(dirname, pkg, options);
});

it('writes the correct HEAD sha', function () {
var HEAD = fs.readFileSync(dirname + '/.git/refs/heads/master', 'utf8');
assert.equal(HEAD.trim(), options.versionCommitSha);
});
});

0 comments on commit 05d9171

Please sign in to comment.