vigour-sentinel
Advanced tools
Comparing version 0.1.1 to 0.2.0
{ | ||
"name": "vigour-sentinel", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Continuos Testing & Delivery Agent for vigour projects", | ||
"preferGlobal": "true", | ||
"main": "lib/index.js", | ||
"main": "src/index.js", | ||
"bin": { | ||
@@ -17,3 +17,3 @@ "sentinel": "bin/sentinel" | ||
}, | ||
"author": "Danillo Corvalan", | ||
"author": "dev@vigour.io", | ||
"license": "ISC", | ||
@@ -25,7 +25,7 @@ "bugs": { | ||
"dependencies": { | ||
"axios": "^0.5.4", | ||
"command-promise": "^2.0.0", | ||
"fs-promise": "^0.3.1", | ||
"stream-to-promise": "^1.0.4" | ||
"axios": "^0.7.0", | ||
"npmlog": "^2.0.0", | ||
"shelljs": "^0.5.3", | ||
"vigour-fs-promised": "^2.0.1" | ||
} | ||
} |
190
src/index.js
"use strict"; | ||
var fs = require('fs-promise') | ||
var command = require('command-promise') | ||
var startProcess = require('command-promise/Process') | ||
var drain = require('stream-to-promise'); | ||
var sendToSlack = require('./integration/slack'); | ||
var config = require('./config') | ||
var repo = config.repo | ||
var buildId = config.buildId | ||
var commit = config.commit | ||
var branch = config.branch | ||
var dir = config.dir | ||
var slackUrl = config.slack.url | ||
var packageJson = require(`${dir}/package.json`); | ||
var log = require('npmlog') | ||
var path = require('path') | ||
var fs = require('vigour-fs-promised') | ||
var exec = require('./utils/exec') | ||
module.exports.ci = function ci() { | ||
let config = packageJson && packageJson.vigour && packageJson.vigour.services && packageJson.vigour.services.sentinel; | ||
let branches = ((config && config.branches) || ['production', 'staging']); | ||
let hasRunTests = false; | ||
var slack = require('./integration/slack') | ||
var github = require('./integration/github') | ||
console.log(`Sentinel: Running test`); | ||
var Sentinel = module.exports = { | ||
init: function(config){ | ||
var pkg = config.pkg = require(path.join(config.dir,'package.json')) | ||
config.sentinel = {} | ||
if(pkg && pkg.vigour && pkg.vigour.services && pkg.vigour.services.sentinel){ | ||
config.sentinel = pkg.vigour.services.sentinel | ||
} | ||
this.config = config | ||
slack.init(config) | ||
github.init(config) | ||
this.cli() | ||
}, | ||
cli: function(){ | ||
var config = Sentinel.config | ||
var failedTests | ||
var test = startProcess(packageJson.scripts.test); | ||
test.pipe(process.stdout); | ||
return drain(test) | ||
.then(() => { | ||
hasRunTests = true; | ||
if (branches.indexOf(branch) === -1) { | ||
notifySuccess(); | ||
return; | ||
} | ||
let branchName = `${branch}-dist`; | ||
let remote = config.remote || 'origin'; | ||
console.log(`Sentinel: Changing git config to fetch all branches`); | ||
return command(`git`, ['config', `remote.${remote}.fetch`, '+refs/heads/*:refs/remotes/origin/*']) | ||
.then(() => { | ||
console.log(`Sentinel: Cleanning git`); | ||
return command(`git clean -df`) | ||
.then(() => { | ||
return command(`git checkout -- .`); | ||
}); | ||
}) | ||
.then(() => { | ||
console.log(`Sentinel: Fetching ${remote} ${branchName}`); | ||
return command(`git fetch ${remote} ${branchName}`) | ||
.then( | ||
() => { | ||
console.log(`Sentinel: Checking out local branch ${branchName}`); | ||
return command(`git checkout ${branchName}`); | ||
}, | ||
() => { | ||
console.log(`Sentinel: Creating local branch ${branchName} and checking out`); | ||
return command(`git checkout -b ${branchName}`); | ||
} | ||
); | ||
}) | ||
.then(() => { | ||
console.log(`Sentinel: Merge ${branch} into ${branchName}`); | ||
return command(`git merge ${branch}`); | ||
}) | ||
.then(() => { | ||
console.log('Sentinel: Unignoring patterns'); | ||
let patterns = config.unignore && config.unignore.length ? config.unignore : ['build']; | ||
return removeIgnorablePatterns(patterns); | ||
}) | ||
.then(() => { | ||
console.log('Sentinel: Building'); | ||
return command('npm run build'); | ||
}) | ||
.then(() => { | ||
console.log(`Sentinel: Adding changed files`); | ||
return command(`git add .`); | ||
}) | ||
.then(() => { | ||
return command(`git status -s`) | ||
.then((res) => { | ||
let output = res[0]; | ||
//if there are changes | ||
if (output) { | ||
let commitMessage = `${Date.now()} commit #${commit}`; | ||
console.log(`Sentinel: Commiting: ${commitMessage}`); | ||
return command(`git commit -m "${commitMessage}"`) | ||
.then(() => { | ||
console.log(`Sentinel: Pushing to ${remote} ${branchName}`); | ||
return command(`git push ${remote} ${branchName}`); | ||
}); | ||
} else { | ||
console.log('Sentinel: No changes detected'); | ||
} | ||
}); | ||
}) | ||
.then(() => { | ||
notifySuccess(); | ||
}); | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
if (!hasRunTests) { | ||
notifyTestsFail(err); | ||
} else { | ||
notifyFail(err); | ||
} | ||
}); | ||
exec(/*config.pkg.scripts.test*/'pwd', true, true) | ||
.then((code) => { | ||
failedTests = code | ||
return ~config.sentinel.branches.indexOf(config.branch) | ||
}) | ||
.then((treatBranch) => { | ||
if(treatBranch){ | ||
return github.makeDistribution() | ||
} | ||
}) | ||
// .then((buildSuccess) => slack.notify(failedTests, /*buildSuccess*/ true)) | ||
.catch((err) => { | ||
log.error('Sentinel', 'err', err) | ||
process.exit(1) | ||
}) | ||
} | ||
} | ||
function removeIgnorablePatterns (patterns) { | ||
let gitignorePath = `${dir}/.gitignore`; | ||
return fs.readFile(gitignorePath) | ||
.then((data) => { | ||
let result = data.toString(); | ||
patterns.forEach((item) => { | ||
let reg = new RegExp(`\n${item}\n`); | ||
result = result.replace(reg, '\n'); | ||
}); | ||
return fs.writeFile(gitignorePath, result, 'utf8'); | ||
}); | ||
} | ||
var notifySuccess = module.exports.notifySuccess = function () { | ||
console.log('Sentinel: Notifying Success'); | ||
sendToSlack('good', 'Build Succeeded'); | ||
} | ||
var notifyFail = module.exports.notifyFail = function (err) { | ||
console.log('Sentinel: Notifying Failed'); | ||
sendToSlack('danger', 'Build Failed') | ||
.then(() => { | ||
exitError(err); | ||
}); | ||
} | ||
var notifyTestsFail = module.exports.notifyTestsFail = function (err) { | ||
console.log('Sentinel: Notifying Tests Failed'); | ||
sendToSlack('danger', 'Tests Failed', err.code) | ||
.then(() => { | ||
exitError(err); | ||
}); | ||
} | ||
function exitError (err) { | ||
console.log('Sentinel: Exiting with Error: ', err && err.code); | ||
process.exit(err && err.code ? err.code : 1); | ||
} |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
13971
12
229
1
2
+ Addednpmlog@^2.0.0
+ Addedshelljs@^0.5.3
+ Addedvigour-fs-promised@^2.0.1
+ Addedansi@0.3.1(transitive)
+ Addedare-we-there-yet@1.1.7(transitive)
+ Addedaxios@0.7.0(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbluebird@3.7.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedbuffer-from@1.1.2(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedconcat-stream@1.6.2(transitive)
+ Addedcore-util-is@1.0.3(transitive)
+ Addedcpr@1.1.2(transitive)
+ Addeddelegates@1.0.0(transitive)
+ Addedeventemitter3@1.2.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedgauge@1.2.7(transitive)
+ Addedglob@6.0.47.2.3(transitive)
+ Addedgraceful-fs@4.1.154.2.11(transitive)
+ Addedhas-unicode@2.0.1(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedlodash.pad@4.5.1(transitive)
+ Addedlodash.padend@4.6.1(transitive)
+ Addedlodash.padstart@4.6.1(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminimist@1.2.8(transitive)
+ Addedmkdirp@0.5.6(transitive)
+ Addednpmlog@2.0.4(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedos-tmpdir@1.0.2(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedprepend-file@1.3.1(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedrimraf@2.4.52.7.1(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedsax@1.4.1(transitive)
+ Addedshelljs@0.5.3(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedthrough2@2.0.5(transitive)
+ Addedtmp@0.0.31(transitive)
+ Addedtypedarray@0.0.6(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedvigour-fs@3.0.6(transitive)
+ Addedvigour-fs-promised@2.0.2(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedxml2js@0.4.23(transitive)
+ Addedxmlbuilder@11.0.1(transitive)
+ Addedxtend@4.0.2(transitive)
- Removedcommand-promise@^2.0.0
- Removedfs-promise@^0.3.1
- Removedstream-to-promise@^1.0.4
- Removedany-promise@0.1.01.3.0(transitive)
- Removedasap@1.0.0(transitive)
- Removedaxios@0.5.4(transitive)
- Removedbluebird@2.11.03.0.6(transitive)
- Removedcommand-promise@2.0.1(transitive)
- Removedduplexer@0.1.2(transitive)
- Removedes6-promise@2.3.0(transitive)
- Removedfs-promise@0.3.1(transitive)
- Removedlodash._baseassign@3.2.0(transitive)
- Removedlodash._basecopy@3.0.1(transitive)
- Removedlodash._baseflatten@3.1.4(transitive)
- Removedlodash._basefor@3.0.3(transitive)
- Removedlodash._bindcallback@3.0.1(transitive)
- Removedlodash._createassigner@3.1.1(transitive)
- Removedlodash._getnative@3.9.1(transitive)
- Removedlodash._isiterateecall@3.0.9(transitive)
- Removedlodash.assign@3.2.0(transitive)
- Removedlodash.flattendeep@3.0.2(transitive)
- Removedlodash.isarguments@3.1.0(transitive)
- Removedlodash.isarray@3.0.4(transitive)
- Removedlodash.isplainobject@3.2.0(transitive)
- Removedlodash.keys@3.1.2(transitive)
- Removedlodash.keysin@3.0.8(transitive)
- Removedlodash.restparam@3.6.1(transitive)
- Removedpromise@6.1.0(transitive)
- Removedq@1.5.1(transitive)
- Removedstream-to-array@2.3.0(transitive)
- Removedstream-to-promise@1.1.1(transitive)
Updatedaxios@^0.7.0