Commit 4bc1c4d5 authored by Johan Helsing's avatar Johan Helsing

Add support for on-demand runs

parent bc020310
......@@ -92,6 +92,31 @@ function postGerritComment(commit, comment, codeReview) {
function listenForGerritChanges() {
const emitter = new GerritEventEmitter(gerritHost);
emitter.on('commentAdded', data => {
const { change, comment, patchSet } = data;
const { project, subject, branch, url } = change; //TODO are all of these needed?
if (project !== 'qt/qtwayland') {
return;
}
console.log(`comment on qtwayland change: ${comment}`);
if (!comment.match(/^wayland-bot: ?/m)) {
return;
}
console.log('Someone wants the bot to do something');
if (comment.match(/^wayland-bot: ?(run|test)/m)) {
console.log("On-demand test!");
let image, config;
if(comment.match(/old-libwayland/)) {
image = 'docker-qt-tests-old-libwayland';
config = 'old-libwayland';
}
testPatchSet({change, patchSet, image, config});
}
});
emitter.on('patchsetCreated', data => {
const { change, patchSet } = data;
const { project, subject, branch, url } = change;
......@@ -111,40 +136,7 @@ function listenForGerritChanges() {
return;
}
const qtWaylandRev = patchSet.ref;
const qt5Rev = branch;
const containerName = `gerrit-watcher-${change.number}-${patchSet.number}`;
const test = {
qtWaylandRev,
qt5Rev,
containerName,
title: `Change ${change.number} patch set #${patchSet.number} (${branch}) - ${subject}`,
url
};
console.log('Starting test', test);
const testProcess = startDockerTest(test);
testProcess.on('close', code => {
const failed = code != 0;
const commit = `${change.number},${patchSet.number}`;
var message = 'Running headless tests for change ' +
`${change.number}, patch set #${patchSet.number} ${failed ? 'failed' : 'passed'}`;
message += "\n\nHow to run the tests locally: https://github.com/johanhelsing/docker-qt-tests";
if (failed) {
const codeReview = '-1';
const tailLines = 30;
readLastLines.read(`logs/${containerName}.txt`, tailLines).then(lines => {
const indentedLogTail = lines.replace(/^/mg, ' ');
message = `${message}\n\nLast ${tailLines} lines of log:\n\n${indentedLogTail}`;
console.log(message);
postGerritComment(commit, message, codeReview);
}).catch(reason => console.log('Couldn\'t get last lines of log file', reason));
} else {
postGerritComment(commit, message);
}
});
testPatchSet({change, patchSet});
});
// The ssh connection will sometimes disconnect us. In that case, just reconnect.
......@@ -154,6 +146,47 @@ function listenForGerritChanges() {
emitter.start();
}
function testPatchSet(opts) {
const { change, patchSet, image, config } = opts;
const { subject, branch, url } = change;
const qtWaylandRev = patchSet.ref;
const qt5Rev = branch;
const containerName = `gerrit-watcher-${change.number}-${patchSet.number}-${unixTimeStamp()}`;
const test = {
qtWaylandRev,
qt5Rev,
containerName,
title: `Change ${change.number} patch set #${patchSet.number} (${branch}) ${image || ''} - ${subject}`,
url,
image,
config
};
console.log('Starting test', test);
const testProcess = startDockerTest(test);
testProcess.on('close', code => {
const failed = code != 0;
const commit = `${change.number},${patchSet.number}`;
var message = 'Running headless tests for change ' +
`${change.number}, patch set #${patchSet.number} ${failed ? 'failed' : 'passed'}`;
message += "\n\nHow to run the tests locally: https://github.com/johanhelsing/docker-qt-tests";
if (failed) {
const codeReview = '-1';
const tailLines = 30;
readLastLines.read(`logs/${containerName}.txt`, tailLines).then(lines => {
const indentedLogTail = lines.replace(/^/mg, ' ');
message = `${message}\n\nLast ${tailLines} lines of log:\n\n${indentedLogTail}`;
console.log(message);
postGerritComment(commit, message, codeReview);
}).catch(reason => console.log('Couldn\'t get last lines of log file', reason));
} else {
postGerritComment(commit, message);
}
});
}
function testsPage(tests) {
const title = 'Qt Wayland Test Results';
return `
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment