Repository navigation
Expand file tree
/
Copy pathmain.js
More file actions
77 lines (63 loc) · 2.33 KB
/
Copy pathmain.js
File metadata and controls
77 lines (63 loc) · 2.33 KB
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
const core = require('@actions/core');
const constants = require('../config/constants');
const ActionInput = require('./actionInput');
const ReportService = require('./services/ReportService');
const ReportProcessor = require('./services/ReportProcessor');
const TimeManager = require('./utils/TimeManager');
async function run() {
try {
core.info('Starting BrowserStack Report Action...');
const actionInput = new ActionInput();
const {
username, accessKey, buildName, userTimeout,
} = actionInput.getInputs();
let reportProcessor;
if (userTimeout < 20 || userTimeout > 600) {
const report = {
report: {
basicHtml: `<pre>Invalid report timeout value: ${userTimeout}. It should be between 20 and 600 seconds for Browserstack reports</pre>`,
},
};
reportProcessor = new ReportProcessor(report);
await reportProcessor.processReport();
return;
}
const authHeader = `Basic ${Buffer.from(`${username}:${accessKey}`).toString('base64')}`;
const timeManager = new TimeManager(userTimeout
|| constants.DEFAULT_USER_TIMEOUT_SECONDS);
const reportService = new ReportService(authHeader);
const initialParams = {
originalBuildName: buildName,
requestingCi: constants.CI_SYSTEM.GITHUB_ACTIONS,
reportFormat: [constants.REPORT_FORMAT.BASIC_HTML, constants.REPORT_FORMAT.RICH_HTML],
requestType: constants.REPORT_REQUEST_STATE.FIRST,
userTimeout,
};
timeManager.checkTimeout();
let reportData = await reportService.fetchReport(initialParams);
let { retryCount: maxRetries, pollingInterval } = reportData;
if (!pollingInterval) {
pollingInterval = constants.DEFAULT_POLLING_INTERVAL_SECONDS;
}
if (!maxRetries) {
maxRetries = constants.DEFAULT_MAX_RETRIES;
}
if (reportData.reportStatus === constants.REPORT_STATUS.IN_PROGRESS) {
reportData = await reportService.pollReport(
initialParams,
timeManager,
maxRetries,
pollingInterval,
);
}
reportProcessor = new ReportProcessor(reportData);
await reportProcessor.processReport();
core.info('Report processing completed successfully');
} catch (error) {
core.setFailed(`Action failed: ${error.message}`);
}
}
module.exports = { run };
if (require.main === module) {
run();
}