-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'release/0.1.3' into production
- Loading branch information
Showing
10 changed files
with
202 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
var shell = require('shelljs'); | ||
var util = require('util'); | ||
|
||
function getCurrentBranch() { | ||
var output = shell.exec('git symbolic-ref --short HEAD', {silent: true}); | ||
if (output.code !== 0) { | ||
return Error('This directory does not contain a valid git repository'); | ||
} | ||
return output.output.trim(); | ||
} | ||
|
||
function isValidBranch(branchName) { | ||
var output = shell.exec( | ||
util.format('git rev-parse --abbrev-ref %s', branchName), | ||
{silent: true}); | ||
return output.code === 0; | ||
} | ||
|
||
function isValidGitURL(url) { | ||
var output = shell.exec( | ||
util.format('git ls-remote %s', url), | ||
{silent: true}); | ||
return output.code === 0; | ||
} | ||
|
||
function doGitPush(gitURL, branch, callback) { | ||
shell.exec( | ||
util.format('git push -f %s %s:%s', gitURL, branch, branch), | ||
callback); | ||
} | ||
|
||
function performGitDeployment(baseUrl, config, branch, callback) { | ||
var deployURL = baseUrl + '/' + config; | ||
|
||
if (!isValidBranch(branch)) { | ||
console.error('Branch `%s` is not available in this repository', branch); | ||
return callback(Error('invalid branch')); | ||
} | ||
|
||
if (!isValidGitURL(deployURL)) { | ||
console.error('URL `%s` is not valid', deployURL); | ||
return callback(Error('invalid url')); | ||
} | ||
|
||
doGitPush(deployURL, branch, callback); | ||
} | ||
|
||
exports.performGitDeployment = performGitDeployment; | ||
// for unit tests | ||
exports._getCurrentBranch = getCurrentBranch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
var fs = require('fs'); | ||
var http = require('http'); | ||
var path = require('path'); | ||
var url = require('url'); | ||
|
||
function performHttpPutDeployment(baseURL, config, npmPkg, callback) { | ||
npmPkg = path.resolve(npmPkg); | ||
|
||
var fileReader = fs.createReadStream(npmPkg); | ||
fileReader.on('error', function(err) { | ||
console.error('Error while reading file: %s', err); | ||
callback(err); | ||
}); | ||
|
||
var postURL = url.parse(baseURL); | ||
if (postURL.protocol !== 'http:') { | ||
console.error('Invalid URL `%s`. Only http:// URLs are supported.', | ||
baseURL | ||
); | ||
return callback(Error('Invalid URL')); | ||
} | ||
|
||
var postOptions = { | ||
auth: postURL.auth, | ||
hostname: postURL.hostname, | ||
port: postURL.port || 80, | ||
path: '/' + config, | ||
method: 'PUT' | ||
}; | ||
|
||
var req = http.request(postOptions, function(res) { | ||
if (res.statusCode === 200) { | ||
callback(); | ||
} | ||
console.error('Deploy `%s` to `%s` failed. HTTP Code: %d', | ||
npmPkg, | ||
baseURL, | ||
res.statusCode | ||
); | ||
callback(Error('HTTP error')); | ||
}); | ||
|
||
req.on('error', function(err) { | ||
console.error('Deploy `%s` to `%s` failed: %s', | ||
npmPkg, | ||
baseURL, | ||
err.message | ||
); | ||
callback(err); | ||
}); | ||
|
||
fileReader.pipe(req); | ||
} | ||
|
||
exports.performHttpPutDeployment = performHttpPutDeployment; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 5 additions & 6 deletions
11
test/test-deploy-current-branch.js → test/test-deploy-default-branch.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
var assert = require('assert'); | ||
var http = require('http'); | ||
var childProcess = require('child_process'); | ||
|
||
var ok = false; | ||
var server = http.createServer(function(req, res) { | ||
assert(req.url === '/repo2'); | ||
assert(req.method === 'PUT'); | ||
ok = true; | ||
|
||
res.end(); | ||
server.close(); | ||
}); | ||
server.listen(0); | ||
|
||
server.on('listening', function() { | ||
var port = server.address().port; | ||
childProcess.fork( | ||
require.resolve('../bin/sl-deploy'), | ||
['--config', 'repo2', 'http://127.0.0.1:' + port, __filename] | ||
); | ||
}); |
Oops, something went wrong.