Skip to content

Commit

Permalink
Trigger binary creation when tags are created manually (#259)
Browse files Browse the repository at this point in the history
Trigger binary creation when tags are created manually
  • Loading branch information
S Aruna committed Jul 11, 2018
1 parent 7594aac commit 294da6f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bin/watchbot-binary-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const getTagForSha = async (sha) => {
data.forEach((ref) => {
ref = ref.split('\t');
if (ref[0] !== sha) return;
const tagRegex = /refs\/tags\/(v[0-9.-]+)(\^\{(.*)\})*/;
const tagRegex = /refs\/tags\/(v?[0-9.-]+)(\^\{(.*)\})*/;
return resolve(tagRegex.exec(ref[1])[1]);
});
return resolve(null);
Expand Down
52 changes: 51 additions & 1 deletion test/bin.watchbot-binary-generator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ test('getTagForSha: commit not found', async (assert) => {
assert.end();
});

test('uploadBundle: tag found', async (assert) => {
test('uploadBundle: tag found (Tag created using `npm version <patch|minor|major>`)', async (assert) => {
process.env.CODEBUILD_RESOLVED_SOURCE_VERSION = 'f4815eb9f3bcfba88930bbe12d0888254af7cfa6';

// stubs and spies
Expand Down Expand Up @@ -83,6 +83,56 @@ test('uploadBundle: tag found', async (assert) => {
assert.end();
});


test('uploadBundle: tag found (Tag created manually)', async (assert) => {
process.env.CODEBUILD_RESOLVED_SOURCE_VERSION = 'f4815eb9f3bcfba88930bbe12d0888254af7cfa6';

// stubs and spies
const execStub = sinon.stub(wbg, 'exec').callsFake(() => {
return Promise.resolve({ stdout: 'f4815eb9f3bcfba88930bbe12d0888254af7cfa6\t/refs/tags/4.1.1' });
});
const fsCreateReadStreamStub = sinon.stub(fs, 'createReadStream').callsFake((file) => file);
const s3Stub = AWS.stub('S3', 'putObject', function () {
this.request.promise.returns(Promise.resolve());
});
const log = sinon.spy(console, 'log');

await wbg.uploadBundle();

assert.ok(execStub.calledWith('npm ci --production'));
assert.ok(execStub.calledWith('npm install -g pkg'));
assert.ok(execStub.calledWith('pkg .'));
assert.ok(execStub.calledWith('git ls-remote --tags https://github.com/mapbox/ecs-watchbot'));

assert.ok(s3Stub.calledWith({
Bucket: 'watchbot-binaries',
Key: 'linux/4.1.1/watchbot',
Body: fs.createReadStream('watchbot-linux'),
ACL: 'public-read'
}));
assert.ok(s3Stub.calledWith({
Bucket: 'watchbot-binaries',
Key: 'macosx/4.1.1/watchbot',
Body: fs.createReadStream('watchbot-macos'),
ACL: 'public-read'
}));
assert.ok(s3Stub.calledWith({
Bucket: 'watchbot-binaries',
Key: 'windows/4.1.1/watchbot',
Body: fs.createReadStream('watchbot-win.exe'),
ACL: 'public-read'
}));
assert.ok(log.calledWith('Uploading the package to s3://watchbot-binaries/linux/4.1.1/watchbot'));
assert.ok(log.calledWith('Uploading the package to s3://watchbot-binaries/macosx/4.1.1/watchbot'));
assert.ok(log.calledWith('Uploading the package to s3://watchbot-binaries/windows/4.1.1/watchbot'));

fsCreateReadStreamStub.restore();
log.restore();
execStub.restore();
s3Stub.restore();
assert.end();
});

test('uploadBundle: tag not found', async (assert) => {
process.env.CODEBUILD_RESOLVED_SOURCE_VERSION = '123456';

Expand Down

0 comments on commit 294da6f

Please sign in to comment.