-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.js
96 lines (76 loc) · 2.94 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
"use strict";
const genDeviceInfo = require('./src/get_device_info.js');
const runTest = require('./src/run.js');
const browser = require('./src/browser.js');
const genTestReport = require('./src/gen_test_report.js');
const sendMail = require('./src/send_mail.js');
const settings = require('./config.json');
const excel = require('./src/excel.js');
const chart = require('./src/chart.js');
const cron = require('node-cron');
const moment = require('moment');
const os = require('os');
const cpuModel = os.cpus()[0].model;
const platform = runTest.getPlatformName();
async function main() {
let now = moment();
const weekAndDay = now.week() + '.' + now.day();
let deviceInfo = {};
try {
deviceInfo = await genDeviceInfo();
// in dev mode, check browser version will be skipped.
if (!settings.dev_mode) {
await browser.checkBrowserVersion(deviceInfo);
}
const workloadResults = await runTest.genWorkloadsResults(deviceInfo);
console.log(JSON.stringify(workloadResults, null, 4));
await excel.genExcelFilesAndUpload(workloadResults);
let chartImages = [];
// only attach the trend charts for Canary tests
// Since AMD testing is before Intel, downloading charts is available after Intel testing done.
if (deviceInfo.Browser.includes('Canary') && cpuModel.includes('Intel')) {
await excel.remoteExecUploadScript(); // upload all the .xlsx data at once
await chart.dlCharts();
chartImages = await chart.getChartFiles();
console.log(chartImages);
}
let mailType = 'test_report';
if (cpuModel.includes('AMD'))
mailType = 'dev_notice'; // If the test is on AMD platform, then send dev team.
const testReports = await genTestReport(workloadResults);
let subject = '[W' + weekAndDay + '] Web PnP weekly automation test report - ' + platform + ' - ' + deviceInfo.Browser;
console.log(subject);
await sendMail(subject, testReports, mailType, chartImages);
} catch (err) {
console.log(err);
let subject = '[W' + weekAndDay + ']';
if (! settings.dev_mode && err.message.includes('No new browser update')) {
subject += 'Web PnP weekly automation test cancelled on ' + platform + ' as no browser update';
} else {
subject += 'Web PnP weekly automation test failed on ' + platform + '-' + cpuModel;
}
console.log(subject);
await sendMail(subject, err, 'failure_notice');
}
// Update the browser version in config.json if necessary
await browser.updateConfig(deviceInfo, settings);
if (deviceInfo.Browser.includes('Canary') && cpuModel.includes('Intel')) {
await chart.cleanUpChartFiles();
}
}
if (settings.enable_cron) {
cron.schedule(settings.update_browser_sched, () => {
browser.updateChrome();
});
if (cpuModel.includes('Intel')) {
cron.schedule(settings.intel_test_cadence, () => {
main();
});
} else {
cron.schedule(settings.amd_test_cadence, () => {
main();
});
}
} else {
main();
}