mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-01-26 23:16:18 +00:00
Merge branch 'master' of github.com:okv/nci
This commit is contained in:
commit
e7b886c01c
58
app.js
58
app.js
@ -9,7 +9,8 @@ var http = require('http'),
|
|||||||
_ = require('underscore'),
|
_ = require('underscore'),
|
||||||
reader = require('./lib/reader'),
|
reader = require('./lib/reader'),
|
||||||
notifier = require('./lib/notifier'),
|
notifier = require('./lib/notifier'),
|
||||||
project = require('./lib/project');
|
project = require('./lib/project'),
|
||||||
|
chokidar = require('chokidar');
|
||||||
|
|
||||||
var staticServer = new nodeStatic.Server('./static');
|
var staticServer = new nodeStatic.Server('./static');
|
||||||
var server = http.createServer(function(req, res, next) {
|
var server = http.createServer(function(req, res, next) {
|
||||||
@ -73,11 +74,64 @@ Steppy(
|
|||||||
notifier.init(app.config.notify, this.slot());
|
notifier.init(app.config.notify, this.slot());
|
||||||
},
|
},
|
||||||
function() {
|
function() {
|
||||||
|
// load all projects for the first time
|
||||||
project.loadAll(app.config.paths.projects, this.slot());
|
project.loadAll(app.config.paths.projects, this.slot());
|
||||||
},
|
},
|
||||||
function(err, projects) {
|
function(err, projects) {
|
||||||
|
// note that `app.projects` is live variable
|
||||||
app.projects = projects;
|
app.projects = projects;
|
||||||
console.log('Loaded projects: ', _(projects).pluck('name'));
|
console.log('Loaded projects: ', _(app.projects).pluck('name'));
|
||||||
|
|
||||||
|
// start file watcher for reloading projects on change
|
||||||
|
var syncProject = function(filename, fileInfo) {
|
||||||
|
var baseDir = app.config.paths.projects,
|
||||||
|
projectName = path.relative(
|
||||||
|
baseDir,
|
||||||
|
path.dirname(filename)
|
||||||
|
);
|
||||||
|
|
||||||
|
var projectIndex = _(app.projects).findIndex(function(project) {
|
||||||
|
return project.name === projectName;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (projectIndex !== -1) {
|
||||||
|
console.log('Unload project: "' + projectName + '"');
|
||||||
|
app.projects.splice(projectIndex, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// on add or change (info is falsy on unlink)
|
||||||
|
if (fileInfo) {
|
||||||
|
console.log('Load project "' + projectName + '" on change');
|
||||||
|
project.load(baseDir, projectName, function(err, project) {
|
||||||
|
if (err) {
|
||||||
|
return console.error(
|
||||||
|
'Error during load project "' + projectName + '": ',
|
||||||
|
err.stack || err
|
||||||
|
);
|
||||||
|
}
|
||||||
|
app.projects.push(project);
|
||||||
|
console.log(
|
||||||
|
'Project "' + projectName + '" loaded:',
|
||||||
|
JSON.stringify(project, null, 4)
|
||||||
|
);
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// NOTE: currently after add remove and then add same file events will
|
||||||
|
// not be emitted
|
||||||
|
var watcher = chokidar.watch(
|
||||||
|
path.join(app.config.paths.projects, '*', 'config.*'),
|
||||||
|
{ignoreInitial: true}
|
||||||
|
);
|
||||||
|
watcher.on('add', syncProject);
|
||||||
|
watcher.on('change', syncProject);
|
||||||
|
watcher.on('unlink', syncProject);
|
||||||
|
|
||||||
|
watcher.on('error', function(err) {
|
||||||
|
console.error('File watcher error occurred: ', err.stack || err);
|
||||||
|
});
|
||||||
|
|
||||||
// init resources
|
// init resources
|
||||||
require('./resources')(app);
|
require('./resources')(app);
|
||||||
|
@ -30,7 +30,7 @@ gulp.task('develop', function() {
|
|||||||
return nodemon({
|
return nodemon({
|
||||||
ignore: ['static/**/*.js', 'app/**/*.js', 'node_modules/**'],
|
ignore: ['static/**/*.js', 'app/**/*.js', 'node_modules/**'],
|
||||||
script: 'app.js',
|
script: 'app.js',
|
||||||
ext: 'js,json,yaml'
|
ext: 'js'
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ function Distributor(params) {
|
|||||||
callback(null, build);
|
callback(null, build);
|
||||||
};
|
};
|
||||||
|
|
||||||
self.projectsHash = _(params.projects).indexBy('name');
|
self.projects = params.projects;
|
||||||
}
|
}
|
||||||
|
|
||||||
inherits(Distributor, EventEmitter);
|
inherits(Distributor, EventEmitter);
|
||||||
@ -106,7 +106,13 @@ Distributor.prototype._onBuildComplete = function(err, build, callback) {
|
|||||||
_(after).each(function(item) {
|
_(after).each(function(item) {
|
||||||
if (!item.status || item.status === build.status) {
|
if (!item.status || item.status === build.status) {
|
||||||
self.run({
|
self.run({
|
||||||
projectName: item.project
|
projectName: item.project,
|
||||||
|
initiator: {
|
||||||
|
type: 'build',
|
||||||
|
id: build.id,
|
||||||
|
number: build.number,
|
||||||
|
project: {name: build.project.name}
|
||||||
|
},
|
||||||
}, triggerAfterGroup.slot());
|
}, triggerAfterGroup.slot());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -163,9 +169,10 @@ Distributor.prototype.run = function(params, callback) {
|
|||||||
project;
|
project;
|
||||||
Steppy(
|
Steppy(
|
||||||
function() {
|
function() {
|
||||||
project = self.projectsHash[params.projectName];
|
project = _(self.projects).findWhere({name: params.projectName});
|
||||||
self._updateBuild({}, {
|
self._updateBuild({}, {
|
||||||
project: project,
|
project: project,
|
||||||
|
initiator: params.initiator,
|
||||||
params: params.params,
|
params: params.params,
|
||||||
createDate: Date.now(),
|
createDate: Date.now(),
|
||||||
status: 'queued',
|
status: 'queued',
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var inherits = require('util').inherits,
|
var Steppy = require('twostep').Steppy,
|
||||||
|
inherits = require('util').inherits,
|
||||||
ParentReader = require('./base').Reader,
|
ParentReader = require('./base').Reader,
|
||||||
path = require('path');
|
path = require('path'),
|
||||||
|
fs = require('fs');
|
||||||
|
|
||||||
|
|
||||||
function Reader() {
|
function Reader() {
|
||||||
@ -16,6 +18,14 @@ exports.Reader = Reader;
|
|||||||
Reader.prototype.ext = 'json';
|
Reader.prototype.ext = 'json';
|
||||||
|
|
||||||
Reader.prototype._load = function(dir, name, callback) {
|
Reader.prototype._load = function(dir, name, callback) {
|
||||||
var content = require(path.join(dir, name + '.' + this.ext));
|
var self = this;
|
||||||
callback(null, content);
|
Steppy(
|
||||||
|
function() {
|
||||||
|
fs.readFile(path.join(dir, name + '.' + self.ext), 'utf8', this.slot())
|
||||||
|
},
|
||||||
|
function(err, content) {
|
||||||
|
this.pass(JSON.parse(content));
|
||||||
|
},
|
||||||
|
callback
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/okv/nci",
|
"homepage": "https://github.com/okv/nci",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"chokidar": "1.0.3",
|
||||||
"data.io": "0.3.0",
|
"data.io": "0.3.0",
|
||||||
"jade": "1.9.2",
|
"jade": "1.9.2",
|
||||||
"js-yaml": "3.3.1",
|
"js-yaml": "3.3.1",
|
||||||
|
@ -110,7 +110,10 @@ module.exports = function(app) {
|
|||||||
resource.use('run', function(req, res) {
|
resource.use('run', function(req, res) {
|
||||||
var projectName = req.data.projectName;
|
var projectName = req.data.projectName;
|
||||||
console.log('Run the project: %s', projectName);
|
console.log('Run the project: %s', projectName);
|
||||||
distributor.run({projectName: projectName}, function(err, build) {
|
distributor.run({
|
||||||
|
projectName: projectName,
|
||||||
|
initiator: {type: 'user'}
|
||||||
|
}, function(err, build) {
|
||||||
console.log('>>> err, build = ', err && err.stack || err, build);
|
console.log('>>> err, build = ', err && err.stack || err, build);
|
||||||
});
|
});
|
||||||
res.send();
|
res.send();
|
||||||
|
@ -1,8 +1,19 @@
|
|||||||
if this.state.build
|
if this.state.build
|
||||||
h2
|
h2
|
||||||
span Build #
|
span= this.state.build.project.name
|
||||||
|
span build #
|
||||||
span= this.state.build.number
|
span= this.state.build.number
|
||||||
|
|
||||||
|
div
|
||||||
|
| Initiated by
|
||||||
|
- var initiator = this.state.build.initiator;
|
||||||
|
if initiator.type === 'user'
|
||||||
|
span user
|
||||||
|
else if initiator.type === 'build'
|
||||||
|
span= initiator.project.name
|
||||||
|
span build #
|
||||||
|
span= initiator.number
|
||||||
|
|
||||||
if this.state.build.startDate
|
if this.state.build.startDate
|
||||||
div
|
div
|
||||||
| Started at
|
| Started at
|
||||||
|
@ -62,7 +62,8 @@ describe('Distributor', function() {
|
|||||||
it('build should be queued', function() {
|
it('build should be queued', function() {
|
||||||
var changes = updateBuildSpy.getCall(0).args[1];
|
var changes = updateBuildSpy.getCall(0).args[1];
|
||||||
expect(changes).only.have.keys(
|
expect(changes).only.have.keys(
|
||||||
'project', 'params', 'createDate', 'status', 'completed'
|
'project', 'initiator', 'params', 'createDate', 'status',
|
||||||
|
'completed'
|
||||||
);
|
);
|
||||||
expect(changes.status).equal('queued');
|
expect(changes.status).equal('queued');
|
||||||
expect(changes.completed).equal(false);
|
expect(changes.completed).equal(false);
|
||||||
|
Loading…
Reference in New Issue
Block a user