-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
96 lines (78 loc) · 2.84 KB
/
index.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
96
const fs = require('fs');
const path = require('path')
const got = require('got')
const FormData = require('form-data');
const core = require('@actions/core');
const github = require('@actions/github');
async function compress(srcFolder, zipFilePath) {
const archiver = require('archiver');
const targetBasePath = path.dirname(zipFilePath);
if (targetBasePath === srcFolder) {
throw new Error('Source and target folder must be different.');
}
try {
await fs.promises.access(srcFolder, fs.constants.R_OK | fs.constants.W_OK);
await fs.promises.access(targetBasePath, fs.constants.R_OK | fs.constants.W_OK);
} catch (e) {
throw new Error(`Permission error: ${e.message}`);
}
const output = fs.createWriteStream(zipFilePath);
const zipArchive = archiver('zip');
return new Promise((resolve, reject) => {
output.on('close', resolve);
output.on('error', (err) => {
reject(err);
});
zipArchive.pipe(output);
zipArchive.directory(srcFolder, false);
zipArchive.finalize();
});
}
async function runAction() {
// http://username:[email protected]/
const allureServerUrl = new URL(core.getInput('allure-server-url', { required: true }));
// getInput returns empty string in case no input passed, which is fine for us
allureServerUrl.username = core.getInput('username')
allureServerUrl.password = core.getInput('password')
await compress(core.getInput('allure-results', { required: true }), './allure-results.zip')
core.info(`Created compressed ./allure-results.zip`)
const defaultGot = got.extend({
prefixUrl: allureServerUrl,
responseType: 'json'
});
const form = new FormData();
core.info(`Uploading compressed ./allure-results.zip`)
form.append('allureResults', fs.createReadStream('allure-results.zip'));
const resultsResp = await defaultGot('api/result', {
method: 'POST',
body: form,
})
core.info(`Upload done: ${resultsResp.body}`)
const results_id = resultsResp.body.uuid
const inputPath = core.getInput('path', { required: true })
const allureReportPath = inputPath == 'DEFAULT_PATH' ? github.context.repo.repo : inputPath
core.info(`Triggering report generation for ${allureReportPath}`)
const reportUrl = await defaultGot('api/report', {
method: 'POST',
json: {
reportSpec: {
path: [
allureReportPath
]
},
results: [
results_id
],
deleteResults: true
}
})
core.info(`Report generation done: ${reportUrl.body}`)
core.info(`========================================================================`)
core.info(`REPORT URL: ${reportUrl.body.url}`)
core.info(`========================================================================`)
core.setOutput("report-url", reportUrl.body.url)
}
runAction().catch(err => {
core.error(err.message)
core.setFailed(err.message);
})