mirror of
https://gitlab.silvrtree.co.uk/martind2000/nci.git
synced 2025-02-10 17:59:16 +00:00
introduce build with scm changes only feature
This commit is contained in:
parent
efacf539cc
commit
a8d3056eb6
@ -42,8 +42,9 @@ exports.register = function(app) {
|
||||
logger.log('Run "' + projectName + '"');
|
||||
distributor.run({
|
||||
projectName: projectName,
|
||||
withScmChangesOnly: body.withScmChangesOnly,
|
||||
initiator: {type: 'httpApi'}
|
||||
}, _.noop);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -216,6 +216,22 @@ Distributor.prototype.run = function(params, callback) {
|
||||
Steppy(
|
||||
function() {
|
||||
project = _(self.projects).findWhere({name: params.projectName});
|
||||
|
||||
if (params.withScmChangesOnly) {
|
||||
self.nodes[0].hasScmChanges(project, this.slot());
|
||||
} else {
|
||||
this.pass(null);
|
||||
}
|
||||
},
|
||||
function(err, hasScmChanges) {
|
||||
if (params.withScmChangesOnly && !hasScmChanges) {
|
||||
logger.log(
|
||||
'Building of "%s" skipped coz no scm changes',
|
||||
project.name
|
||||
);
|
||||
return callback();
|
||||
}
|
||||
|
||||
self._updateBuild({}, {
|
||||
project: project,
|
||||
initiator: params.initiator,
|
||||
|
@ -26,6 +26,11 @@ Executor.prototype._runStep = function(params, callback) {
|
||||
|
||||
};
|
||||
|
||||
// Does current project scm has new changes to build
|
||||
Executor.prototype.hasScmChanges = function(callback) {
|
||||
|
||||
};
|
||||
|
||||
Executor.prototype.run = function(params, callback) {
|
||||
var self = this,
|
||||
project = _({}).extend(self.project, params);
|
||||
|
@ -20,7 +20,7 @@ Executor.prototype._createScm = function(params) {
|
||||
return createScm(params);
|
||||
};
|
||||
|
||||
Executor.prototype._getSources = function(params, callback) {
|
||||
Executor.prototype._getChanges = function(params, callback) {
|
||||
var self = this,
|
||||
scm, isFirstRun, oldRev;
|
||||
Steppy(
|
||||
@ -65,8 +65,34 @@ Executor.prototype._getSources = function(params, callback) {
|
||||
},
|
||||
function(err, changes) {
|
||||
var target = self._getTarget(params.rev, changes);
|
||||
this.pass(target.changes);
|
||||
scm.update(target.rev, this.slot());
|
||||
this.pass({
|
||||
scm: scm,
|
||||
oldRev: oldRev,
|
||||
rev: target.rev,
|
||||
changes: target.changes
|
||||
});
|
||||
},
|
||||
callback
|
||||
);
|
||||
};
|
||||
|
||||
Executor.prototype.hasScmChanges = function(callback) {
|
||||
this._getChanges(this.project.scm, function(err, data) {
|
||||
callback(err, !err && data.changes.length > 0);
|
||||
});
|
||||
};
|
||||
|
||||
Executor.prototype._getSources = function(params, callback) {
|
||||
var self = this,
|
||||
scm;
|
||||
Steppy(
|
||||
function() {
|
||||
self._getChanges(params, this.slot());
|
||||
},
|
||||
function(err, data) {
|
||||
scm = data.scm;
|
||||
this.pass(data.changes);
|
||||
scm.update(data.rev, this.slot());
|
||||
},
|
||||
function(err, changes) {
|
||||
scm.getCurrent(this.slot());
|
||||
|
@ -83,6 +83,10 @@ Node.prototype._createExecutor = function(project) {
|
||||
});
|
||||
};
|
||||
|
||||
Node.prototype.hasScmChanges = function(project, callback) {
|
||||
this._createExecutor(project).hasScmChanges(callback);
|
||||
};
|
||||
|
||||
Node.prototype.run = function(project, params, callback) {
|
||||
var self = this;
|
||||
|
||||
|
@ -46,10 +46,7 @@ var expect = require('expect.js'),
|
||||
});
|
||||
|
||||
it('should run without errors', function(done) {
|
||||
executor.run({}, function(err) {
|
||||
expect(err).not.ok();
|
||||
done();
|
||||
});
|
||||
executor.run({}, done);
|
||||
executor.on('scmData', function(data) {
|
||||
scmData = data;
|
||||
});
|
||||
@ -67,6 +64,18 @@ var expect = require('expect.js'),
|
||||
);
|
||||
});
|
||||
|
||||
var itHasScmChanges = function(value) {
|
||||
it((value ? 'should' : 'should`t') + ' has scm changes',
|
||||
function(done) {
|
||||
executor.hasScmChanges(function(err, hasScmChanges) {
|
||||
if (err) return done(err);
|
||||
expect(hasScmChanges).equal(value);
|
||||
done();
|
||||
});
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
_(['first revision', /^first revision$/]).each(function(comment) {
|
||||
|
||||
describe('with scm rev default and catch rev ' + comment, function() {
|
||||
@ -99,6 +108,8 @@ var expect = require('expect.js'),
|
||||
});
|
||||
});
|
||||
|
||||
itHasScmChanges(true);
|
||||
|
||||
it('should run it again without errors', function(done) {
|
||||
executor.run({}, done);
|
||||
});
|
||||
@ -113,6 +124,8 @@ var expect = require('expect.js'),
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
itHasScmChanges(false);
|
||||
});
|
||||
|
||||
});
|
||||
@ -140,6 +153,8 @@ var expect = require('expect.js'),
|
||||
});
|
||||
});
|
||||
|
||||
itHasScmChanges(true);
|
||||
|
||||
it('scm data should be rev: 2, changes: [0, 2], not latest',
|
||||
function() {
|
||||
expect(scmData).eql({
|
||||
@ -164,6 +179,8 @@ var expect = require('expect.js'),
|
||||
}
|
||||
);
|
||||
|
||||
itHasScmChanges(false);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user