Commit 718a592c authored by Johan Helsing's avatar Johan Helsing

Also be a simple web server

parent 6fa264af
This diff is collapsed.
"use strict";
const GerritEventEmitter = require('gerrit-event-emitter').GerritEventEmitter;
const emitter = new GerritEventEmitter('codereview.qt-project.org');
const { spawn } = require('child_process');
const { reduce } = require('lodash');
const fs = require('fs');
const express = require('express');
const serveIndex = require('serve-index');
function startDockerTest(options, callback) {
const { qtWaylandRev, qt5Rev, containerName } = options;
const tests = [];
function startDockerTest(test, callback) {
test.title = test.title || test.containerName;
const { qtWaylandRev, qt5Rev, containerName, title } = test;
const environment = {
QT_DOCKERTEST_QTWAYLAND_REV: qtWaylandRev,
QT_DOCKERTEST_QT5_REV: qt5Rev
......@@ -15,52 +19,103 @@ function startDockerTest(options, callback) {
const command = `docker run ${envArgs} --name ${containerName} qtbuilder-stretch`;
const args = [].concat(['run', '--name', containerName], envArgs, ['qtbuilder-stretch']);
console.log('docker ' + args.join(' '));
return spawn('docker', args);
test.process = spawn('docker', args);
test.status = 'running';
const logFile = fs.createWriteStream(`logs/${containerName}.txt`);
test.process.stdout.pipe(logFile);
test.process.stderr.pipe(logFile);
test.process.on('close', code => {
if (code != 0) {
console.log(title, "Failed: with code", code);
test.status = 'failed';
} else {
console.log(title, 'Passed');
test.status = 'passed';
}
});
tests.push(test);
return test;
}
emitter.on('patchsetCreated', data => {
const { change, patchSet } = data;
const { project, subject, branch, url } = change;
function listenForGerritChanges() {
const emitter = new GerritEventEmitter('codereview.qt-project.org');
emitter.on('patchsetCreated', data => {
const { change, patchSet } = data;
const { project, subject, branch, url } = change;
//if (!project.startsWith('qt/')) {
if (project !== 'qt/qtwayland') {
return;
}
if (project !== 'qt/qtwayland') {
return;
}
const prefix = `${url} #${patchSet.number} (${branch}) - ${subject} -`;
//const prefix = `[${project}] ${url} #${patchSet.number} (${branch}) - ${subject} -`;
const test = {
qtWaylandRev,
qt5Rev,
containerName,
title: `Change ${change.number} patch set #${patchSet.number} (${branch}) - ${subject} -`,
url
};
const qtWaylandRev = patchSet.ref;
const qt5Rev = branch;
const containerName = `gerrit-watcher-${change.number}-${patchSet.number}`;
console.log(prefix, 'Starting test');
startDockerTest(test);
});
console.log(prefix, 'STARTING TEST');
emitter.on('gerritStreamEnd', () => emitter.start());
const qtWaylandRev = patchSet.ref;
const qt5Rev = branch;
const containerName = `gerrit-watcher-${change.number}-${patchSet.number}`;
startDockerTest({qtWaylandRev, qt5Rev, containerName}, (error, stdout, stderr) => {
if (error) {
console.log(prefix, "FAILED: error", error);
console.log(stderr);
} else {
console.log(prefix, 'PASSED');
}
});
});
console.log("Starting gerrit-watcher");
emitter.start();
}
emitter.on('gerritStreamEnd', () => emitter.start());
function testsPage(tests) {
const title = 'Qt Wayland Test Results';
return `
<html>
<head>
<title>${title}</title>
<style>
.failed { color: darkred; }
.passed { color: darkgreen; }
.running { color: darkorange; }
</style>
</head>
<body>
<h1>${title}</h1>
<p><a href="logs/">Browse logs</a></p>
<ul>
${tests.map(test => `
<li class="${test.status}">
${test.title} -
qt5: ${test.qt5Rev} -
qtwayland: ${test.qtWaylandRev} -
${test.status} -
${test.url ? `<a href="${test.url}">${test.url}</a> - ` : ''}
<a href="logs/${test.containerName}.txt">log</a>
</li>
`).join('\n')}
</ul>
</body>
</html>
`;
}
console.log("Starting gerrit-watcher");
emitter.start();
function serveLogs() {
var server = express();
server.use('/logs/', express.static(`${__dirname}/logs/`));
server.use('/logs/', serveIndex(`${__dirname}/logs/`));
server.get('/', (req, res) => res.send(testsPage(tests)));
server.listen(8056);
}
const initContainerName = 'gerrit-watcher-init-test-'+Math.floor(new Date() / 1000);
const initTest = startDockerTest({qtWaylandRev: '5.11', qt5Rev: '5.11', containerName: initContainerName});
const logFile = fs.createWriteStream(`logs/${initContainerName}`);
initTest.stdout.pipe(logFile);
initTest.stderr.pipe(logFile);
function initTest() {
const initContainerName = 'gerrit-watcher-init-test-'+Math.floor(new Date() / 1000);
const initTest = startDockerTest({qtWaylandRev: '5.11', qt5Rev: '5.11', containerName: initContainerName});
}
if (!fs.existsSync('logs')){
fs.mkdirSync('logs');
}
initTest.on('close', code => {
if (code != 0) {
console.log(initContainerName, "FAILED: with code", code);
} else {
console.log(initContainerName, 'PASSED');
}
logFile.close();
});
listenForGerritChanges();
initTest();
serveLogs();
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